Dodal da se nemore dodati filem ce je ze v DB

This commit is contained in:
Nikola Petrov 2023-06-25 16:09:43 +02:00
parent 6f0632db6b
commit e75952fb52

View File

@ -35,6 +35,15 @@ module.exports = {
code: req.body.code ? req.body.code : req.body.Code code: req.body.code ? req.body.code : req.body.Code
}); });
MovieModel.findOne({ code: movie.code })
.then(movieFound => {
if (movieFound) {
return res.status(409).json({
message: 'Movie already exists'
});
}
else
{
movie.save() movie.save()
.then(savedMovie => { .then(savedMovie => {
// Handle successful save operation // Handle successful save operation
@ -46,6 +55,16 @@ module.exports = {
error: err error: err
}); });
}); });
}
})
.catch(err => {
return res.status(500).json({
message: 'Error when getting movie',
error: err
})
});
}, },
/** /**