From f2efb443361e69b2fcdf3e179b82124d122bbbe1 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Thu, 16 Oct 2025 23:04:50 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AB=E0=B8=B2=E0=B8=84=E0=B8=99=E0=B9=80?= =?UTF-8?q?=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93=E0=B8=95=E0=B8=B2?= =?UTF-8?q?=E0=B8=A1=E0=B8=9B=E0=B8=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 8 +++- src/controllers/ProfileEmployeeController.ts | 6 ++- .../ProfileEmployeeTempController.ts | 44 ++++++++----------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 52c13443..2e3a4da5 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -4975,7 +4975,7 @@ export class ProfileController extends Controller { * */ @Post("cal/retire") - async calDateRetire(@Body() body:{birthDate: Date}) { + async calDateRetire(@Body() body: { birthDate: Date }) { const retireDate = await calculateRetireDate(body.birthDate); const age = calculateAge(body.birthDate); @@ -10436,7 +10436,11 @@ export class ProfileController extends Controller { .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("positions.posExecutive", "posExecutive") - .where("YEAR(profile.dateRetire) = :year", { year }) + // calculate range: start = 2 Oct of (year-1), end = 1 Oct of year (inclusive) + .where("profile.dateRetire BETWEEN :start AND :end", { + start: `${year - 1}-10-02`, + end: `${year}-10-01`, + }) .getMany(); if (!profiles || profiles.length === 0) { diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 362c9419..8d2ebc43 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -5032,7 +5032,11 @@ export class ProfileEmployeeController extends Controller { .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.positions", "positions") - .where("YEAR(profileEmployee.dateRetire) = :year", { year }) + // calculate range: start = 2 Oct of (year-1), end = 1 Oct of year (inclusive) + .where("profile.dateRetire BETWEEN :start AND :end", { + start: `${year - 1}-10-02`, + end: `${year}-10-01`, + }) .getMany(); if (!profiles || profiles.length === 0) { diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 12c65e10..189cb80c 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1527,7 +1527,7 @@ export class ProfileEmployeeTempController extends Controller { if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - + let query = await this.profileRepo .createQueryBuilder("profileEmployee") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") @@ -1640,36 +1640,24 @@ export class ProfileEmployeeTempController extends Controller { } } }), - ) + ); if (sortBy) { - if(sortBy == "posLevel"){ - query = query.orderBy( - `posLevel.posLevelName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy == "posType"){ - query = query.orderBy( - `posType.posTypeName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy == "govAge"){ - query = query.orderBy( - `profileEmployee.dateAppoint`, - descending ? "DESC" : "ASC" - ); - }else{ - query = query.orderBy( - `profileEmployee.${sortBy}`, - descending ? "DESC" : "ASC" - ); + if (sortBy == "posLevel") { + query = query.orderBy(`posLevel.posLevelName`, descending ? "DESC" : "ASC"); + } else if (sortBy == "posType") { + query = query.orderBy(`posType.posTypeName`, descending ? "DESC" : "ASC"); + } else if (sortBy == "govAge") { + query = query.orderBy(`profileEmployee.dateAppoint`, descending ? "DESC" : "ASC"); + } else { + query = query.orderBy(`profileEmployee.${sortBy}`, descending ? "DESC" : "ASC"); } } const [record, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const data = await Promise.all( record.map((_data) => { @@ -3241,7 +3229,11 @@ export class ProfileEmployeeTempController extends Controller { .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.positions", "positions") // .leftJoinAndSelect("positions.posExecutive", "posExecutive") - .where("YEAR(profileEmployee.dateRetire) = :year", { year }) + // calculate range: start = 2 Oct of (year-1), end = 1 Oct of year (inclusive) + .where("profile.dateRetire BETWEEN :start AND :end", { + start: `${year - 1}-10-02`, + end: `${year}-10-01`, + }) .getMany(); if (!profiles || profiles.length === 0) {