diff --git a/src/services/PositionService.ts b/src/services/PositionService.ts index 37c5f083..2c454a39 100644 --- a/src/services/PositionService.ts +++ b/src/services/PositionService.ts @@ -11,6 +11,7 @@ import { PosMasterHistory } from "../entities/PosMasterHistory"; import { Position } from "../entities/Position"; import { ProfileEducation } from "../entities/ProfileEducation"; import { RequestWithUser } from "../middlewares/user"; +import { Profile } from "../entities/Profile"; /** * function สำหรับดึงตำแหน่งที่รักษาการแทน @@ -85,6 +86,7 @@ export async function CreatePosMasterHistoryOfficer( const repoHistory = transactionManager.getRepository(PosMasterHistory); const repoOrgRevision = transactionManager.getRepository(OrgRevision); const repoPosition = transactionManager.getRepository(Position); + const repoProfile = transactionManager.getRepository(Profile); const pm = await repoPosmaster.findOne({ where: { id: posMasterId }, @@ -132,6 +134,21 @@ export async function CreatePosMasterHistoryOfficer( : null; } + let position = selectedPosition?.positionName ?? _null; + let posTypeName = selectedPosition?.posType?.posTypeName ?? _null; + let posLevelName = selectedPosition?.posLevel?.posLevelName ?? _null; + let posExecutiveName = selectedPosition?.posExecutive?.posExecutiveName ?? _null; + if (pm.isSit && pm.current_holderId) { + const profile = await repoProfile.findOne({ + where: { id: pm.current_holderId }, + relations: ["posType", "posLevel"] + }); + position = profile?.position ?? _null; + posTypeName = profile?.posType?.posTypeName ?? _null; + posLevelName = profile?.posLevel?.posLevelName ?? _null; + posExecutiveName = profile?.posExecutive ?? _null; + } + h.ancestorDNA = pm.ancestorDNA ? pm.ancestorDNA : _null; if (!type || type != "DELETE") { if (checkCurrentRevision) { @@ -144,9 +161,9 @@ export async function CreatePosMasterHistoryOfficer( h.firstName = pm.next_holder?.firstName || _null; h.lastName = pm.next_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; @@ -156,7 +173,7 @@ export async function CreatePosMasterHistoryOfficer( h.posMasterNoPrefix = pm.posMasterNoPrefix ?? _null; h.posMasterNo = pm.posMasterNo ?? _null; h.posMasterNoSuffix = pm.posMasterNoSuffix ?? _null; - h.posExecutive = selectedPosition?.posExecutive?.posExecutiveName ?? _null; + h.posExecutive = posExecutiveName; h.shortName = [ pm.orgChild4?.orgChild4ShortName,