added controller update to router

parent f0a6ca24
...@@ -73,7 +73,11 @@ const update = (model: Model<any>) => (req: Request, res: Response) => { ...@@ -73,7 +73,11 @@ const update = (model: Model<any>) => (req: Request, res: Response) => {
model model
.findByIdAndUpdate(id, data) .findByIdAndUpdate(id, data)
.then((result) => { .then((result) => {
return res.status(200).send(result); if (result) {
return res.status(200).send(result);
} else {
return res.json({message: 'Not found'});
}
}) })
.catch((error) => { .catch((error) => {
console.log(error); console.log(error);
......
...@@ -11,6 +11,7 @@ const router: Router = express.Router(); ...@@ -11,6 +11,7 @@ const router: Router = express.Router();
router.get('/', controller.getAll(model, ['category', 'location'])); router.get('/', controller.getAll(model, ['category', 'location']));
router.get('/:id', controller.get(model, ['category', 'location'])); router.get('/:id', controller.get(model, ['category', 'location']));
router.delete('/:id', controller.deleteDoc(model)); router.delete('/:id', controller.deleteDoc(model));
router.put('/:id', controller.update(model));
router.post( router.post(
'/', '/',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment