fix: delete unused branch cause error new branch same code
This commit is contained in:
parent
4be62e6bd2
commit
20cf11f988
1 changed files with 27 additions and 15 deletions
|
|
@ -561,22 +561,34 @@ export class BranchController extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used.", "branchInUsed");
|
||||
}
|
||||
|
||||
await minio.removeObject(MINIO_BUCKET, lineImageLoc(branchId), {
|
||||
forceDelete: true,
|
||||
});
|
||||
await minio.removeObject(MINIO_BUCKET, branchImageLoc(branchId), {
|
||||
forceDelete: true,
|
||||
});
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
const data = await tx.branch.delete({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: branchId },
|
||||
});
|
||||
|
||||
return await prisma.branch.delete({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: branchId },
|
||||
if (record.isHeadOffice) {
|
||||
await tx.runningNo.delete({
|
||||
where: {
|
||||
key: `MAIN_BRANCH_${record.code.slice(0, -6)}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await minio.removeObject(MINIO_BUCKET, lineImageLoc(branchId), {
|
||||
forceDelete: true,
|
||||
});
|
||||
await minio.removeObject(MINIO_BUCKET, branchImageLoc(branchId), {
|
||||
forceDelete: true,
|
||||
});
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue