fix: permission & user code

This commit is contained in:
puriphat 2024-06-14 06:26:09 +00:00
parent d8a6565abe
commit 1048944773
2 changed files with 22 additions and 22 deletions

View file

@ -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",
);
}
}

View file

@ -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<string[]>((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(