diff --git a/src/controllers/branch/contact-controller.ts b/src/controllers/branch/contact-controller.ts index f782271..479dc5b 100644 --- a/src/controllers/branch/contact-controller.ts +++ b/src/controllers/branch/contact-controller.ts @@ -29,4 +29,30 @@ const MINIO_BUCKET = process.env.MINIO_BUCKET; @Tags("Branch Contact") @Security("keycloak") export class BranchContactController extends Controller { + @Post() + async createBranchContact( + @Request() req: RequestWithUser, + @Path() branchId: string, + @Body() body: BranchContactCreate, + ) { + if (!(await prisma.branch.findFirst({ where: { id: branchId } }))) { + throw new HttpError(HttpStatus.BAD_REQUEST, "Branch not found."); + } + const record = await prisma.branchContact.create({ + include: { branch: true }, + data: { ...body, branchId, createdBy: req.user.name, updateBy: req.user.name }, + }); + return Object.assign(record, { + qrCodeImageUrl: await minio.presignedGetObject( + MINIO_BUCKET, + `branch/contact-${record.id}`, + 12 * 60 * 60, + ), + qrCodeImageUploadUrl: await minio.presignedPutObject( + MINIO_BUCKET, + `branch/contact-${record.id}`, + 12 * 60 * 60, + ), + }); + } }