fix ประวัติคนครอง #2405

This commit is contained in:
harid 2026-04-02 17:02:20 +07:00
parent 212360a764
commit 2fd99aaa94
2 changed files with 57 additions and 11 deletions

View file

@ -8,6 +8,7 @@ import { PosMaster } from "../entities/PosMaster";
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
import { PosMasterEmployeeTempHistory } from "../entities/PosMasterEmployeeTempHistory";
import { PosMasterHistory } from "../entities/PosMasterHistory";
import { Position } from "../entities/Position";
import { ProfileEducation } from "../entities/ProfileEducation";
import { RequestWithUser } from "../middlewares/user";
@ -15,12 +16,14 @@ export async function CreatePosMasterHistoryOfficer(
posMasterId: string,
request: RequestWithUser | null,
type?: string | null,
positionData?: { positionId?: string } | null,
): Promise<boolean> {
try {
await AppDataSource.transaction(async (manager) => {
const repoPosmaster = manager.getRepository(PosMaster);
const repoHistory = manager.getRepository(PosMasterHistory);
const repoOrgRevision = manager.getRepository(OrgRevision);
const repoPosition = manager.getRepository(Position);
const pm = await repoPosmaster.findOne({
where: { id: posMasterId },
@ -51,10 +54,22 @@ export async function CreatePosMasterHistoryOfficer(
});
const _null: any = null;
const h = new PosMasterHistory();
const selectedPosition =
pm.positions.length > 0
? pm.positions.find((p) => p.positionIsSelected === true) ?? null
: null;
// query position โดยตรงจาก positionRepository
let selectedPosition: Position | null = null;
if (positionData?.positionId) {
selectedPosition = await repoPosition.findOne({
where: { id: positionData.positionId },
relations: { posLevel: true, posType: true, posExecutive: true },
});
} else {
// ใช้ logic เดิม หาจาก pm.positions ที่ positionIsSelected = true
selectedPosition =
pm.positions.length > 0
? pm.positions.find((p) => p.positionIsSelected === true) ?? null
: null;
}
h.ancestorDNA = pm.ancestorDNA ? pm.ancestorDNA : _null;
if (!type || type != "DELETE") {
if (checkCurrentRevision) {