From d97b1260cf8dabaf5f56c3f61d0fa749176b1703 Mon Sep 17 00:00:00 2001 From: puriphat Date: Fri, 14 Jun 2024 05:58:14 +0000 Subject: [PATCH] fix: customer branch code --- src/controllers/customer-branch-controller.ts | 30 +++++++++---------- src/controllers/customer-controller.ts | 22 +++++++------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index 2d40baf..5bd51c4 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -182,7 +182,7 @@ export class CustomerBranchController extends Controller { }); if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound"); } return record; @@ -250,25 +250,25 @@ export class CustomerBranchController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Province cannot be found.", - "missing_or_invalid_parameter", + "relationProvinceNotFound", ); if (body.districtId && !district) throw new HttpError( HttpStatus.BAD_REQUEST, "District cannot be found.", - "missing_or_invalid_parameter", + "relationDistrictNotFound", ); if (body.subDistrictId && !subDistrict) throw new HttpError( HttpStatus.BAD_REQUEST, "Sub-district cannot be found.", - "missing_or_invalid_parameter", + "relationSubDistrictNotFound", ); if (!customer) throw new HttpError( HttpStatus.BAD_REQUEST, "Customer cannot be found.", - "missing_or_invalid_parameter", + "relationCustomerNotFound", ); const { provinceId, districtId, subDistrictId, customerId, ...rest } = body; @@ -328,32 +328,32 @@ export class CustomerBranchController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Province cannot be found.", - "missing_or_invalid_parameter", + "relationProvinceNotFound", ); if (body.districtId && !district) throw new HttpError( HttpStatus.BAD_REQUEST, "District cannot be found.", - "missing_or_invalid_parameter", + "relationDistrictNotFound", ); if (body.subDistrictId && !subDistrict) throw new HttpError( HttpStatus.BAD_REQUEST, "Sub-district cannot be found.", - "missing_or_invalid_parameter", + "relationSubDistrictNotFound", ); if (body.customerId && !customer) throw new HttpError( HttpStatus.BAD_REQUEST, "Customer cannot be found.", - "missing_or_invalid_parameter", + "relationCustomerNotFound", ); } const { provinceId, districtId, subDistrictId, customerId, ...rest } = body; if (!(await prisma.customerBranch.findUnique({ where: { id: branchId } }))) { - throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound"); } const record = await prisma.customerBranch.update({ @@ -398,12 +398,12 @@ export class CustomerBranchController extends Controller { throw new HttpError( HttpStatus.NOT_FOUND, "Customer branch cannot be found.", - "data_not_found", + "customerBranchNotFound", ); } if (record.status !== Status.CREATED) { - throw new HttpError(HttpStatus.FORBIDDEN, "Customer branch is in used.", "data_in_used"); + throw new HttpError(HttpStatus.FORBIDDEN, "Customer branch is in used.", "customerBranchInUsed"); } return await prisma.customerBranch.delete({ where: { id: branchId } }).then((v) => { @@ -444,7 +444,7 @@ export class CustomerAttachmentController extends Controller { throw new HttpError( HttpStatus.NOT_FOUND, "Customer branch cannot be found.", - "data_not_found", + "customerBranchNotFound", ); } @@ -479,7 +479,7 @@ export class CustomerAttachmentController extends Controller { throw new HttpError( HttpStatus.NOT_FOUND, "Customer branch cannot be found.", - "data_not_found", + "customerBranchNotFound", ); } @@ -509,7 +509,7 @@ export class CustomerAttachmentController extends Controller { throw new HttpError( HttpStatus.NOT_FOUND, "Customer branch cannot be found.", - "data_not_found", + "customerBranchNotFound", ); } diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index d43fecd..0774a5a 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -211,7 +211,7 @@ export class CustomerController extends Controller { where: { id: customerId }, }); if (!record) - throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "customerNotFound"); return Object.assign(record, { imageUrl: await presignedGetObjectIfExist( MINIO_BUCKET, @@ -249,21 +249,21 @@ export class CustomerController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Some province cannot be found.", - "missing_or_invalid_parameter", + "relationProvinceNotFound", ); } if (districtId && district.length !== districtId?.length) { throw new HttpError( HttpStatus.BAD_REQUEST, "Some district cannot be found.", - "missing_or_invalid_parameter", + "relationDistrictNotFound", ); } if (subDistrictId && subDistrict.length !== subDistrictId?.length) { throw new HttpError( HttpStatus.BAD_REQUEST, "Some sub district cannot be found.", - "missing_or_invalid_parameter", + "relationSubDistrictNotFound", ); } @@ -338,7 +338,7 @@ export class CustomerController extends Controller { const customer = await prisma.customer.findUnique({ where: { id: customerId } }); if (!customer) { - throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "customerNotFound"); } const provinceId = body.customerBranch?.reduce((acc, cur) => { @@ -365,21 +365,21 @@ export class CustomerController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Some province cannot be found.", - "missing_or_invalid_parameter", + "relationProvinceNotFound", ); } if (districtId && district.length !== districtId?.length) { throw new HttpError( HttpStatus.BAD_REQUEST, "Some district cannot be found.", - "missing_or_invalid_parameter", + "relationDistrictNotFound", ); } if (subDistrictId && subDistrict.length !== subDistrictId?.length) { throw new HttpError( HttpStatus.BAD_REQUEST, "Some sub district cannot be found.", - "missing_or_invalid_parameter", + "relationSubDistrictNotFound", ); } @@ -398,7 +398,7 @@ export class CustomerController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "One or more branch cannot be delete and is missing.", - "missing_or_invalid_parameter", + "oneOrMoreBranchMissing", ); } @@ -490,11 +490,11 @@ export class CustomerController extends Controller { const record = await prisma.customer.findFirst({ where: { id: customerId } }); if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "customerNotFound"); } if (record.status !== Status.CREATED) { - throw new HttpError(HttpStatus.FORBIDDEN, "Customer is in used.", "data_in_used"); + throw new HttpError(HttpStatus.FORBIDDEN, "Customer is in used.", "customerInUsed"); } return await prisma.customer.delete({ where: { id: customerId } }).then((v) => {