From 10489447736c883c1f99c298d6326522c25c6f5e Mon Sep 17 00:00:00 2001 From: puriphat Date: Fri, 14 Jun 2024 06:26:09 +0000 Subject: [PATCH] fix: permission & user code --- src/controllers/permission-controller.ts | 26 ++++++++++++------------ src/controllers/user-controller.ts | 18 ++++++++-------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/controllers/permission-controller.ts b/src/controllers/permission-controller.ts index 0ea14e0..d10c649 100644 --- a/src/controllers/permission-controller.ts +++ b/src/controllers/permission-controller.ts @@ -41,7 +41,7 @@ export class MenuController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Parent menu not found.", - "missing_or_invalid_parameter", + "parentMenuBadReq", ); } } @@ -66,7 +66,7 @@ export class MenuController extends Controller { }) .catch((e) => { if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") { - throw new HttpError(HttpStatus.NOT_FOUND, "Menu cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Menu cannot be found.", "menuNotFound"); } throw new Error(e); }); @@ -78,7 +78,7 @@ export class MenuController extends Controller { async deleteMenu(@Path("menuId") id: string) { const record = await prisma.menu.deleteMany({ where: { id } }); if (record.count <= 0) { - throw new HttpError(HttpStatus.NOT_FOUND, "Menu cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Menu cannot be found.", "menuNotFound"); } } } @@ -114,7 +114,7 @@ export class RoleMenuController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Menu not found.", - "missing_or_invalid_parameter", + "menuBadReq", ); } @@ -140,7 +140,7 @@ export class RoleMenuController extends Controller { }) .catch((e) => { if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") { - throw new HttpError(HttpStatus.NOT_FOUND, "Role menu cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Role menu cannot be found.", "roleMenuNotFound"); } throw new Error(e); }); @@ -154,7 +154,7 @@ export class RoleMenuController extends Controller { where: { id, menuId }, }); if (record.count <= 0) { - throw new HttpError(HttpStatus.NOT_FOUND, "Role menu cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "Role menu cannot be found.", "roleMenuNotFound"); } } } @@ -193,7 +193,7 @@ export class MenuComponentController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Menu not found.", - "missing_or_invalid_parameter", + "menuBadReq", ); } @@ -215,7 +215,7 @@ export class MenuComponentController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Menu not found.", - "missing_or_invalid_parameter", + "menuBadReq", ); } } @@ -231,7 +231,7 @@ export class MenuComponentController extends Controller { throw new HttpError( HttpStatus.NOT_FOUND, "Menu component cannot be found.", - "data_not_found", + "menuComponentNotFound", ); } throw new Error(e); @@ -247,7 +247,7 @@ export class MenuComponentController extends Controller { throw new HttpError( HttpStatus.NOT_FOUND, "Menu component cannot be found.", - "data_not_found", + "menuComponentNotFound", ); } } @@ -287,7 +287,7 @@ export class RoleMenuComponentController extends Controller { throw new HttpError( HttpStatus.BAD_REQUEST, "Menu not found.", - "missing_or_invalid_parameter", + "menuBadReq", ); } @@ -316,7 +316,7 @@ export class RoleMenuComponentController extends Controller { throw new HttpError( HttpStatus.NOT_FOUND, "Role menu component cannot be found.", - "data_not_found", + "roleMenuNotFound", ); } throw new Error(e); @@ -337,7 +337,7 @@ export class RoleMenuComponentController extends Controller { throw new HttpError( HttpStatus.NOT_FOUND, "Role menu component cannot be found.", - "data_not_found", + "roleMenuNotFound", ); } } diff --git a/src/controllers/user-controller.ts b/src/controllers/user-controller.ts index 2e0951a..06e58e8 100644 --- a/src/controllers/user-controller.ts +++ b/src/controllers/user-controller.ts @@ -210,7 +210,7 @@ export class UserController extends Controller { }); if (!record) - throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "userNotFound"); return Object.assign(record, { profileImageUrl: await minio.presignedGetObject( @@ -233,21 +233,21 @@ export class UserController 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", ); } } @@ -396,7 +396,7 @@ export class UserController extends Controller { }); if (!user) { - 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 lastUserOfType = @@ -463,11 +463,11 @@ export class UserController extends Controller { }); if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "userNotFound"); } if (record.status !== Status.CREATED) { - throw new HttpError(HttpStatus.FORBIDDEN, "User is in used.", "data_in_used"); + throw new HttpError(HttpStatus.FORBIDDEN, "User is in used.", "userInUsed"); } await minio.removeObject(MINIO_BUCKET, imageLocation(userId), { @@ -521,7 +521,7 @@ export class UserAttachmentController extends Controller { }); if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "userNotFound"); } const list = await new Promise((resolve, reject) => { @@ -554,7 +554,7 @@ export class UserAttachmentController extends Controller { }); if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "data_not_found"); + throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "userNotFound"); } return await Promise.all(