use await Promise.all in uploadedFile Product
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 6s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 6s
This commit is contained in:
parent
05d16f22de
commit
e42b772dcf
1 changed files with 27 additions and 26 deletions
|
|
@ -518,34 +518,35 @@ export class ProductController extends Controller {
|
|||
async (tx) => {
|
||||
const branch = productGroup.registeredBranch;
|
||||
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) {
|
||||
const last = await tx.runningNo.upsert({
|
||||
where: {
|
||||
key: `PRODUCT_${company}_${item.code.toLocaleUpperCase()}`,
|
||||
},
|
||||
create: {
|
||||
key: `PRODUCT_${company}_${item.code.toLocaleUpperCase()}`,
|
||||
value: 1,
|
||||
},
|
||||
update: { value: { increment: 1 } },
|
||||
});
|
||||
await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const dataDuplicate = productSameName.some(
|
||||
(v) => v.code.slice(0, -3) === item.code.toUpperCase() && v.name === item.name,
|
||||
);
|
||||
|
||||
dataProduct.push({
|
||||
...item,
|
||||
code: `${item.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||
createdByUserId: req.user.sub,
|
||||
updatedByUserId: req.user.sub,
|
||||
productGroupId: productGroupId,
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log("dataProduct", dataProduct);
|
||||
if (!dataDuplicate) {
|
||||
const last = await tx.runningNo.upsert({
|
||||
where: {
|
||||
key: `PRODUCT_${company}_${item.code.toLocaleUpperCase()}`,
|
||||
},
|
||||
create: {
|
||||
key: `PRODUCT_${company}_${item.code.toLocaleUpperCase()}`,
|
||||
value: 1,
|
||||
},
|
||||
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({
|
||||
data: dataProduct,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue