-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
31 lines (28 loc) · 950 Bytes
/
routes.js
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
module.exports = function (stockRepository) {
return {
stockUp: function (req, res, next) {
var isbn = req.body.isbn;
var count = req.body.count;
stockRepository.
stockUp(isbn, count).
catch(next);
res.json({isbn: isbn, count: count});
},
findAll: function (req, res, next) {
stockRepository.findAll().
then(function (docs) {
res.json(docs);
}).
catch(next);
},
getCount: function (req, res) {
stockRepository.getCount(req.params.isbn).then(function (result) {
if (result !== null) {
res.status(200).json({count: result});
} else {
res.status(404).json({error: 'No book with ISBN: ' + req.params.isbn});
}
});
}
};
};