Jenderal92

Untitled

Jul 22nd, 2022
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. exports.create = (req, res) => {
  2. if(!req.body.name) {
  3. return res.status(400).send({
  4. message: "Fields can not be empty"
  5. });
  6. }
  7.  
  8. // Create a Category
  9. const category = new Category({
  10. name: req.body.name,
  11. details: req.body.details
  12. });
  13.  
  14. // Save Category in the database
  15. category.save()
  16. .then(data => {
  17. res.send(data);
  18. }).catch(err => {
  19. res.status(500).send({
  20. message: err.message || "Something went wrong."
  21. });
  22. });
  23. };
Advertisement
Add Comment
Please, Sign In to add comment