From 58274b479cca817ba50451046db24779e8d731f4 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Thu, 16 Oct 2025 00:33:48 +0700 Subject: [PATCH 1/2] =?UTF-8?q?=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98?= =?UTF-8?q?=E0=B8=B4=E0=B9=8C=E0=B8=94=E0=B8=B9=E0=B9=82=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=87=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 509 ++-------------------- 1 file changed, 39 insertions(+), 470 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index fdf194f6..18a65e8d 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -42,6 +42,7 @@ import { CreatePosMasterHistoryEmployee, CreatePosMasterHistoryOfficer, } from "../services/PositionService"; + @Route("api/v1/org") @Tags("Organization") @Security("bearerAuth") @@ -1962,34 +1963,41 @@ export class OrganizationController extends Controller { child3: null, child4: null, }; + let _data1: any = { + root: null, + }; const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } }); if (!orgRevision) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - let attrOwnership = null; let _privilege = await new permission().PermissionOrgList(request, "SYS_ORG"); - attrOwnership = _privilege.root == null ? true : false; - if ( - orgRevision.orgRevisionIsDraft == true && - orgRevision.orgRevisionIsCurrent == false && - attrOwnership == false - ) { - const profile = await this.profileRepo.findOne({ - where: { keycloak: request.user.sub }, - relations: ["permissionProfiles"], - }); - if (!profile) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ"); + const attrOwnership = _privilege.root === null ? true : false; + + const profile = await this.profileRepo.findOne({ + where: { keycloak: request.user.sub }, + relations: ["permissionProfiles", "current_holders", "current_holders.posMasterAssigns"], + }); + if (!profile) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ"); + } + let profileAssign = profile.current_holders + ?.find((x) => x.orgRevisionId === id) + ?.posMasterAssigns.find((x) => x.assignId === "SYS_ORG"); + + if (orgRevision.orgRevisionIsDraft && !orgRevision.orgRevisionIsCurrent && !attrOwnership) { + _data.root = profile.permissionProfiles.map((x) => x.orgRootId); + } + // กำหนดการเข้าถึงข้อมูลตามสถานะและสิทธิ์ + const isCurrentActive = !orgRevision.orgRevisionIsDraft && orgRevision.orgRevisionIsCurrent; + + if (isCurrentActive) { + if (profileAssign) { + _data.root = [profile.current_holders.find((x) => x.orgRevisionId === id)?.orgRootId]; + } else { + if (!attrOwnership) _data = _privilege; } - _data = { - root: profile.permissionProfiles.map((x) => x.orgRootId), - child1: null, - child2: null, - child3: null, - child4: null, - }; } const _revision = await this.orgRevisionRepository.findOne({ @@ -2001,8 +2009,8 @@ export class OrganizationController extends Controller { .createQueryBuilder("orgRoot") .where("orgRoot.orgRevisionId = :id", { id }) .andWhere( - _data.root != undefined && _data.root != null - ? _data.root[0] != null + _data.root !== undefined && _data.root !== null + ? _data.root[0] !== null ? `orgRoot.id IN (:...node)` : `orgRoot.id is null` : "1=1", @@ -2040,8 +2048,8 @@ export class OrganizationController extends Controller { .createQueryBuilder("orgChild1") .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) .andWhere( - _data.child1 != undefined && _data.child1 != null - ? _data.child1[0] != null + _data.child1 !== undefined && _data.child1 !== null + ? _data.child1[0] !== null ? `orgChild1.id IN (:...node)` : `orgChild1.id is null` : "1=1", @@ -2081,8 +2089,8 @@ export class OrganizationController extends Controller { .createQueryBuilder("orgChild2") .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) .andWhere( - _data.child2 != undefined && _data.child2 != null - ? _data.child2[0] != null + _data.child2 !== undefined && _data.child2 !== null + ? _data.child2[0] !== null ? `orgChild2.id IN (:...node)` : `orgChild2.id is null` : "1=1", @@ -2121,8 +2129,8 @@ export class OrganizationController extends Controller { .createQueryBuilder("orgChild3") .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) .andWhere( - _data.child3 != undefined && _data.child3 != null - ? _data.child3[0] != null + _data.child3 !== undefined && _data.child3 !== null + ? _data.child3[0] !== null ? `orgChild3.id IN (:...node)` : `orgChild3.id is null` : "1=1", @@ -2161,8 +2169,8 @@ export class OrganizationController extends Controller { .createQueryBuilder("orgChild4") .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) .andWhere( - _data.child4 != undefined && _data.child4 != null - ? _data.child4[0] != null + _data.child4 !== undefined && _data.child4 !== null + ? _data.child4[0] !== null ? `orgChild4.id IN (:...node)` : `orgChild4.id is null` : "1=1", @@ -2194,7 +2202,6 @@ export class OrganizationController extends Controller { .getMany() : []; - // const formattedData = orgRootData.map((orgRoot) => { const formattedData = await Promise.all( orgRootData.map(async (orgRoot) => { return { @@ -2223,91 +2230,6 @@ export class OrganizationController extends Controller { responsibility: orgRoot.responsibility, labelName: orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName, - // totalPosition: await this.posMasterRepository.count({ - // where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id }, - // }), - // totalPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // current_holderId: IsNull() || "", - // }, - // }), - // totalPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // next_holderId: IsNull() || "", - // }, - // }), - // totalRootPosition: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: IsNull() || "", - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // }, - // }), - // totalRootPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: IsNull() || "", - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: IsNull() || "", - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // current_holderId: IsNull() || "", - // }, - // }), - // totalRootPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: IsNull() || "", - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: IsNull() || "", - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // next_holderId: IsNull() || "", - // }, - // }), children: await Promise.all( orgChild1Data @@ -2352,91 +2274,6 @@ export class OrganizationController extends Controller { "00" + " " + orgRoot.orgRootShortName, - // totalPosition: await this.posMasterRepository.count({ - // where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id }, - // }), - // totalPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild1Id: orgChild1.id, - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild1Id: orgChild1.id, - // current_holderId: IsNull() || "", - // }, - // }), - // totalPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild1Id: orgChild1.id, - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild1Id: orgChild1.id, - // next_holderId: IsNull() || "", - // }, - // }), - // totalRootPosition: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // }, - // }), - // totalRootPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // current_holderId: IsNull() || "", - // }, - // }), - // totalRootPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: IsNull() || "", - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // next_holderId: IsNull() || "", - // }, - // }), children: await Promise.all( orgChild2Data @@ -2486,94 +2323,6 @@ export class OrganizationController extends Controller { "00" + " " + orgRoot.orgRootShortName, - // totalPosition: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild2Id: orgChild2.id, - // }, - // }), - // totalPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild2Id: orgChild2.id, - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild2Id: orgChild2.id, - // current_holderId: IsNull() || "", - // }, - // }), - // totalPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild2Id: orgChild2.id, - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild2Id: orgChild2.id, - // next_holderId: IsNull() || "", - // }, - // }), - // totalRootPosition: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // }, - // }), - // totalRootPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // current_holderId: IsNull() || "", - // }, - // }), - // totalRootPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: IsNull() || "", - // orgChild4Id: IsNull() || "", - // next_holderId: IsNull() || "", - // }, - // }), children: await Promise.all( orgChild3Data @@ -2630,94 +2379,6 @@ export class OrganizationController extends Controller { "00" + " " + orgRoot.orgRootShortName, - // totalPosition: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild3Id: orgChild3.id, - // }, - // }), - // totalPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild3Id: orgChild3.id, - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild3Id: orgChild3.id, - // current_holderId: IsNull() || "", - // }, - // }), - // totalPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild3Id: orgChild3.id, - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild3Id: orgChild3.id, - // next_holderId: IsNull() || "", - // }, - // }), - // totalRootPosition: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: IsNull() || "", - // }, - // }), - // totalRootPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: IsNull() || "", - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: IsNull() || "", - // current_holderId: IsNull() || "", - // }, - // }), - // totalRootPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: IsNull() || "", - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: IsNull() || "", - // next_holderId: IsNull() || "", - // }, - // }), children: await Promise.all( orgChild4Data @@ -2781,99 +2442,6 @@ export class OrganizationController extends Controller { "00" + " " + orgRoot.orgRootShortName, - // totalPosition: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild4Id: orgChild4.id, - // }, - // }), - // totalPositionCurrentUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild4Id: orgChild4.id, - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionCurrentVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild4Id: orgChild4.id, - // current_holderId: IsNull() || "", - // }, - // }), - // totalPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild4Id: orgChild4.id, - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalPositionNextVacant: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgChild4Id: orgChild4.id, - // next_holderId: IsNull() || "", - // }, - // }), - // totalRootPosition: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: orgChild4.id, - // }, - // }), - // totalRootPositionCurrentUse: await this.posMasterRepository.count( - // { - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: orgChild4.id, - // current_holderId: Not(IsNull()) || Not(""), - // }, - // }, - // ), - // totalRootPositionCurrentVacant: - // await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: orgChild4.id, - // current_holderId: IsNull() || "", - // }, - // }), - // totalRootPositionNextUse: await this.posMasterRepository.count({ - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: orgChild4.id, - // next_holderId: Not(IsNull()) || Not(""), - // }, - // }), - // totalRootPositionNextVacant: await this.posMasterRepository.count( - // { - // where: { - // orgRevisionId: orgRoot.orgRevisionId, - // orgRootId: orgRoot.id, - // orgChild1Id: orgChild1.id, - // orgChild2Id: orgChild2.id, - // orgChild3Id: orgChild3.id, - // orgChild4Id: orgChild4.id, - // next_holderId: IsNull() || "", - // }, - // }, - // ), })), ), })), @@ -2886,6 +2454,7 @@ export class OrganizationController extends Controller { }), ); + // return new HttpSuccess({ remark: _revision.remark, data: formattedData }); return new HttpSuccess({ remark: _revision.remark, data: formattedData }); } From f2efb443361e69b2fcdf3e179b82124d122bbbe1 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Thu, 16 Oct 2025 23:04:50 +0700 Subject: [PATCH 2/2] =?UTF-8?q?=E0=B8=AB=E0=B8=B2=E0=B8=84=E0=B8=99?= =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93=E0=B8=95?= =?UTF-8?q?=E0=B8=B2=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) {