Fixed bug on delete vegetable

This commit is contained in:
dbroqua 2019-04-09 19:45:00 +02:00
parent 219c2f449c
commit faaee98022

View File

@ -84,18 +84,34 @@ class Vegetables {
}
_deleteOne (item, req, callback) {
vegetables.destroy({
where: {
id: req.params.vegetablesId
}
})
.then(deleted => {
if (deleted === 0) {
callback(new Error('Error when trying to delete item'))
return false
models.vegetablePictures
.destroy({
where: {
vegetableId: req.params.vegetablesId
}
})
.then(() => {
models.vegetableProperties
.destroy({
where: {
vegetableId: req.params.vegetablesId
}
})
.then(() => {
vegetables.destroy({
where: {
id: req.params.vegetablesId
}
})
.then(deleted => {
if (deleted === 0) {
callback(new Error('Error when trying to delete item'))
return false
}
callback(null, null)
callback(null, null)
})
})
})
.catch(e => {
callback(e, null)