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;