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");
|
throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used.", "branchInUsed");
|
||||||
}
|
}
|
||||||
|
|
||||||
await minio.removeObject(MINIO_BUCKET, lineImageLoc(branchId), {
|
return await prisma.$transaction(async (tx) => {
|
||||||
forceDelete: true,
|
const data = await tx.branch.delete({
|
||||||
});
|
include: {
|
||||||
await minio.removeObject(MINIO_BUCKET, branchImageLoc(branchId), {
|
province: true,
|
||||||
forceDelete: true,
|
district: true,
|
||||||
});
|
subDistrict: true,
|
||||||
|
createdBy: true,
|
||||||
|
updatedBy: true,
|
||||||
|
},
|
||||||
|
where: { id: branchId },
|
||||||
|
});
|
||||||
|
|
||||||
return await prisma.branch.delete({
|
if (record.isHeadOffice) {
|
||||||
include: {
|
await tx.runningNo.delete({
|
||||||
province: true,
|
where: {
|
||||||
district: true,
|
key: `MAIN_BRANCH_${record.code.slice(0, -6)}`,
|
||||||
subDistrict: true,
|
},
|
||||||
createdBy: true,
|
});
|
||||||
updatedBy: true,
|
}
|
||||||
},
|
|
||||||
where: { id: branchId },
|
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