fix: update contact endpoint

This commit is contained in:
Methapon2001 2024-04-17 13:46:16 +07:00
parent 63293b671b
commit f9eb48d741

View file

@ -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,