diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 62beaf69..cd5b62dd 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2830,78 +2830,78 @@ export class ProfileController extends Controller { return new HttpSuccess(historyProfile); } - - /** + + /** * API รายการทะเบียนประวัติในระบบอื่น * * @summary ORG_065 - รายการทะเบียนประวัติในระบบอื่น * */ - @Get("otherSystem") - @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 listProfileNoPermission( - @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, - ) { - 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 = `CONCAT( + @Get("otherSystem") + @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 listProfileNoPermission( + @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, + ) { + 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 = `CONCAT( IFNULL(orgChild4.orgChild4ShortName, ''), IFNULL(orgChild3.orgChild3ShortName, ''), IFNULL(orgChild2.orgChild2ShortName, ''), @@ -2909,197 +2909,197 @@ export class ProfileController extends Controller { IFNULL(orgRoot.orgRootShortName, ''), IFNULL(current_holders.posMasterNo , '') ) 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 [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.orgRoot", "orgRoot") - .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") - .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") - .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") - .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") - .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.dateLeave IS NOT NULL` - : "1=1", - ) - .andWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" - ? queryLike - : "1=1", - { - keyword: `%${searchKeyword}%`, - }, - ) - .andWhere(nodeCondition, { - nodeId: nodeId, - }) - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); - - const findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, - }); - if (!findRevision) { - throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); - } - 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 == null ? "" : `${child1.orgChild1Name}/`; - let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`; - let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`; - let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`; - - return { - id: _data.id, - avatar: _data.avatar, - avatarName: _data.avatarName, - 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}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`, - }; - }), - ); - - return new HttpSuccess({ data: data, total }); - } + } + 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 [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.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + .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.dateLeave IS NOT NULL` + : "1=1", + ) + .andWhere( + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + ? queryLike + : "1=1", + { + keyword: `%${searchKeyword}%`, + }, + ) + .andWhere(nodeCondition, { + nodeId: nodeId, + }) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + 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 == null ? "" : `${child1.orgChild1Name}/`; + let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`; + let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`; + let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`; + + return { + id: _data.id, + avatar: _data.avatar, + avatarName: _data.avatarName, + 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}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`, + }; + }), + ); + + return new HttpSuccess({ data: data, total }); + } /** * API รายละเอียดรายการทะเบียนประวัติ @@ -5346,6 +5346,7 @@ export class ProfileController extends Controller { */ @Post("probation") async getProfileBySearchKeywordProbation( + @Request() request: RequestWithUser, @Body() body: { page: number; @@ -5353,7 +5354,17 @@ export class ProfileController extends Controller { keyword?: string; }, ) { + let _data: any = { + root: null, + child1: null, + child2: null, + child3: null, + child4: null, + }; const isProbation: boolean = true; + if (!request.user.role.includes("SUPER_ADMIN")) { + _data = await new permission().PermissionOrgCreate(request, "SYS_PROBATION"); + } const [findProfile, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .leftJoinAndSelect("profile.profileSalary", "profileSalary") @@ -5368,24 +5379,81 @@ export class ProfileController extends Controller { .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("positions.posExecutive", "posExecutive") - .where(`profile.prefix LIKE :keyword and profile.isProbation = ${isProbation}`, { - keyword: `%${body.keyword}%`, - }) - .orWhere(`profile.firstName LIKE :keyword and profile.isProbation = ${isProbation}`, { - keyword: `%${body.keyword}%`, - }) - .orWhere(`profile.lastName LIKE :keyword and profile.isProbation = ${isProbation}`, { - keyword: `%${body.keyword}%`, - }) - .orWhere(`profile.position LIKE :keyword and profile.isProbation = ${isProbation}`, { - keyword: `%${body.keyword}%`, - }) - .orWhere(`posLevel.posLevelName LIKE :keyword and profile.isProbation = ${isProbation}`, { - keyword: `%${body.keyword}%`, - }) - .orWhere(`posType.posTypeName LIKE :keyword and profile.isProbation = ${isProbation}`, { - keyword: `%${body.keyword}%`, - }) + .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( + new Brackets((qb) => { + qb.orWhere(`profile.prefix LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere(`profile.firstName LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere(`profile.lastName LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere(`profile.position LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere( + `posLevel.posLevelName LIKE :keyword and profile.isProbation = ${isProbation}`, + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere(`posType.posTypeName LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }); + }), + ) .orderBy("profile.citizenId", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) @@ -6936,6 +7004,4 @@ export class ProfileController extends Controller { ]); return new HttpSuccess(); } - - } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index d7918565..164b087c 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2539,6 +2539,7 @@ export class ProfileEmployeeController extends Controller { */ @Post("probation") async getProfileBySearchKeywordProbation( + @Request() request: RequestWithUser, @Body() body: { page: number; @@ -2546,6 +2547,16 @@ export class ProfileEmployeeController extends Controller { keyword?: string; }, ) { + let _data: any = { + root: null, + child1: null, + child2: null, + child3: null, + child4: null, + }; + if (!request.user.role.includes("SUPER_ADMIN")) { + _data = await new permission().PermissionOrgCreate(request, "SYS_PROBATION"); + } const [findProfile, total] = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") .leftJoinAndSelect("profile.posLevel", "posLevel") @@ -2556,11 +2567,65 @@ export class ProfileEmployeeController extends Controller { .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") - .where("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` }) + .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( + new Brackets((qb) => { + qb.orWhere("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` }) + .orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` }) + .orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` }) + .orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` }) + .orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` }); + }), + ) .orderBy("profile.citizenId", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize)