From d7b7a6ebee6cf983ccb4669d92d17e886b82a920 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:25:28 +0700 Subject: [PATCH] feat: get branch endpoint --- src/controllers/branch/contact-controller.ts | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/controllers/branch/contact-controller.ts b/src/controllers/branch/contact-controller.ts index dcb7541..a673f2d 100644 --- a/src/controllers/branch/contact-controller.ts +++ b/src/controllers/branch/contact-controller.ts @@ -43,6 +43,35 @@ function imageLocation(id: string) { @Tags("Branch Contact") @Security("keycloak") export class BranchContactController extends Controller { + @Get() + async getBranchContact( + @Path() branchId: string, + @Query() page: number = 1, + @Query() pageSize: number = 30, + ) { + const [result, total] = await prisma.$transaction([ + prisma.branchContact.findMany({ + where: { branchId }, + take: pageSize, + skip: (page - 1) * pageSize, + }), + prisma.branchContact.count({ where: { branchId } }), + ]); + + return { result, page, pageSize, total }; + } + + @Get("{contactId}") + async getBranchContactById(@Path() branchId: string, @Path() contactId: string) { + const record = await prisma.branchContact.findFirst({ where: { id: contactId, branchId } }); + + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found."); + + return Object.assign(record, { + qrCodeImageUrl: await minio.presignedGetObject(MINIO_BUCKET, imageLocation(record.id)), + }); + } + @Post() async createBranchContact( @Request() req: RequestWithUser,