diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 5852b7b8..6faf820f 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2556,13 +2556,15 @@ export class ProfileController extends Controller { async listProfile( @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, - @Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position", + @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, ) { let queryLike = "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; @@ -2570,6 +2572,27 @@ export class ProfileController extends Controller { queryLike = "profile.citizenId LIKE :keyword"; } else if (searchField == "position") { queryLike = "profile.position LIKE :keyword"; + } else if (searchField == "posNo") { + queryLike = `CONCAT( + IFNULL(orgChild4.orgChild4ShortName, ''), + IFNULL(orgChild3.orgChild3ShortName, ''), + IFNULL(orgChild2.orgChild2ShortName, ''), + IFNULL(orgChild1.orgChild1ShortName, ''), + IFNULL(orgRoot.orgRootShortName, ''), + IFNULL(current_holders.posMasterNo , '') + ) LIKE :keyword`; + } + let nodeCondition = "1=1"; + if (node === 0 && nodeId) { + nodeCondition = "current_holders.orgRootId = :nodeId"; + } else if (node === 1 && nodeId) { + nodeCondition = "current_holders.orgChild1Id = :nodeId"; + } else if (node === 2 && nodeId) { + nodeCondition = "current_holders.orgChild2Id = :nodeId"; + } else if (node === 3 && nodeId) { + nodeCondition = "current_holders.orgChild3Id = :nodeId"; + } else if (node === 4 && nodeId) { + nodeCondition = "current_holders.orgChild4Id = :nodeId"; } const [record, total] = await this.profileRepo .createQueryBuilder("profile") @@ -2619,9 +2642,13 @@ export class ProfileController extends Controller { keyword: `%${searchKeyword}%`, }, ) + .andWhere(nodeCondition, { + nodeId: nodeId, + }) .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); + const findRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true }, });