Fixed bug on delete vegetable
This commit is contained in:
parent
219c2f449c
commit
faaee98022
1 changed files with 26 additions and 10 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue