diff --git a/src/controllers/DevelopmentRequestController.ts b/src/controllers/DevelopmentRequestController.ts index b917c20b..28fbef4d 100644 --- a/src/controllers/DevelopmentRequestController.ts +++ b/src/controllers/DevelopmentRequestController.ts @@ -173,7 +173,7 @@ export class DevelopmentRequestController extends Controller { ); }), ) - .orderBy("developmentRequest.createdAt", "ASC") + .orderBy("developmentRequest.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 1f42706b..498a9a5e 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -5978,14 +5978,32 @@ export class ProfileController extends Controller { @Query("pageSize") pageSize: number = 10, @Body() body: { - fieldName: string; + fieldName?: string | null; keyword?: string; }, ) { let findProfile: any; let total: any; + let revision = await this.orgRevisionRepo.findOne({where: { orgRevisionIsCurrent: true }}); const skip = (page - 1) * pageSize; const take = pageSize; + let queryLike = `CONCAT( + IFNULL(orgChild4.orgChild4ShortName, ''), + IFNULL(current_holders.posMasterNo , '') + ) LIKE :keyword OR CONCAT( + IFNULL(orgChild3.orgChild3ShortName, ''), + IFNULL(current_holders.posMasterNo , '') + ) LIKE :keyword OR CONCAT( + IFNULL(orgChild2.orgChild2ShortName, ''), + IFNULL(current_holders.posMasterNo , '') + ) LIKE :keyword OR CONCAT( + IFNULL(orgChild1.orgChild1ShortName, ''), + IFNULL(current_holders.posMasterNo , '') + ) LIKE :keyword OR CONCAT( + IFNULL(orgRoot.orgRootShortName, ''), + IFNULL(current_holders.posMasterNo , '') + ) LIKE :keyword`; + switch (body.fieldName) { case "citizenId": [findProfile, total] = await this.profileRepo.findAndCount({ @@ -6006,9 +6024,25 @@ export class ProfileController extends Controller { }); break; - case "firstname": + case "fullName": + [findProfile, total] = await this.profileRepo.createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .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("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` }) + .skip(skip) + .take(take) + .getManyAndCount(); + break; + + case "position": [findProfile, total] = await this.profileRepo.findAndCount({ - where: { firstName: Like(`%${body.keyword}%`) }, + where: { position: Like(`%${body.keyword}%`) }, relations: [ "posType", "posLevel", @@ -6025,9 +6059,39 @@ export class ProfileController extends Controller { }); break; - case "lastname": + case "posNo": + [findProfile, total] = await this.profileRepo.createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .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("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) + .andWhere( + new Brackets((qb) => { + qb.orWhere(body.keyword != undefined && body.keyword != null && body.keyword != "" + ? queryLike + : "1=1", + { + keyword: `%${body.keyword}%`, + }) + }) + ) + .skip(skip) + .take(take) + .getManyAndCount(); + break; + + case "posType": [findProfile, total] = await this.profileRepo.findAndCount({ - where: { lastName: Like(`%${body.keyword}%`) }, + where: { + posType: { + posTypeName:Like(`%${body.keyword}%`) + } + }, relations: [ "posType", "posLevel", @@ -6044,6 +6108,53 @@ export class ProfileController extends Controller { }); break; + case "posLevel": + [findProfile, total] = await this.profileRepo.findAndCount({ + where: { + posLevel: { + posLevelName:Like(`%${body.keyword}%`) + } + }, + relations: [ + "posType", + "posLevel", + "current_holders", + "profileSalary", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + skip, + take, + }); + break; + + case "organization": + [findProfile, total] = await this.profileRepo.findAndCount({ + where: { + current_holders:{ + orgRoot:{ + orgRootName:Like(`%${body.keyword}%`) + } + }}, + relations: [ + "posType", + "posLevel", + "current_holders", + "profileSalary", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + skip, + take, + }); + break; + default: [findProfile, total] = await this.profileRepo.findAndCount({ relations: [ @@ -6072,7 +6183,7 @@ export class ProfileController extends Controller { const mapDataProfile = await Promise.all( findProfile.map(async (item: Profile) => { - const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; + const fullName = `${item.prefix}${item.firstName} ${item.lastName}`; const shortName = item.current_holders.length == 0 ? null @@ -6158,7 +6269,7 @@ export class ProfileController extends Controller { positionType: item.posTypeId, positionTypeName: item.posType?.posTypeName, posNo: shortName, - organization: root == null ? null : root.orgRootShortName, + organization: root == null ? null : root.orgRootName, salary: salary == "" ? "" : salary.amount, root: rootHolder?.orgRootName ?? null, rootId: rootHolder?.id ?? null,