use await Promise.all in uploadedFile Product
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 6s

This commit is contained in:
Kanjana 2025-04-18 16:23:02 +07:00
parent 05d16f22de
commit e42b772dcf

View file

@ -518,34 +518,35 @@ export class ProductController extends Controller {
async (tx) => { async (tx) => {
const branch = productGroup.registeredBranch; const branch = productGroup.registeredBranch;
const company = (branch.headOffice || branch).code; const company = (branch.headOffice || branch).code;
console.log(branch, company);
for (const item of data) {
const dataDuplicate = productSameName.some(
(v) => v.code.slice(0, -3) === item.code.toUpperCase() && v.name === item.name,
);
if (!dataDuplicate) { await Promise.all(
const last = await tx.runningNo.upsert({ data.map(async (item) => {
where: { const dataDuplicate = productSameName.some(
key: `PRODUCT_${company}_${item.code.toLocaleUpperCase()}`, (v) => v.code.slice(0, -3) === item.code.toUpperCase() && v.name === item.name,
}, );
create: {
key: `PRODUCT_${company}_${item.code.toLocaleUpperCase()}`,
value: 1,
},
update: { value: { increment: 1 } },
});
dataProduct.push({ if (!dataDuplicate) {
...item, const last = await tx.runningNo.upsert({
code: `${item.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`, where: {
createdByUserId: req.user.sub, key: `PRODUCT_${company}_${item.code.toLocaleUpperCase()}`,
updatedByUserId: req.user.sub, },
productGroupId: productGroupId, create: {
}); key: `PRODUCT_${company}_${item.code.toLocaleUpperCase()}`,
} value: 1,
} },
console.log("dataProduct", dataProduct); update: { value: { increment: 1 } },
});
dataProduct.push({
...item,
code: `${item.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
createdByUserId: req.user.sub,
updatedByUserId: req.user.sub,
productGroupId: productGroupId,
});
}
}),
);
return await prisma.product.createManyAndReturn({ return await prisma.product.createManyAndReturn({
data: dataProduct, data: dataProduct,