#2427 and migration

This commit is contained in:
adisak 2026-04-20 08:05:16 +07:00
parent 7f3408e2f5
commit 28b5408d5b
6 changed files with 159 additions and 5 deletions

View file

@ -48,6 +48,7 @@ import {
import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster";
import { EmployeePosition } from "../entities/EmployeePosition";
import { getPosMasterNo, getOrgFullName } from "../utils/org-formatting";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
@ -3660,6 +3661,7 @@ export class CommandController extends Controller {
const posMaster = await this.posMasterRepository.findOne({
where: { id: item.posmasterId },
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
});
if (posMaster == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
@ -3715,6 +3717,7 @@ export class CommandController extends Controller {
id: item.positionId,
posMasterId: item.posmasterId,
},
relations: ["posExecutive"],
});
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if (positionNew != null) {
@ -3723,6 +3726,12 @@ export class CommandController extends Controller {
profile.posLevelId = positionNew.posLevelId;
profile.posTypeId = positionNew.posTypeId;
profile.position = positionNew.positionName;
profile.positionField = positionNew.positionField ?? null;
profile.posExecutive = positionNew.posExecutive?.posExecutiveName ?? null;
profile.positionArea = positionNew.positionArea ?? null;
profile.positionExecutiveField = positionNew.positionExecutiveField ?? null;
profile.posMasterNo = getPosMasterNo(posMaster);
profile.org = getOrgFullName(posMaster);
}
profile.amount = item.amount ?? null;
profile.amountSpecial = item.amountSpecial ?? null;
@ -6876,7 +6885,7 @@ export class CommandController extends Controller {
where: {
id: item.bodyPosition.posmasterId,
},
relations: { orgRevision: true }
relations: { orgRevision: true, orgRoot: true, orgChild1: true, orgChild2: true, orgChild3: true, orgChild4: true }
});
// เช็คว่า posMaster ที่หามาอยู่ในโครงสร้างปัจจุบันหรือไม่
@ -6893,9 +6902,8 @@ export class CommandController extends Controller {
orgRevisionIsDraft: false
}
},
relations: { orgRevision: true }
});
}
relations: { orgRevision: true, orgRoot: true, orgChild1: true, orgChild2: true, orgChild3: true, orgChild4: true }
}); }
if (posMaster == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
@ -6983,6 +6991,7 @@ export class CommandController extends Controller {
id: item.bodyPosition.positionId,
posMasterId: posMaster.id,
},
relations: ["posExecutive"],
});
}
@ -6993,6 +7002,12 @@ export class CommandController extends Controller {
profile.posLevelId = positionNew.posLevelId;
profile.posTypeId = positionNew.posTypeId;
profile.position = positionNew.positionName;
profile.positionField = positionNew.positionField ?? null;
profile.posExecutive = positionNew.posExecutive?.posExecutiveName ?? null;
profile.positionArea = positionNew.positionArea ?? null;
profile.positionExecutiveField = positionNew.positionExecutiveField ?? null;
profile.posMasterNo = getPosMasterNo(posMaster);
profile.org = getOrgFullName(posMaster);
// profile.dateStart = new Date();
await this.profileRepository.save(profile, { data: req });
setLogDataDiff(req, { before, after: profile });