fix: delete customer branch hq now also delete parent
This commit is contained in:
parent
0d41f60829
commit
e4064a0695
1 changed files with 27 additions and 6 deletions
|
|
@ -493,12 +493,33 @@ export class CustomerBranchController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await prisma.customerBranch
|
return await prisma.$transaction(async (tx) => {
|
||||||
.delete({
|
if (record.code.endsWith("00")) {
|
||||||
include: { createdBy: true, updatedBy: true },
|
await Promise.all([
|
||||||
where: { id: branchId },
|
tx.customer.delete({
|
||||||
})
|
where: { id: record.customerId },
|
||||||
.then((v) => deleteFolder(fileLocation.customerBranch.attachment(branchId)).then(() => v));
|
}),
|
||||||
|
tx.runningNo.delete({
|
||||||
|
where: { key: record.code.slice(0, -3) },
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return await prisma.customerBranch
|
||||||
|
.delete({
|
||||||
|
include: { createdBy: true, updatedBy: true },
|
||||||
|
where: { id: branchId },
|
||||||
|
})
|
||||||
|
.then((v) =>
|
||||||
|
Promise.all([
|
||||||
|
deleteFolder(fileLocation.customerBranch.attachment(branchId)),
|
||||||
|
deleteFolder(fileLocation.customerBranch.citizen(branchId)),
|
||||||
|
deleteFolder(fileLocation.customerBranch.powerOfAttorney(branchId)),
|
||||||
|
deleteFolder(fileLocation.customerBranch.vatRegistration(branchId)),
|
||||||
|
deleteFolder(fileLocation.customerBranch.houseRegistration(branchId)),
|
||||||
|
deleteFolder(fileLocation.customerBranch.commercialRegistration(branchId)),
|
||||||
|
]).then(() => v),
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue