From ef88a48d0cf3cd335e8df1fdd7807650fec784ae Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 5 Apr 2024 11:18:01 +0700 Subject: [PATCH] feat: edit customer endpoint --- src/controllers/customer-controller.ts | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index acc12a2..fe7d347 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -121,6 +121,39 @@ export class CustomerController extends Controller { }); } + @Put("{customerId}") + async editById( + @Path() customerId: string, + @Request() req: RequestWithUser, + @Body() body: CustomerUpdate, + ) { + const record = await prisma.customer.update({ + where: { id: customerId }, + data: { + ...body, + createdBy: req.user.name, + updateBy: req.user.name, + }, + }); + + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found."); + } + + return Object.assign(record, { + imageUrl: await minio.presignedGetObject( + MINIO_BUCKET, + imageLocation(record.id), + 12 * 60 * 60, + ), + imageUploadUrl: await minio.presignedPutObject( + MINIO_BUCKET, + imageLocation(record.id), + 12 * 60 * 60, + ), + }); + } + @Delete("{customerId}") async deleteById(@Path() customerId: string) { const record = await prisma.customer.findFirst({ where: { id: customerId } });