-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollers.js
More file actions
35 lines (26 loc) · 881 Bytes
/
Copy pathcontrollers.js
File metadata and controls
35 lines (26 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { Books } = require('./models');
const booksController = {};
booksController.getBooks = (req, res, next) => {
Books.find({}, (err, books) => {
if(err) return next(err);
// send the list of all books
res.locals.books = books;
return next();
});
}
booksController.postBooks = (req, res, next) => {
const { title, author, pages } = req.body;
// console.log(req.body)
Books.create({ title, author, pages }, (err, booksAdded) => {
if (err) return next(err);
return next();
})
}
// booksController.deleteBooks = (req, res, next) => {
// const { titles, authors, pages } = req.body;
// Books.deleteOne({ titles, authors, pages }, (err, booksDeleted) => {
// if(err) return next(err);
// return next();
// })
// }
module.exports = booksController;