Dodal da se nemore dodati filem ce je ze v DB
This commit is contained in:
parent
6f0632db6b
commit
e75952fb52
@ -34,18 +34,37 @@ module.exports = {
|
||||
genre: req.body.genre ? req.body.genre : req.body.Genre,
|
||||
code: req.body.code ? req.body.code : req.body.Code
|
||||
});
|
||||
|
||||
movie.save()
|
||||
.then(savedMovie => {
|
||||
// Handle successful save operation
|
||||
return res.json(savedMovie);
|
||||
})
|
||||
.catch(err => {
|
||||
return res.status(500).json({
|
||||
message: 'Error when creating movie',
|
||||
error: err
|
||||
|
||||
MovieModel.findOne({ code: movie.code })
|
||||
.then(movieFound => {
|
||||
if (movieFound) {
|
||||
return res.status(409).json({
|
||||
message: 'Movie already exists'
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
movie.save()
|
||||
.then(savedMovie => {
|
||||
// Handle successful save operation
|
||||
return res.json(savedMovie);
|
||||
})
|
||||
.catch(err => {
|
||||
return res.status(500).json({
|
||||
message: 'Error when creating movie',
|
||||
error: err
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting movie',
|
||||
error: err
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user