From 37b919930f82fda45166c250d5e1fae41002fd7e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 27 Mar 2025 11:08:41 +0700 Subject: [PATCH] add api profile leave --- src/controllers/ProfileController.ts | 352 ++++++++++++++++++ src/controllers/ProfileEmployeeController.ts | 356 +++++++++++++++++++ 2 files changed, 708 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index c3d85d14..0ad007d5 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -5470,6 +5470,357 @@ export class ProfileController extends Controller { return new HttpSuccess(); } + /** + * API ค้นหาและแสดงผู้พ้นจากราชการ ข้าราชการ กทม. สามัญ + * + * @summary ค้นหาและแสดงผู้พ้นจากราชการ ข้าราชการ กทม. สามัญ จากตำแหน่ง + */ + @Get("profileLeave") + @Example({ + status: 200, + message: "สำเร็จ", + result: { + data: [ + { + id: "ecb0b34c-037e-41f2-b95e-7e19f88b42ae", + createdAt: "2024-03-24T12:39:12.105Z", + createdUserId: "00000000-0000-0000-0000-000000000000", + lastUpdatedAt: "2024-03-24T12:41:43.164Z", + lastUpdateUserId: "00000000-0000-0000-0000-000000000000", + createdFullName: "string", + lastUpdateFullName: "string", + rank: null, + prefix: null, + firstName: "Methapon", + lastName: "Metanipat", + citizenId: null, + position: null, + posLevelId: null, + posTypeId: null, + email: null, + phone: null, + keycloak: null, + isProbation: false, + dateRetire: null, + birthDate: null, + ethnicity: null, + telephoneNumber: null, + gender: null, + relationship: null, + bloodGroup: null, + posLevel: null, + posType: null, + org: null, + }, + ], + total: 1, + }, + }) + async listProfileLeave( + @Request() request: RequestWithUser, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query() + searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position" | "posNo", + @Query() searchKeyword: string = "", + @Query() posType?: string, + @Query() posLevel?: string, + @Query() yearLeave?: number, + @Query() isProbation?: boolean, + // @Query() isRetire?: boolean, + @Query() node?: number, + @Query() nodeId?: string, + @Query() isAll?: boolean, + @Query() retireType?: string, + @Query() sortBy: string = "current_holders.posMasterNo", + @Query() sort: "ASC" | "DESC" = "ASC", + ) { + let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); + let queryLike = + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; + if (searchField == "citizenId") { + queryLike = "profile.citizenId LIKE :keyword"; + } else if (searchField == "position") { + queryLike = "profile.position LIKE :keyword"; + } else if (searchField == "posNo") { + queryLike = ` + CASE + WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo) + WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo) + WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo) + WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo) + ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo) + END LIKE :keyword + `; + } + let nodeCondition = "1=1"; + let nodeAll = ""; + if (node === 0 && nodeId) { + nodeCondition = "current_holders.orgRootId = :nodeId"; + if (isAll == false) nodeAll = " AND current_holders.orgChild1Id IS NULL"; + } else if (node === 1 && nodeId) { + nodeCondition = "current_holders.orgChild1Id = :nodeId"; + if (isAll == false) nodeAll = " AND current_holders.orgChild2Id IS NULL"; + } else if (node === 2 && nodeId) { + nodeCondition = "current_holders.orgChild2Id = :nodeId"; + if (isAll == false) nodeAll = " AND current_holders.orgChild3Id IS NULL"; + } else if (node === 3 && nodeId) { + nodeCondition = "current_holders.orgChild3Id = :nodeId"; + if (isAll == false) nodeAll = " AND current_holders.orgChild4Id IS NULL"; + } else if (node === 4 && nodeId) { + nodeCondition = "current_holders.orgChild4Id = :nodeId"; + } + nodeCondition = nodeCondition + nodeAll; + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + const [record, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.positions", "positions") + .leftJoinAndSelect("positions.posExecutive", "posExecutive") + .leftJoinAndSelect("current_holders.orgRevision", "orgRevision") + .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(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", { + orgRevisionId: node && nodeId ? findRevision.id : undefined, + }) + .andWhere( + new Brackets(qb => { + qb.where("profile.isLeave IS TRUE") + .orWhere("profile.isRetirement IS TRUE"); + }) + ) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `current_holders.orgRootId IN (:...root)` + : `current_holders.orgRootId is null` + : "1=1", + { + root: _data.root, + }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `current_holders.orgChild1Id IN (:...child1)` + : `current_holders.orgChild1Id is null` + : "1=1", + { + child1: _data.child1, + }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `current_holders.orgChild2Id IN (:...child2)` + : `current_holders.orgChild2Id is null` + : "1=1", + { + child2: _data.child2, + }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `current_holders.orgChild3Id IN (:...child3)` + : `current_holders.orgChild3Id is null` + : "1=1", + { + child3: _data.child3, + }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `current_holders.orgChild4Id IN (:...child4)` + : `current_holders.orgChild4Id is null` + : "1=1", + { + child4: _data.child4, + }, + ) + .andWhere( + posType != undefined && posType != null && posType != "" + ? "posType.posTypeName LIKE :keyword1" + : "1=1", + { + keyword1: `${posType}`, + }, + ) + .andWhere( + posLevel != undefined && posLevel != null && posLevel != "" + ? "posLevel.posLevelName LIKE :keyword2" + : "1=1", + { + keyword2: `${posLevel}`, + }, + ) + .andWhere( + isProbation != undefined && isProbation != null + ? `profile.isProbation = ${isProbation}` + : "1=1", + ) + // .andWhere( + // isRetire != undefined && isRetire != null + // ? isRetire == false + // ? // ? `profile.dateLeave IS NULL` + // `profile.isLeave IS FALSE` + // : isRetire == true && retireType != undefined && retireType != null + // ? // ? `profile.dateLeave IS NOT NULL AND profile.leaveType = '${retireType}'` + // // : `profile.dateLeave IS NOT NULL` + // `profile.isLeave IS TRUE AND profile.leaveType = '${retireType}'` + // : `profile.isLeave IS TRUE` + // : "1=1", + // ) + .andWhere(nodeCondition, { + nodeId: nodeId, + }) + + .andWhere( + new Brackets((qb) => { + qb.orWhere( + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + ? queryLike + : "1=1", + { + keyword: `%${searchKeyword}%`, + }, + ); + }), + ) + // .orderBy("current_holders.posMasterNo", "ASC") + .orderBy(`${sortBy}`, sort) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + const data = await Promise.all( + record.map((_data) => { + const posExecutive = + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions.length == + 0 || + _data.current_holders + .find((x) => x.orgRevisionId == findRevision.id) + ?.positions.find((x: any) => x.positionIsSelected == true) == null || + _data.current_holders + .find((x) => x.orgRevisionId == findRevision.id) + ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null + ? null + : _data.current_holders + .find((x) => x.orgRevisionId == findRevision.id) + ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive + ?.posExecutiveName; + + const shortName = + _data.current_holders.length == 0 + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != + null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild3 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild2 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild1 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgRoot != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : null; + const root = + _data.current_holders.length == 0 || + (_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; + + const child1 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1; + + const child2 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2; + + const child3 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3; + + const child4 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4; + + let _child1 = child1?.orgChild1Name; + let _child2 = child2?.orgChild2Name; + let _child3 = child3?.orgChild3Name; + let _child4 = child4?.orgChild4Name; + + return { + id: _data.id, + avatar: _data.avatar, + avatarName: _data.avatarName, + dateAppoint: _data.dateAppoint, + prefix: _data.prefix, + rank: _data.rank, + firstName: _data.firstName, + lastName: _data.lastName, + citizenId: _data.citizenId, + posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posType: _data.posType == null ? null : _data.posType.posTypeName, + posLevelId: _data.posLevel == null ? null : _data.posLevel.id, + posTypeId: _data.posType == null ? null : _data.posType.id, + position: _data.position, + posExecutive: posExecutive, + posNo: shortName, + rootId: root == null ? null : root.id, + root: root == null ? null : root.orgRootName, + orgRootShortName: root == null ? null : root.orgRootShortName, + orgRevisionId: root == null ? null : root.orgRevisionId, + org: (_child4 == null ? "" : _child4 + "\n") + + (_child3 == null ? "" : _child3 + "\n") + + (_child2 == null ? "" : _child2 + "\n") + + (_child1 == null ? "" : _child1 + "\n") + + (root?.orgRootName == null ? "" : root?.orgRootName), + }; + }), + ); + + return new HttpSuccess({ data: data, total }); + } + /** * API รายละเอียดรายการทะเบียนประวัติ * @@ -5886,6 +6237,7 @@ export class ProfileController extends Controller { return new HttpSuccess({ data: data, total }); } + /** * API ค้นหารายชื่อไปครองตำแหน่ง * diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 8f4b4954..ce125822 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1650,6 +1650,362 @@ export class ProfileEmployeeController extends Controller { }); return new HttpSuccess(); } + + /** + * API ค้นหาและแสดงผู้พ้นจากราชการ ลูกจ้างประจำ กทม. + * + * @summary ค้นหาและแสดงผู้พ้นจากราชการ ลูกจ้างประจำ กทม. + * + */ + @Get("profileLeave") + async listProfileLeave( + @Request() request: RequestWithUser, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query() + searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position" | "posNo", + @Query() searchKeyword: string = "", + @Query() posType?: string, + @Query() posLevel?: string, + @Query() yearLeave?: number, + @Query() isProbation?: boolean, + // @Query() isRetire?: boolean, + @Query() type?: string, + @Query() node?: number, + @Query() nodeId?: string, + @Query() isAll?: boolean, + @Query() retireType?: string, + @Query() sortBy: string = "current_holders.posMasterNo", + @Query() sort: "ASC" | "DESC" = "ASC", + ) { + let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP"); + let queryLike = + "CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword"; + if (searchField == "citizenId") { + queryLike = "profileEmployee.citizenId LIKE :keyword"; + } else if (searchField == "position") { + queryLike = "profileEmployee.position LIKE :keyword"; + } else if (searchField == "posNo") { + queryLike = ` + CASE + WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo) + WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo) + WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo) + WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo) + ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo) + END LIKE :keyword + `; + } + let nodeCondition = "1=1"; + let nodeAll = ""; + if (node === 0 && nodeId) { + nodeCondition = "current_holders.orgRootId = :nodeId"; + if (isAll == false) nodeAll = " AND current_holders.orgChild1Id IS NULL"; + } else if (node === 1 && nodeId) { + nodeCondition = "current_holders.orgChild1Id = :nodeId"; + if (isAll == false) nodeAll = " AND current_holders.orgChild2Id IS NULL"; + } else if (node === 2 && nodeId) { + nodeCondition = "current_holders.orgChild2Id = :nodeId"; + if (isAll == false) nodeAll = " AND current_holders.orgChild3Id IS NULL"; + } else if (node === 3 && nodeId) { + nodeCondition = "current_holders.orgChild3Id = :nodeId"; + if (isAll == false) nodeAll = " AND current_holders.orgChild4Id IS NULL"; + } else if (node === 4 && nodeId) { + nodeCondition = "current_holders.orgChild4Id = :nodeId"; + } + nodeCondition = nodeCondition + nodeAll; + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + const [record, total] = await this.profileRepo + .createQueryBuilder("profileEmployee") + .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") + .leftJoinAndSelect("profileEmployee.posType", "posType") + .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") + .leftJoinAndSelect("profileEmployee.profileEmployeeEmployment", "profileEmployeeEmployment") + .leftJoinAndSelect("current_holders.positions", "positions") + .leftJoinAndSelect("current_holders.orgRevision", "orgRevision") + .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(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", { + orgRevisionId: node && nodeId ? findRevision.id : undefined, + }) + .andWhere( + new Brackets(qb => { + qb.where("profileEmployee.isLeave IS TRUE") + .orWhere("profileEmployee.isRetirement IS TRUE"); + }) + ) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `current_holders.orgRootId IN (:...root)` + : `current_holders.orgRootId is null` + : "1=1", + { + root: _data.root, + }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `current_holders.orgChild1Id IN (:...child1)` + : `current_holders.orgChild1Id is null` + : "1=1", + { + child1: _data.child1, + }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `current_holders.orgChild2Id IN (:...child2)` + : `current_holders.orgChild2Id is null` + : "1=1", + { + child2: _data.child2, + }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `current_holders.orgChild3Id IN (:...child3)` + : `current_holders.orgChild3Id is null` + : "1=1", + { + child3: _data.child3, + }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `current_holders.orgChild4Id IN (:...child4)` + : `current_holders.orgChild4Id is null` + : "1=1", + { + child4: _data.child4, + }, + ) + .andWhere( + posType != undefined && posType != null && posType != "" + ? "posType.posTypeName LIKE :keyword1" + : "1=1", + { + keyword1: `${posType}`, + }, + ) + .andWhere( + posLevel != undefined && posLevel != null && posLevel != "" + ? `CONCAT(posType.posTypeShortName,' ',posLevel.posLevelName) LIKE :keyword2` + : "1=1", + { + keyword2: `${posLevel}`, + }, + ) + .andWhere( + isProbation != undefined && isProbation != null + ? `profileEmployee.isProbation = ${isProbation}` + : "1=1", + ) + // .andWhere( + // isRetire != undefined && isRetire != null + // ? isRetire == false + // ? `profileEmployee.isLeave IS FALSE` + // : isRetire == true && retireType != undefined && retireType != null + // ? `profileEmployee.isLeave IS TRUE AND profileEmployee.leaveType = '${retireType}'` + // : `profileEmployee.isLeave IS TRUE` + // : "1=1", + // ) + .andWhere("profileEmployee.employeeClass LIKE :type", { + type: "PERM", + }) + .andWhere( + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + ? queryLike + : "1=1", + { + keyword: `%${searchKeyword}%`, + }, + ) + .andWhere(nodeCondition, { + nodeId: nodeId, + }) + // .andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, { + // orgRevisionId: findRevision.id, + // }) + // .orderBy("current_holders.posMasterNo", "ASC") + .orderBy(`${sortBy}`, sort) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const data = await Promise.all( + record.map((_data) => { + const shortName = + _data.current_holders.length == 0 + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != + null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild3 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild2 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild1 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgRoot != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : null; + const dateEmployment = + _data.profileEmployeeEmployment.length == 0 + ? null + : _data.profileEmployeeEmployment.reduce((latest, current) => { + return latest.date > current.date ? latest : current; + }).date; + const root = + _data.current_holders.length == 0 || + (_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; + + const child1 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1; + + const child2 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2; + + const child3 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3; + + const child4 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4; + + let _child1 = child1?.orgChild1Name; + let _child2 = child2?.orgChild2Name; + let _child3 = child3?.orgChild3Name; + let _child4 = child4?.orgChild4Name; + return { + id: _data.id, + prefix: _data.prefix, + rank: _data.rank, + firstName: _data.firstName, + lastName: _data.lastName, + citizenId: _data.citizenId, + posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posType: _data.posType == null ? null : _data.posType.posTypeName, + posTypeShortName: _data.posType == null ? null : _data.posType.posTypeShortName, + posLevelId: _data.posLevel == null ? null : _data.posLevel.id, + posTypeId: _data.posType == null ? null : _data.posType.id, + positionId: _data.positionIdTemp, + posmasterId: _data.posmasterIdTemp, + position: _data.position, + posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName, + employeeClass: _data.employeeClass == null ? null : _data.employeeClass, + govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + dateEmployment: dateEmployment, + dateAppoint: _data.dateAppoint, + dateStart: _data.dateStart, + createdAt: _data.createdAt, + dateRetireLaw: _data.dateRetireLaw, + draftOrganizationOrganization: + _data.nodeTemp == "0" + ? _data.rootTemp + : _data.nodeTemp == "1" + ? _data.child1Temp + : _data.nodeTemp == "2" + ? _data.child2Temp + : _data.nodeTemp == "3" + ? _data.child3Temp + : _data.nodeTemp == "4" + ? _data.child4Temp + : null, + draftPositionEmployee: _data.positionTemp, + draftOrgEmployeeStatus: _data.statusTemp, + node: _data.nodeTemp, + nodeId: _data.nodeIdTemp, + nodeName: + _data.nodeTemp == "0" + ? _data.rootTemp + : _data.nodeTemp == "1" + ? _data.child1Temp + : _data.nodeTemp == "2" + ? _data.child2Temp + : _data.nodeTemp == "3" + ? _data.child3Temp + : _data.nodeTemp == "4" + ? _data.child4Temp + : null, + nodeShortName: + _data.nodeTemp == "0" + ? _data.rootShortNameTemp + : _data.nodeTemp == "1" + ? _data.child1ShortNameTemp + : _data.nodeTemp == "2" + ? _data.child1ShortNameTemp + : _data.nodeTemp == "3" + ? _data.child3ShortNameTemp + : _data.nodeTemp == "4" + ? _data.child4ShortNameTemp + : null, + root: _data.rootTemp ? _data.rootTemp : null, + rootId: _data.rootIdTemp ? _data.rootIdTemp : null, + rootShortName: _data.rootShortNameTemp ? _data.rootShortNameTemp : null, + child1: _data.child1Temp ? _data.child1Temp : null, + child1Id: _data.child1IdTemp ? _data.child1IdTemp : null, + child1ShortName: _data.child1ShortNameTemp ? _data.child1ShortNameTemp : null, + child2: _data.child2Temp ? _data.child2Temp : null, + child2Id: _data.child2IdTemp ? _data.child2IdTemp : null, + child2ShortName: _data.child2ShortNameTemp ? _data.child2ShortNameTemp : null, + child3: _data.child3Temp ? _data.child3Temp : null, + child3Id: _data.child3IdTemp ? _data.child3IdTemp : null, + child3ShortName: _data.child3ShortNameTemp ? _data.child3ShortNameTemp : null, + child4: _data.child4Temp ? _data.child4Temp : null, + child4Id: _data.child4IdTemp ? _data.child4IdTemp : null, + child4ShortName: _data.child4ShortNameTemp ? _data.child4ShortNameTemp : null, + org: (_child4 == null ? "" : _child4 + "\n") + + (_child3 == null ? "" : _child3 + "\n") + + (_child2 == null ? "" : _child2 + "\n") + + (_child1 == null ? "" : _child1 + "\n") + + (root?.orgRootName == null ? "" : root?.orgRootName), + }; + }), + ); + + return new HttpSuccess({ data: data, total }); + } /** * API รายละเอียดรายการทะเบียนประวัติ