feat: allow company change
This commit is contained in:
parent
4b963cf69c
commit
6ba5234587
1 changed files with 28 additions and 15 deletions
|
|
@ -230,21 +230,34 @@ 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;
|
||||||
|
|
||||||
if (companyBefore && companyAfter && companyBefore !== companyAfter) {
|
const result = await prisma.$transaction(async (tx) => {
|
||||||
throw new HttpError(
|
let code = "";
|
||||||
HttpStatus.BAD_REQUEST,
|
if (companyBefore && companyAfter && companyBefore !== companyAfter) {
|
||||||
"Cannot move between different headoffice",
|
const last = await tx.runningNo.upsert({
|
||||||
"crossCompanyNotPermit",
|
where: {
|
||||||
);
|
key: `PRODGRP_${companyAfter}`,
|
||||||
}
|
},
|
||||||
|
create: {
|
||||||
const result = await prisma.productGroup.update({
|
key: `PRODGRP_${companyAfter}`,
|
||||||
include: {
|
value: 1,
|
||||||
createdBy: true,
|
},
|
||||||
updatedBy: true,
|
update: { value: { increment: 1 } },
|
||||||
},
|
});
|
||||||
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
code = `G${last.value.toString().padStart(2, "0")}`;
|
||||||
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