Bug fixed: Create establishment without mapping products
This commit is contained in:
parent
31ad2d89bd
commit
7037adafd3
@ -86,6 +86,24 @@ exports.createEstablishment = async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (!Array.isArray(establishment_products) || establishment_products.length === 0) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "Please select at least one product."
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of establishment_products) {
|
||||
const id = Number(item.product_id);
|
||||
|
||||
if (!id || isNaN(id) || id <= 1) {
|
||||
return res.status(400).send({
|
||||
status: "failed",
|
||||
message: "Invalid product_id. product_id must be a number greater than 1 and cannot be 0."
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Check if establishment already exists
|
||||
const existingEstablishment = await Establishment.findOne({where: { establishment_code }, });
|
||||
if (existingEstablishment) {
|
||||
@ -167,7 +185,6 @@ exports.createEstablishment = async (req, res) => {
|
||||
|
||||
// remove duplicates from request itself
|
||||
let uniqueProducts = [...new Set(establishment_products.map(x => x.product_id))];
|
||||
|
||||
// now check which already exist for this establishment
|
||||
const existing = await EstablishmentProduct.findAll({
|
||||
where: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user