mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-23 17:19:18 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
40
api/controllers/controller.js
Normal file
40
api/controllers/controller.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
'use strict';
|
||||
const mongoose = require('mongoose'),
|
||||
Book = mongoose.model('Books');exports.list_all_books = (req, res) => {
|
||||
Book.find({}, (err, book) => {
|
||||
if (err)
|
||||
res.send(err);
|
||||
res.json(book);
|
||||
});
|
||||
};
|
||||
exports.create_a_book = (req, res) => {
|
||||
let new_book = new Book(req.body);
|
||||
new_book.save((err, book) => {
|
||||
if (err)
|
||||
res.send(err);
|
||||
res.json(book);
|
||||
});
|
||||
};
|
||||
exports.read_a_book = (req, res) => {
|
||||
Book.findById(req.params.bookId, (err, book) => {
|
||||
if (err)
|
||||
res.send(err);
|
||||
res.json(book);
|
||||
});
|
||||
};
|
||||
exports.update_a_book = (req, res) => {
|
||||
Book.findOneAndUpdate({_id: req.params.bookId}, req.body, {new: true}, (err, task) => {
|
||||
if (err)
|
||||
res.send(err);
|
||||
res.json(book);
|
||||
});
|
||||
};
|
||||
exports.delete_a_book = (req, res) => {
|
||||
Book.remove({
|
||||
_id: req.params.bookId
|
||||
}, (err, book) => {
|
||||
if (err)
|
||||
res.send(err);
|
||||
res.json({ message: 'Book successfully deleted' });
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue