Guest User

Untitled

a guest
Feb 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. server.route({
  2. path: '/api/companies/{id}',
  3. method: 'PUT',
  4. handler(req, reply) {
  5.  
  6. if (!req.params.id) {
  7. return reply({err: 'id is required param'}).code(400);
  8. }
  9. let attributes = {};
  10.  
  11. if (req.payload.name) {
  12. attributes.name = req.payload.name;
  13. }
  14. if (req.payload.city) {
  15. attributes.city = req.payload.city;
  16. }
  17. if (req.payload.address) {
  18. attributes.address = req.payload.address;
  19. }
  20. Company.findByIdAndUpdate(
  21. req.params.id,
  22. attributes,
  23. {new: true},
  24. (err, company) => {
  25. if (err) {
  26. return reply(err).code(500);
  27. }
  28. return reply.response(company);
  29. })
  30. }
  31. });
Add Comment
Please, Sign In to add comment