From c84a626911b01b0fb0660b60f268ba2c25e4f98e Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 24 Jan 2025 15:52:16 +0700 Subject: [PATCH] =?UTF-8?q?list=20=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=A1?= =?UTF-8?q?=E0=B8=B5=E0=B8=AD=E0=B8=B3=E0=B8=99=E0=B8=B2=E0=B8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 179 +++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 55dd0b46..86e16483 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1654,6 +1654,185 @@ export class ProfileController extends Controller { return new HttpSuccess({ data: lists, total }); } } + /** + * + * + */ + @Post("commander-director-position") + async getProfileCommanderDirectorPosition( + @Request() request: RequestWithUser, + @Body() + body: { + isAct: boolean; + isDirector: boolean; + keyword: string; + page: number; + pageSize: number; + }, + ) { + let posMaster = await this.posMasterRepo.findOne({ + where: { + current_holder: { keycloak: request.user.sub }, + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + }, + relations: ["current_holder", "current_holder.posLevel"], + }); + if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง"); + if (posMaster?.current_holder?.posLevel?.posLevelAuthority ?? null == "DEPUTY") { + posMaster = await this.posMasterRepo.findOne({ + where: { + orgRoot: { isDeputy: true }, + orgChild1Id: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + }, + }); + if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างปลัด"); + } else if (posMaster?.current_holder?.posLevel?.posLevelAuthority ?? null == "GOVERNOR") { + return new HttpSuccess({ data: [], total: 0 }); + } + let condition: any = { + orgRootId: posMaster.orgRootId, + id: Not(posMaster.current_holderId || ""), + }; + let conditionNow: any = { + orgRootId: posMaster.orgRootId ?? IsNull(), + orgChild1Id: posMaster.orgChild1Id ?? IsNull(), + orgChild2Id: posMaster.orgChild2Id ?? IsNull(), + orgChild3Id: posMaster.orgChild3Id ?? IsNull(), + orgChild4Id: posMaster.orgChild4Id ?? IsNull(), + id: Not(posMaster.current_holderId), + }; + if ( + posMaster.orgRootId == null || + posMaster.orgChild1Id == null || + posMaster.orgChild2Id == null + ) { + condition.orgChild1Id = IsNull(); + } else if (posMaster.orgChild3Id == null) { + condition.orgChild2Id = IsNull(); + } else if (posMaster.orgChild4Id == null) { + condition.orgChild3Id = IsNull(); + } else if (posMaster.orgChild4Id != null) { + condition.orgChild4Id = IsNull(); + } + if (body.isDirector == true) { + condition.isDirector = true; + conditionNow.isDirector = true; + } + if (body.isAct == true) { + const [lists, total] = await AppDataSource.getRepository(viewDirectorActing) + .createQueryBuilder("viewDirectorActing") + .andWhere( + new Brackets((qb) => { + qb.orWhere(condition).orWhere(conditionNow); + }), + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere( + body.keyword != null && body.keyword != "" + ? "CONCAT(viewDirectorActing.prefix,viewDirectorActing.firstName,' ',viewDirectorActing.lastName) LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.position LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.actFullName LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "CONCAT(viewDirectorActing.posType, ' (', viewDirectorActing.posLevel, ')') LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.posNo LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ); + }), + ) + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) + .getManyAndCount(); + return new HttpSuccess({ data: lists, total }); + } else { + const [lists, total] = await AppDataSource.getRepository(viewDirector) + .createQueryBuilder("viewDirector") + .andWhere( + new Brackets((qb) => { + qb.orWhere(condition).orWhere(conditionNow); + }), + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere( + body.keyword != null && body.keyword != "" + ? "CONCAT(viewDirector.prefix,viewDirector.firstName,' ',viewDirector.lastName) LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.position LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.actFullName LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "CONCAT(viewDirector.posType, ' (', viewDirector.posLevel, ')') LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.posNo LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ); + }), + ) + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) + .getManyAndCount(); + return new HttpSuccess({ data: lists, total }); + } + } /** * API เลือกผู้ประเมินสำหรับ User (ADMIN)