From cb5d7ae208cecfc4fca68edea4c71bd0e2cc77e5 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:09:53 +0700 Subject: [PATCH] fix: error when update record not found --- src/controllers/customer-controller.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index c2a8b52..4be81cf 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -134,6 +134,10 @@ export class CustomerController extends Controller { @Request() req: RequestWithUser, @Body() body: CustomerUpdate, ) { + if (!(await prisma.customer.findUnique({ where: { id: customerId } }))) { + throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found"); + } + const record = await prisma.customer.update({ where: { id: customerId }, data: { @@ -143,10 +147,6 @@ export class CustomerController extends Controller { }, }); - if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found."); - } - return Object.assign(record, { imageUrl: await minio.presignedGetObject( MINIO_BUCKET,