From 5aded1d21527309d801e435d4fc121e393c996ce Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:55:54 +0700 Subject: [PATCH] feat: create branch contact endpoint --- src/controllers/branch/contact-controller.ts | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) 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, + ), + }); + } }