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) => {
|
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,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue