Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. exports.update = (req, res) => {
  2. if(!req.body.name) {
  3. return res.status(400).send({
  4. message: "Fields can not be empty"
  5. });
  6. }
  7. // Find category and update it with the request body
  8. Category.findByIdAndUpdate(req.params.categoryId, {
  9. name: req.body.name,
  10. details: req.body.details
  11. }, {new: true})
  12. .then(category => {
  13. if(!category) {
  14. return res.status(404).send({
  15. message: "Category does not exist"
  16. });
  17. }
  18. res.send(category);
  19. }).catch(err => {
  20. return res.status(500).send({
  21. message: "Something went wrong"
  22. });
  23. });
  24. };