Guest User

Untitled

a guest
Jul 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // @POST api/clients
  2. // @desc Create A Clients
  3.  
  4. router.post('/', (req, res) => {
  5. ClientModel.findOne({ name: req.body.name }).then(client => {
  6. if (client) {
  7. return res.status(400).json({ name: 'Client already exist' });
  8. } else {
  9. const newClient = new ClientModel({
  10. name: req.body.name,
  11. handle: req.body.name.toLowerCase(),
  12. pgf_fb_x: req.body.pgf_fb_x,
  13. });
  14.  
  15. newClient
  16. .save()
  17. .then(client => res.json(client))
  18. .catch(err => console.log(err));
  19.  
  20. // WHERE I WANT TO UPDATE
  21.  
  22. ClientModel.findOneAndUpdate(
  23. { pgf_fb_xt: req.body.pgf_fb_x },
  24. { new: true }
  25. ).then(client => res.json(client));
  26.  
  27. // END OF UPDATE
  28. }
  29. });
  30. });
Add Comment
Please, Sign In to add comment