fix script move
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m5s

This commit is contained in:
Warunee Tamkoo 2026-06-12 09:05:11 +07:00
parent 3a4ac309b9
commit a830633c7a
2 changed files with 34 additions and 18 deletions

View file

@ -19,9 +19,7 @@ import { Profile } from "../entities/Profile";
* - posType = "อำนวยการ" "บริหาร" posExecutiveName
* - posType positionName + posLevel
*/
export async function getPosMasterPositions(
posMasterIds: string[]
): Promise<Map<string, string>> {
export async function getPosMasterPositions(posMasterIds: string[]): Promise<Map<string, string>> {
if (posMasterIds.length === 0) {
return new Map();
}
@ -62,7 +60,9 @@ export async function getPosMasterPositions(
let positionText = "";
if (posTypeName === "อำนวยการ" || posTypeName === "บริหาร") {
positionText = pos.posExecutive?.posExecutiveName || `${pos.positionName || ""}ระดับ${pos.posLevel?.posLevelName || ""}`.trim();
positionText =
pos.posExecutive?.posExecutiveName ||
`${pos.positionName || ""}ระดับ${pos.posLevel?.posLevelName || ""}`.trim();
} else {
positionText = `${pos.positionName || ""}${pos.posLevel?.posLevelName || ""}`.trim();
}
@ -73,7 +73,6 @@ export async function getPosMasterPositions(
return positionMap;
}
export async function CreatePosMasterHistoryOfficer(
posMasterId: string,
request: RequestWithUser | null,
@ -141,7 +140,7 @@ export async function CreatePosMasterHistoryOfficer(
if (pm.isSit && pm.current_holderId) {
const profile = await repoProfile.findOne({
where: { id: pm.current_holderId },
relations: ["posType", "posLevel"]
relations: ["posType", "posLevel"],
});
position = profile?.position ?? _null;
posTypeName = profile?.posType?.posTypeName ?? _null;
@ -476,8 +475,15 @@ export async function BatchSavePosMasterHistoryOfficer(
const existing = historyByDna.get(op.posMasterDnaId)?.[0];
const shouldInsert = !existing && op.profileId && op.pm;
const profileChanged = existing && existing.profileId !== op.profileId;
const positionChanged =
existing &&
existing.position !== op.pm?.position &&
existing.posType !== op.pm?.posType &&
existing.posLevel !== op.pm?.posLevel &&
existing.posExecutive !== op.pm?.posExecutive;
if (shouldInsert || profileChanged) {
// ถ้าไม่มี record เดิม หรือ profile เปลี่ยน หรือ position เปลี่ยน ให้สร้าง record ใหม่
if (shouldInsert || profileChanged || positionChanged) {
const newPmh = new PosMasterHistory();
newPmh.ancestorDNA = op.posMasterDnaId;
newPmh.prefix = op.pm?.prefix ?? _null;
@ -542,11 +548,11 @@ export async function updateHolderProfileHistory(
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
}
},
},
relations: {
orgRevision : true
}
orgRevision: true,
},
});
if (posMaster) {
@ -560,11 +566,11 @@ export async function updateHolderProfileHistory(
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
}
},
},
relations: {
orgRevision : true
}
orgRevision: true,
},
});
if (employeePosMaster) {