feat: prevent from change company

This commit is contained in:
Methapon Metanipat 2024-09-23 18:14:33 +07:00
parent 18ef97cc71
commit 18963f666d

View file

@ -361,6 +361,26 @@ export class CustomerController extends Controller {
await permissionCheck(req.user, branch);
}
if (!!body.registeredBranchId && !branch) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Branch cannot be found.",
"relationBranchNotFound",
);
}
let companyBefore = (customer.registeredBranch.headOffice || customer.registeredBranch).code;
let companyAfter =
!!body.registeredBranchId && branch ? (branch.headOffice || branch).code : false;
if (companyBefore && companyAfter && companyBefore !== companyAfter) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Cannot move between different headoffice",
"crossCompanyNotPermit",
);
}
const record = await prisma.$transaction(async (tx) => {
return await tx.customer.update({
include: {