From 9cda6e176e70eda58cb63831c196ae1b4ba41832 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 9 Jul 2025 14:26:42 +0700 Subject: [PATCH] =?UTF-8?q?api=20list=20=E0=B8=A3=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=95=E0=B8=B2=E0=B8=A1?= =?UTF-8?q?=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C=20admin?= =?UTF-8?q?=20=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20order=20&=20=E0=B9=81?= =?UTF-8?q?=E0=B8=81=E0=B9=89=E0=B8=82=E0=B8=AD=E0=B8=87=E0=B8=A5=E0=B8=B9?= =?UTF-8?q?=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationDotnetController.ts | 154 ++++++++++++++---- 1 file changed, 125 insertions(+), 29 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index ae5129b6..332a6153 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -26,6 +26,7 @@ import { Position } from "../entities/Position"; import { Insignia } from "../entities/Insignia"; import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia"; import { PosMaster } from "../entities/PosMaster"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosDict } from "../entities/EmployeePosDict"; import { calculateRetireLaw } from "../interfaces/utils"; import Extension from "../interfaces/extension"; @@ -44,6 +45,7 @@ export class OrganizationDotnetController extends Controller { private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private positionRepository = AppDataSource.getRepository(Position); private posMasterRepository = AppDataSource.getRepository(PosMaster); + private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict); @@ -4164,7 +4166,9 @@ export class OrganizationDotnetController extends Controller { } } else if (body.role === "ROOT") { typeCondition = { - orgRootId: body.nodeId + orgRoot: { + ancestorDNA: body.nodeId + }, }; } else if (body.role === "NORMAL") { switch (node) { @@ -4225,6 +4229,26 @@ export class OrganizationDotnetController extends Controller { "current_holders.orgChild3", "current_holders.orgChild4", ], + order: { + current_holders: { + orgRoot: { + orgRootOrder: "ASC", + }, + orgChild1: { + orgChild1Order: "ASC", + }, + orgChild2: { + orgChild2Order: "ASC", + }, + orgChild3: { + orgChild3Order: "ASC", + }, + orgChild4: { + orgChild4Order: "ASC", + }, + posMasterNo: "ASC", + } + } }); if (body.isRetirement) { profile = await this.profileRepo.find({ @@ -4246,7 +4270,7 @@ export class OrganizationDotnetController extends Controller { }); } let findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } }); if (body.revisionId) { @@ -4285,15 +4309,15 @@ export class OrganizationDotnetController extends Controller { const Oc = item.current_holders.length == 0 ? null - : (node == 4 || node == null) && item.current_holders[0].orgChild4 != null + : item.current_holders[0].orgChild4 != null ? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : (node == 3 || node == null) && item.current_holders[0].orgChild3 != null + : item.current_holders[0].orgChild3 != null ? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : (node == 2 || node == null) && item.current_holders[0].orgChild2 != null + : item.current_holders[0].orgChild2 != null ? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : (node == 1 || node == null) && item.current_holders[0].orgChild1 != null + : item.current_holders[0].orgChild1 != null ? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : (node == 0 || node == null) && item.current_holders[0].orgRoot != null + : item.current_holders[0].orgRoot != null ? `${item.current_holders[0].orgRoot.orgRootName}` : null; @@ -4659,19 +4683,39 @@ export class OrganizationDotnetController extends Controller { if (body.role === "OWNER" || body.role === "CHILD") { switch (node) { case 0: - typeCondition = { orgRootId: body.nodeId }; + typeCondition = { + orgRoot: { + ancestorDNA: body.nodeId + } + }; break; case 1: - typeCondition = { orgChild1Id: body.nodeId }; + typeCondition = { + orgChild1: { + ancestorDNA: body.nodeId + } + }; break; case 2: - typeCondition = { orgChild2Id: body.nodeId }; + typeCondition = { + orgChild2: { + ancestorDNA: body.nodeId + } + }; break; case 3: - typeCondition = { orgChild3Id: body.nodeId }; + typeCondition = { + orgChild3: { + ancestorDNA: body.nodeId + } + }; break; case 4: - typeCondition = { orgChild4Id: body.nodeId }; + typeCondition = { + orgChild4: { + ancestorDNA: body.nodeId + } + }; break; case null: typeCondition = {}; @@ -4682,32 +4726,49 @@ export class OrganizationDotnetController extends Controller { } } else if (body.role === "ROOT") { typeCondition = { - orgRootId: body.nodeId + orgRoot: { + ancestorDNA: body.nodeId + }, }; } else if (body.role === "NORMAL") { switch (node) { case 0: typeCondition = { - orgRootId: body.nodeId, - orgChild1Id: IsNull(), + orgRoot: { + ancestorDNA: body.nodeId + }, + orgChild1: IsNull() }; break; case 1: typeCondition = { - orgChild1Id: body.nodeId, - orgChild2Id: IsNull(), + orgChild1: { + ancestorDNA: body.nodeId + }, + orgChild2: IsNull() }; break; case 2: typeCondition = { - orgChild2Id: body.nodeId, - orgChild3Id: IsNull(), + orgChild2: { + ancestorDNA: body.nodeId + }, + orgChild3: IsNull() }; break; case 3: typeCondition = { - orgChild3Id: body.nodeId, - orgChild4Id: IsNull(), + orgChild3: { + ancestorDNA: body.nodeId + }, + orgChild4: IsNull() + }; + break; + case 4: + typeCondition = { + orgChild4: { + ancestorDNA: body.nodeId + }, }; break; default: @@ -4728,6 +4789,26 @@ export class OrganizationDotnetController extends Controller { "current_holders.orgChild3", "current_holders.orgChild4", ], + order: { + current_holders: { + orgRoot: { + orgRootOrder: "ASC", + }, + orgChild1: { + orgChild1Order: "ASC", + }, + orgChild2: { + orgChild2Order: "ASC", + }, + orgChild3: { + orgChild3Order: "ASC", + }, + orgChild4: { + orgChild4Order: "ASC", + }, + posMasterNo: "ASC", + } + } }); if (body.isRetirement) { profile = await this.profileEmpRepo.find({ @@ -4749,7 +4830,7 @@ export class OrganizationDotnetController extends Controller { }); } let findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } }); if (body.revisionId) { @@ -4759,7 +4840,7 @@ export class OrganizationDotnetController extends Controller { } const profile_ = await Promise.all( - profile.map((item: ProfileEmployee) => { + profile.map(async(item: ProfileEmployee) => { const shortName = item.current_holders.length == 0 ? null @@ -4788,17 +4869,25 @@ export class OrganizationDotnetController extends Controller { const Oc = item.current_holders.length == 0 ? null - : body.node == 4 && item.current_holders[0].orgChild4 != null + : item.current_holders[0].orgChild4 != null ? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 3 && item.current_holders[0].orgChild3 != null + : item.current_holders[0].orgChild3 != null ? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 2 && item.current_holders[0].orgChild2 != null + : item.current_holders[0].orgChild2 != null ? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 1 && item.current_holders[0].orgChild1 != null + : item.current_holders[0].orgChild1 != null ? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 0 && item.current_holders[0].orgRoot != null + : item.current_holders[0].orgRoot != null ? `${item.current_holders[0].orgRoot.orgRootName}` : null; + + let _posMaster = await this.empPosMasterRepository.findOne({ + where: { + orgRevisionId: findRevision?.id, + current_holderId: item.id + } + }); + return { id: item.id, prefix: item.prefix, @@ -4808,9 +4897,16 @@ export class OrganizationDotnetController extends Controller { keycloak: item.keycloak, posNo: shortName, position: item.position, - positionLevel: item.posLevel?.posLevelName ?? null, + positionLevel: item.posType?.posTypeShortName && item.posLevel?.posLevelName + ? `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}` + : null, positionType: item.posType?.posTypeName ?? null, oc: Oc, + orgRootId: _posMaster?.orgRootId, + orgChild1Id: _posMaster?.orgChild1Id, + orgChild2Id: _posMaster?.orgChild2Id, + orgChild3Id: _posMaster?.orgChild3Id, + orgChild4Id: _posMaster?.orgChild4Id, }; }), );