|
|
@ -1,4 +1,5 @@ |
|
|
|
const Factory = require("../model/factory.model"); |
|
|
|
const Chicken = require("../model/chicken.model"); |
|
|
|
class FactoryService { |
|
|
|
async getAllFactory() { |
|
|
|
const res = await Factory.findAll(); |
|
|
@ -33,6 +34,16 @@ class FactoryService { |
|
|
|
} |
|
|
|
|
|
|
|
async deleteFactoryById(id) { |
|
|
|
const whereOpt = { is_marketed: 0, factory_id: id }; |
|
|
|
const chickInfo = await Chicken.findAll({ |
|
|
|
where: whereOpt, |
|
|
|
}); |
|
|
|
if (chickInfo) { |
|
|
|
const arr = chickInfo.map((item) => item.dataValues); |
|
|
|
if (arr.length > 0) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
const res = await Factory.destroy({ |
|
|
|
where: { |
|
|
|
id, |
|
|
|