parent
6ba5234587
commit
18ef97cc71
1 changed files with 15 additions and 28 deletions
|
|
@ -230,34 +230,21 @@ export class ProductGroup extends Controller {
|
||||||
let companyAfter =
|
let companyAfter =
|
||||||
!!body.registeredBranchId && branch ? (branch.headOffice || branch).code : false;
|
!!body.registeredBranchId && branch ? (branch.headOffice || branch).code : false;
|
||||||
|
|
||||||
const result = await prisma.$transaction(async (tx) => {
|
if (companyBefore && companyAfter && companyBefore !== companyAfter) {
|
||||||
let code = "";
|
throw new HttpError(
|
||||||
if (companyBefore && companyAfter && companyBefore !== companyAfter) {
|
HttpStatus.BAD_REQUEST,
|
||||||
const last = await tx.runningNo.upsert({
|
"Cannot move between different headoffice",
|
||||||
where: {
|
"crossCompanyNotPermit",
|
||||||
key: `PRODGRP_${companyAfter}`,
|
);
|
||||||
},
|
}
|
||||||
create: {
|
|
||||||
key: `PRODGRP_${companyAfter}`,
|
const result = await prisma.productGroup.update({
|
||||||
value: 1,
|
include: {
|
||||||
},
|
createdBy: true,
|
||||||
update: { value: { increment: 1 } },
|
updatedBy: true,
|
||||||
});
|
},
|
||||||
code = `G${last.value.toString().padStart(2, "0")}`;
|
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
||||||
}
|
where: { id: groupId },
|
||||||
return await prisma.productGroup.update({
|
|
||||||
include: {
|
|
||||||
createdBy: true,
|
|
||||||
updatedBy: true,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
...body,
|
|
||||||
code: !!code ? code : undefined,
|
|
||||||
statusOrder: +(body.status === "INACTIVE"),
|
|
||||||
updatedByUserId: req.user.sub,
|
|
||||||
},
|
|
||||||
where: { id: groupId },
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue