From e6bdea2b206013f80506a2e03aa243e5e052ff7b Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 17 Jun 2026 15:42:48 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AD=E0=B8=B1=E0=B8=95=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=81=E0=B8=B3=E0=B8=A5=E0=B8=B1=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=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=88=E0=B8=B3=20=E0=B8=81=E0=B8=A3=E0=B8=93?= =?UTF-8?q?=E0=B8=B5=E0=B8=99=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=97=E0=B8=B1?= =?UTF-8?q?=E0=B8=9A=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=95=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=87=E0=B9=80=E0=B8=9B=E0=B9=87=E0=B8=99=E0=B8=95=E0=B8=B3?= =?UTF-8?q?=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87=E0=B8=88=E0=B8=A3?= =?UTF-8?q?=E0=B8=B4=E0=B8=87=20#2563?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/PositionService.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/services/PositionService.ts b/src/services/PositionService.ts index c242c184..2b0cc324 100644 --- a/src/services/PositionService.ts +++ b/src/services/PositionService.ts @@ -12,6 +12,7 @@ import { Position } from "../entities/Position"; import { ProfileEducation } from "../entities/ProfileEducation"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; +import { ProfileEmployee } from "../entities/ProfileEmployee"; /** * function สำหรับดึงตำแหน่งที่รักษาการแทน @@ -221,6 +222,7 @@ export async function CreatePosMasterHistoryEmployee( await AppDataSource.transaction(async (manager) => { const repoPosmaster = manager.getRepository(EmployeePosMaster); const repoHistory = manager.getRepository(PosMasterEmployeeHistory); + const repoProfileEmployee = manager.getRepository(ProfileEmployee); const pm = await repoPosmaster.findOne({ where: { id: posMasterId }, @@ -245,15 +247,28 @@ export async function CreatePosMasterHistoryEmployee( pm.positions.length > 0 ? pm.positions.find((p) => p.positionIsSelected === true) ?? null : null; + + let position = selectedPosition?.positionName ?? _null; + let posTypeName = selectedPosition?.posType?.posTypeName ?? _null; + let posLevelName = selectedPosition?.posLevel?.posLevelName ?? _null; + if (pm.isSit && pm.current_holderId) { + const profile = await repoProfileEmployee.findOne({ + where: { id: pm.current_holderId }, + relations: ["posType", "posLevel"] + }); + position = profile?.position ?? _null; + posTypeName = profile?.posType?.posTypeName ?? _null; + posLevelName = profile?.posLevel?.posLevelName ?? _null; + } h.ancestorDNA = pm.ancestorDNA; if (!type || type != "DELETE") { h.profileEmployeeId = pm.current_holder?.id || _null; h.prefix = pm.current_holder?.prefix || _null; h.firstName = pm.current_holder?.firstName || _null; h.lastName = pm.current_holder?.lastName || _null; - h.position = selectedPosition?.positionName ?? _null; - h.posType = selectedPosition?.posType?.posTypeName ?? _null; - h.posLevel = selectedPosition?.posLevel?.posLevelName ?? _null; + h.position = position; + h.posType = posTypeName; + h.posLevel = posLevelName; } h.rootDnaId = pm.orgRoot?.ancestorDNA || _null; h.child1DnaId = pm.orgChild1?.ancestorDNA || _null;