From 88d8f40ee3a438e3dd981433fc53a364d01c444d Mon Sep 17 00:00:00 2001 From: Francesco Esposito <33671357+frab1t@users.noreply.github.com> Date: Wed, 20 Feb 2019 08:54:48 +0100 Subject: [PATCH] add remove function in controller/routes --- apiRoutes.js | 3 ++- controllers/deviceController.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apiRoutes.js b/apiRoutes.js index 1af3a8e..d6cc9cc 100644 --- a/apiRoutes.js +++ b/apiRoutes.js @@ -11,6 +11,7 @@ router .route('/devices/:deviceId') .get(deviceController.view) .put(deviceController.update) - .patch(deviceController.update); + .patch(deviceController.update) + .delete(deviceController.remove); module.exports = router; diff --git a/controllers/deviceController.js b/controllers/deviceController.js index 53b2f36..c15695f 100644 --- a/controllers/deviceController.js +++ b/controllers/deviceController.js @@ -29,6 +29,16 @@ function update(req, res) { }); } +function remove(req, res) { + Device.deleteOne({ _id: req.params.deviceId }, (err) => { + if (err) { + res.status(500).send(); + } + res.status(200).send(); + }); +} + module.exports.index = index; module.exports.view = view; module.exports.update = update; +module.exports.remove = remove;