Dodal delete movies

This commit is contained in:
Nikola Petrov 2023-06-26 00:59:11 +02:00
parent e75952fb52
commit 757acd9014
2 changed files with 13 additions and 8 deletions

View File

@ -104,16 +104,21 @@ module.exports = {
*/ */
remove: function (req, res) { remove: function (req, res) {
var id = req.params.id; var id = req.params.id;
console.log(id);
MovieModel.findByIdAndRemove(id, function (err, movie) { MovieModel.findOneAndDelete({ code: id })
if (err) { .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({ return res.status(500).json({
message: 'Error when deleting the movie.', message: 'Error when deleting the movie.',
error: err error: err
}); });
}
return res.status(204).json();
}); });
}, },
}; };

View File

@ -13,6 +13,6 @@ router.post('/', movieController.create);
//router.put('/:id', movieController.update); //router.put('/:id', movieController.update);
//router.delete('/:id', movieController.remove); router.delete('/:id', movieController.remove);
module.exports = router; module.exports = router;