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

@ -8985,7 +8985,16 @@ export class OrganizationController extends Controller {
// Fetch draft PosMasters with relations for history tracking
const draftPosMasters = await queryRunner.manager.find(PosMaster, {
where: { id: In(draftPosMasterIds) },
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4", "next_holder"],
relations: [
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
"next_holder",
"next_holder.posType",
"next_holder.posLevel",
],
});
// Fetch ALL positions for ALL posMasters in just 2 queries
@ -9150,10 +9159,11 @@ export class OrganizationController extends Controller {
prefix: draftPosMaster.next_holder?.prefix ?? null,
firstName: draftPosMaster.next_holder?.firstName ?? null,
lastName: draftPosMaster.next_holder?.lastName ?? null,
position: selectedPos.positionName ?? null,
posType: (selectedPos as any).posType?.posTypeName ?? null,
posLevel: (selectedPos as any).posLevel?.posLevelName ?? null,
posExecutive: (selectedPos as any).posExecutive?.posExecutiveName ?? null,
// isSit = true ดึงค่าจาก profile
position: draftPosMaster?.isSit ? draftPosMaster.next_holder?.position ?? null : selectedPos.positionName ?? null,
posType: draftPosMaster?.isSit ? draftPosMaster.next_holder?.posType?.posTypeName ?? null : (selectedPos as any).posType?.posTypeName ?? null,
posLevel: draftPosMaster?.isSit ? draftPosMaster.next_holder?.posLevel?.posLevelName ?? null : (selectedPos as any).posLevel?.posLevelName ?? null,
posExecutive: draftPosMaster?.isSit ? draftPosMaster.next_holder?.posExecutive ?? null : (selectedPos as any).posExecutive?.posExecutiveName ?? null,
profileId: nextHolderId,
rootDnaId: draftPosMaster.orgRoot?.ancestorDNA ?? null,
child1DnaId: draftPosMaster.orgChild1?.ancestorDNA ?? null,

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) {