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) {
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
});
});
},
};

View File

@ -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;