Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- server.route({
- path: '/api/companies/{id}',
- method: 'PUT',
- handler(req, reply) {
- if (!req.params.id) {
- return reply({err: 'id is required param'}).code(400);
- }
- let attributes = {};
- if (req.payload.name) {
- attributes.name = req.payload.name;
- }
- if (req.payload.city) {
- attributes.city = req.payload.city;
- }
- if (req.payload.address) {
- attributes.address = req.payload.address;
- }
- Company.findByIdAndUpdate(
- req.params.id,
- attributes,
- {new: true},
- (err, company) => {
- if (err) {
- return reply(err).code(500);
- }
- return reply.response(company);
- })
- }
- });
Add Comment
Please, Sign In to add comment