From 6e6253887f4b3fabe1bc07ea7e344fc61add00d5 Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 26 Jan 2026 14:14:58 +0700 Subject: [PATCH] #2231 --- src/controllers/UserController.ts | 46 +++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 5d7d4910..ecfef0ca 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -472,9 +472,9 @@ export class KeycloakController extends Controller { @Post("user/admin") async listUserKeycloak( - @Request() req: RequestWithUser, - @Body() - body:{ + @Request() req: RequestWithUser, + @Body() + body: { page: number, pageSize: number, keyword: string | null, @@ -507,9 +507,9 @@ export class KeycloakController extends Controller { let typeCondition = ""; let checkChildConditions = ""; - let conditions:any = {}; + let conditions: any = {}; - if(body.nodeId !== null && body.nodeId !== "" && body.nodeId !== undefined){ + if (body.nodeId !== null && body.nodeId !== "" && body.nodeId !== undefined) { if (body.node === 0) { typeCondition = `current_holders.orgRootId = '${body.nodeId}'`; if (!body.isAll) { @@ -533,9 +533,9 @@ export class KeycloakController extends Controller { } else if (body.node === 4) { typeCondition = `current_holders.orgChild4Id = '${body.nodeId}'`; } - + conditions = typeCondition; - if(checkChildConditions){ + if (checkChildConditions) { conditions += checkChildConditions; } } @@ -547,6 +547,11 @@ export class KeycloakController extends Controller { .createQueryBuilder("profile") .leftJoinAndSelect("profile.roleKeycloaks", "roleKeycloaks") .leftJoinAndSelect("profile.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .where("profile.keycloak IS NOT NULL AND profile.keycloak != ''") .andWhere(checkChildFromRole) .andWhere(conditions) @@ -566,6 +571,13 @@ export class KeycloakController extends Controller { }), ) .orderBy("profile.citizenId", "ASC") + .orderBy("orgRoot.orgRootOrder", "ASC") + .addOrderBy("orgChild1.orgChild1Order", "ASC") + .addOrderBy("orgChild2.orgChild2Order", "ASC") + .addOrderBy("orgChild3.orgChild3Order", "ASC") + .addOrderBy("orgChild4.orgChild4Order", "ASC") + .addOrderBy("current_holders.posMasterOrder", "ASC") + .addOrderBy("current_holders.posMasterCreatedAt", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); @@ -574,6 +586,11 @@ export class KeycloakController extends Controller { .createQueryBuilder("profileEmployee") .leftJoinAndSelect("profileEmployee.roleKeycloaks", "roleKeycloaks") .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .where("profileEmployee.keycloak IS NOT NULL AND profileEmployee.keycloak != ''") .andWhere(checkChildFromRole) .andWhere(conditions) @@ -598,6 +615,13 @@ export class KeycloakController extends Controller { }), ) .orderBy("profileEmployee.citizenId", "ASC") + .orderBy("orgRoot.orgRootOrder", "ASC") + .addOrderBy("orgChild1.orgChild1Order", "ASC") + .addOrderBy("orgChild2.orgChild2Order", "ASC") + .addOrderBy("orgChild3.orgChild3Order", "ASC") + .addOrderBy("orgChild4.orgChild4Order", "ASC") + .addOrderBy("current_holders.posMasterOrder", "ASC") + .addOrderBy("current_holders.posMasterCreatedAt", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); @@ -758,17 +782,17 @@ export class KeycloakController extends Controller { } @Get("user/role/{id}") - async getRoleUser(@Request() req: RequestWithUser,@Path("id") id: string) { - + async getRoleUser(@Request() req: RequestWithUser, @Path("id") id: string) { + const profile = await this.profileRepo.findOne({ where: { keycloak: id }, relations: ["roleKeycloaks"], }); - + if ( req.user.sub === id && req.user.role.some(x => x === 'ADMIN') && - !req.user.role.some(x => x === 'SUPER_ADMIN') + !req.user.role.some(x => x === 'SUPER_ADMIN') ) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่มีสิทธิ์เข้าถึงข้อมูลนี้"); }