feat: handle running no on delete customer
This commit is contained in:
parent
8172bd4ab6
commit
19f4a58df4
1 changed files with 27 additions and 3 deletions
|
|
@ -418,9 +418,33 @@ export class CustomerController extends Controller {
|
|||
|
||||
if (record.status !== Status.CREATED) throw isUsedError("Customer");
|
||||
|
||||
return await prisma.customer
|
||||
.delete({ where: { id: customerId } })
|
||||
.then((data) => deleteFolder(`customer/${customerId}`).then(() => data));
|
||||
await prisma.$transaction(async (tx) => {
|
||||
await deleteFolder(`customer/${customerId}`);
|
||||
const data = await tx.customer.delete({
|
||||
include: {
|
||||
branch: true,
|
||||
registeredBranch: {
|
||||
include: {
|
||||
headOffice: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: { id: customerId },
|
||||
});
|
||||
|
||||
await tx.runningNo.deleteMany({
|
||||
where: {
|
||||
key: {
|
||||
in: data.branch.map(
|
||||
(v) =>
|
||||
`CUSTOMER_BRANCH_${(data.registeredBranch.headOffice || data.registeredBranch).code}_${v.code.slice(0, -3)}`,
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return await tx.customer.delete({ where: { id: customerId } });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue