Merge branch 'develop' into adiDev

This commit is contained in:
Adisak 2026-06-12 10:01:30 +07:00
commit 1b1a234bfb
15 changed files with 197 additions and 46 deletions

View file

@ -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
@ -18,9 +19,7 @@ import { RequestWithUser } from "../middlewares/user";
* - 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();
}
@ -61,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();
}
@ -72,7 +73,6 @@ export async function getPosMasterPositions(
return positionMap;
}
export async function CreatePosMasterHistoryOfficer(
posMasterId: string,
request: RequestWithUser | null,
@ -85,6 +85,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 +133,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 +160,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 +172,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,
@ -459,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;
@ -525,11 +548,11 @@ export async function updateHolderProfileHistory(
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
}
},
},
relations: {
orgRevision : true
}
orgRevision: true,
},
});
if (posMaster) {
@ -543,11 +566,11 @@ export async function updateHolderProfileHistory(
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
}
},
},
relations: {
orgRevision : true
}
orgRevision: true,
},
});
if (employeePosMaster) {