added update func in generic controller

parent 3a2941ee
......@@ -67,9 +67,24 @@ const deleteDoc = (model: Model<any>) => (req: Request, res: Response) => {
});
};
const update = (model: Model<any>) => (req: Request, res: Response) => {
const id = req.params.id;
const data = {...req.body};
model
.findByIdAndUpdate(id, data)
.then((result) => {
return res.status(200).send(result);
})
.catch((error) => {
console.log(error);
return res.status(500).json({error});
});
};
export default {
create,
getAll,
get,
deleteDoc,
update,
};
......@@ -9,6 +9,7 @@ const router: Router = express.Router();
router.get('/', controller.getAll(model));
router.post('/', controller.create(model));
router.get('/:id', controller.get(model));
router.put('/:id', controller.update(model));
router.delete('/:id', (req: Request, res: Response) => {
try {
......
......@@ -8,6 +8,8 @@ const router: Router = express.Router();
router.get('/', controller.getAll(model));
router.post('/', controller.create(model));
router.get('/:id', controller.get(model));
router.put('/:id', controller.update(model));
router.delete('/:id', (req: Request, res: Response) => {
try {
const id = req.params.id;
......
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