diff --git a/middleware/Vegetables.js b/middleware/Vegetables.js index febeeab..6167e55 100644 --- a/middleware/Vegetables.js +++ b/middleware/Vegetables.js @@ -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)