diff --git a/src/controllers/branch-controller.ts b/src/controllers/branch-controller.ts index 552e5e4..7febf1a 100644 --- a/src/controllers/branch-controller.ts +++ b/src/controllers/branch-controller.ts @@ -351,7 +351,7 @@ export class BranchController extends Controller { ); } - const { provinceId, districtId, subDistrictId, headOfficeId, ...rest } = body; + const { provinceId, districtId, subDistrictId, headOfficeId, telephoneNo, ...rest } = body; if (!(await prisma.branch.findUnique({ where: { id: branchId } }))) { throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found"); @@ -383,6 +383,16 @@ export class BranchController extends Controller { where: { id: branchId }, }); + if (record && telephoneNo) { + await prisma.branchContact.deleteMany({ where: { branchId } }); + await prisma.branchContact.createMany({ + data: + typeof telephoneNo === "string" + ? [{ telephoneNo, branchId }] + : telephoneNo.map((v) => ({ telephoneNo: v, branchId })), + }); + } + return Object.assign(record, { qrCodeImageUrl: await minio.presignedGetObject( MINIO_BUCKET,