feat: update status of headoffice so it cannot be delete

This commit is contained in:
Methapon Metanipat 2024-08-22 14:29:18 +07:00
parent 1d68cc2d61
commit 03d25219c1

View file

@ -333,7 +333,8 @@ export class CustomerBranchController extends Controller {
const record = await prisma.$transaction(
async (tx) => {
const headofficeCode = customer.branch.at(0)?.code.slice(0, -3);
const headoffice = customer.branch.at(0);
const headofficeCode = headoffice?.code.slice(0, -3);
let runningKey = "";
@ -354,6 +355,16 @@ export class CustomerBranchController extends Controller {
update: { value: { increment: 1 } },
});
if (headoffice) {
await tx.customerBranch.updateMany({
where: {
id: headoffice.id,
status: "CREATED",
},
data: { status: "ACTIVE" },
});
}
return await tx.customerBranch.create({
include: {
province: true,