From c978d3adec8a3d75175da4afc7f3183bdd83d4d9 Mon Sep 17 00:00:00 2001 From: puriphat Date: Fri, 14 Jun 2024 05:43:32 +0000 Subject: [PATCH] fix: work & service code --- src/controllers/service/service-controller.ts | 10 +++++----- src/controllers/work/work-controller.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controllers/service/service-controller.ts b/src/controllers/service/service-controller.ts index ec88f63..60c926b 100644 --- a/src/controllers/service/service-controller.ts +++ b/src/controllers/service/service-controller.ts @@ -124,7 +124,7 @@ export class ServiceController extends Controller { }); if (!record) - throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "serviceNotFound"); return Object.assign(record, { imageUrl: await presignedGetObjectIfExist(MINIO_BUCKET, imageLocation(record.id), 60 * 60), @@ -173,7 +173,7 @@ export class ServiceController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Some product not found.", - "missing_or_invalid_parameter", + "someProductBadReq", ); } @@ -250,7 +250,7 @@ export class ServiceController extends Controller { @Path() serviceId: string, ) { if (!(await prisma.service.findUnique({ where: { id: serviceId } }))) { - throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "serviceNotFound"); } const record = await prisma.service.update({ @@ -276,11 +276,11 @@ export class ServiceController extends Controller { const record = await prisma.service.findFirst({ where: { id: serviceId } }); if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "serviceNotFound"); } if (record.status !== Status.CREATED) { - throw new HttpError(HttpStatus.FORBIDDEN, "Service is in used.", "data_in_used"); + throw new HttpError(HttpStatus.FORBIDDEN, "Service is in used.", "serviceInUsed"); } return await prisma.service.delete({ where: { id: serviceId } }); diff --git a/src/controllers/work/work-controller.ts b/src/controllers/work/work-controller.ts index 8bd491f..455e5d5 100644 --- a/src/controllers/work/work-controller.ts +++ b/src/controllers/work/work-controller.ts @@ -79,7 +79,7 @@ export class WorkController extends Controller { }); if (!record) - throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "workNotFound"); return record; } @@ -163,7 +163,7 @@ export class WorkController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Some product not found.", - "missing_or_invalid_parameter", + "someProductBadReq", ); } @@ -214,7 +214,7 @@ export class WorkController extends Controller { const { productId, ...payload } = body; if (!(await prisma.work.findUnique({ where: { id: workId } }))) { - throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "workNotFound"); } const exist = await prisma.work.findFirst({ @@ -301,11 +301,11 @@ export class WorkController extends Controller { const record = await prisma.work.findFirst({ where: { id: workId } }); if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "workNotFound"); } if (record.status !== Status.CREATED) { - throw new HttpError(HttpStatus.FORBIDDEN, "Work is in used.", "missing_or_invalid_parameter"); + throw new HttpError(HttpStatus.FORBIDDEN, "Work is in used.", "workInUsed"); } return await prisma.work.delete({ where: { id: workId } });