From 63de7b3e52582fedb3ed3a2fe624ff1ab9da5fcd Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:21:19 +0700 Subject: [PATCH] feat: edit 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 a1bcb3d..dcb7541 100644 --- a/src/controllers/branch/contact-controller.ts +++ b/src/controllers/branch/contact-controller.ts @@ -70,6 +70,35 @@ export class BranchContactController extends Controller { }); } + @Patch("{contactId}") + async editBranchContact( + @Request() req: RequestWithUser, + @Body() body: BranchContactUpdate, + @Path() branchId: string, + @Path() contactId: string, + ) { + const record = await prisma.branchContact.update({ + include: { branch: true }, + data: { ...body, updateBy: req.user.name }, + where: { id: contactId, branchId }, + }); + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found."); + } + return Object.assign(record, { + qrCodeImageUrl: await minio.presignedGetObject( + MINIO_BUCKET, + imageLocation(record.id), + 12 * 60 * 60, + ), + qrCodeImageUploadUrl: await minio.presignedPutObject( + MINIO_BUCKET, + imageLocation(record.id), + 12 * 60 * 60, + ), + }); + } + @Delete("{contactId}") async deleteBranchContact(@Path() branchId: string, @Path() contactId: string) { const result = await prisma.branchContact.deleteMany({ where: { id: contactId, branchId } });