diff --git a/controllers/movieController.js b/controllers/movieController.js index 2c9935d..33fa7c9 100644 --- a/controllers/movieController.js +++ b/controllers/movieController.js @@ -104,16 +104,21 @@ module.exports = { */ remove: function (req, res) { var id = req.params.id; - - MovieModel.findByIdAndRemove(id, function (err, movie) { - if (err) { - return res.status(500).json({ - message: 'Error when deleting the movie.', - error: err + console.log(id); + MovieModel.findOneAndDelete({ code: id }) + .then(movie => { + if (!movie) { + return res.status(404).json({ + message: 'No such movie' }); } - return res.status(204).json(); + }) + .catch(err => { + return res.status(500).json({ + message: 'Error when deleting the movie.', + error: err + }); }); }, }; diff --git a/routes/movies/movieRouter.js b/routes/movies/movieRouter.js index c7d3892..49c0bf7 100644 --- a/routes/movies/movieRouter.js +++ b/routes/movies/movieRouter.js @@ -13,6 +13,6 @@ router.post('/', movieController.create); //router.put('/:id', movieController.update); -//router.delete('/:id', movieController.remove); +router.delete('/:id', movieController.remove); module.exports = router; \ No newline at end of file