no message

This commit is contained in:
kittapath 2024-09-06 10:33:13 +07:00
parent 98ebf587a3
commit f23fd05c2a

View file

@ -218,37 +218,42 @@ export class PermissionOrgController extends Controller {
*
* @param {string} id Id
*/
@Get("{id}")
@Post("profile")
async GetById(
@Request() request: RequestWithUser,
@Path() id: string,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query()
searchField?: "fullName" | "position" | "posNo" | "postype" | "poslevel",
@Query() searchKeyword: string = "",
@Body()
requestBody: {
id: string | null;
page: number;
pageSize: number;
searchField?: "fullName" | "position" | "posNo" | "postype" | "poslevel";
searchKeyword: string;
},
) {
if (!request.user.role.includes("SUPER_ADMIN")) {
throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
}
const _permissionOrg = await this.orgRootRepository.findOne({
where: { id },
relations: ["permissionOrgRoots"],
});
if (!_permissionOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์โครงสร้างนี้");
let profiles: any = [];
if (requestBody.id != null) {
const _permissionOrg = await this.orgRootRepository.findOne({
where: { id: requestBody.id },
relations: ["permissionOrgRoots", "permissionOrgRoots.profileTree"],
});
if (!_permissionOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์โครงสร้างนี้");
}
profiles = await _permissionOrg.permissionOrgRoots.map((x) => x.profileTree.id);
}
let profiles = _permissionOrg.permissionOrgRoots.map((x) => x.profileTree);
let queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
if (searchField == "postype") {
if (requestBody.searchField == "postype") {
queryLike = "posLevel.name LIKE :keyword";
} else if (searchField == "poslevel") {
} else if (requestBody.searchField == "poslevel") {
queryLike = "posType.name LIKE :keyword";
} else if (searchField == "position") {
} else if (requestBody.searchField == "position") {
queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") {
} else if (requestBody.searchField == "posNo") {
queryLike = `CONCAT(
IFNULL(orgChild4.orgChild4ShortName, ''),
IFNULL(orgChild3.orgChild3ShortName, ''),
@ -269,19 +274,21 @@ export class PermissionOrgController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.andWhere(`current_holders.orgRootId IN (:...profiles)`, {
profiles: profiles,
.andWhere(`profile.id IN (:...profiles)`, {
profiles: profiles == null ? [] : profiles,
})
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
requestBody.searchKeyword != undefined &&
requestBody.searchKeyword != null &&
requestBody.searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
keyword: `%${requestBody.searchKeyword}%`,
},
)
.skip((page - 1) * pageSize)
.take(pageSize)
.skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize)
.getManyAndCount();
const findRevision = await this.orgRevisionRepository.findOne({
@ -392,14 +399,12 @@ export class PermissionOrgController extends Controller {
}
const orgRoot = await this.orgRootRepository.findOne({
where: { id: requestBody.nodeId },
relations: ["permissionOrgRoots"],
});
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสำนัก");
}
const profile = await this.profileRepository.findOne({
where: { id: requestBody.personId },
relations: ["permissionOrgRoots"],
});
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัติ");