feat: detect self reference

This commit is contained in:
Methapon2001 2024-04-10 16:21:56 +07:00
parent ae42cb2f76
commit c59e0f537a

View file

@ -238,6 +238,13 @@ export class BranchController extends Controller {
@Body() body: BranchUpdate,
@Path() branchId: string,
) {
if (body.headOfficeId === branchId)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Cannot make this as head office and branch at the same time.",
"missing_or_invalid_parameter",
);
if (body.subDistrictId || body.districtId || body.provinceId || body.headOfficeId) {
const [province, district, subDistrict, branch] = await prisma.$transaction([
prisma.province.findFirst({ where: { id: body.provinceId || undefined } }),