update save history position

This commit is contained in:
AdisakKanthawilang 2025-09-04 12:10:53 +07:00
parent acbd0604f8
commit 9a40e455c6
2 changed files with 19 additions and 6 deletions

View file

@ -1169,13 +1169,23 @@ export class PositionController extends Controller {
);
}
const before = null;
const chkRevision = await this.orgRevisionRepository.findOne({
where: { id: orgRoot.orgRevisionId },
});
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.createdAt = new Date();
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster, { data: request });
const saved = await this.posMasterRepository.save(posMaster, { data: request });
// รอบสอง set ancestorDNA = id ที่เพิ่งได้มา
if (chkRevision?.orgRevisionIsCurrent) {
saved.ancestorDNA = saved.id; //โครงสร้างปัจจุบันเอาตัวเองเป็น dna
await this.posMasterRepository.save(saved, { data: request });
}
setLogDataDiff(request, { before, after: posMaster });
await Promise.all(
requestBody.positions.map(async (x: any) => {
@ -3681,6 +3691,11 @@ export class PositionController extends Controller {
if (!dataMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
}
if (dataMaster.orgRevision.orgRevisionIsCurrent) {
await CreatePosMasterHistoryOfficer(dataMaster.id, request);
}
let _profileId: string = "";
if (dataMaster?.current_holderId) {
_profileId = dataMaster?.current_holderId;
@ -3691,15 +3706,13 @@ export class PositionController extends Controller {
current_holderId: null,
statusReport: "PENDING",
});
dataMaster.positions.forEach(async (position) => {
await this.positionRepository.update(position.id, {
positionIsSelected: false,
});
});
if (dataMaster.orgRevision.orgRevisionIsCurrent) {
await CreatePosMasterHistoryOfficer(dataMaster.id, request);
}
// //เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile
// const chkRevision = await this.orgRevisionRepository.findOne({
// where: { id: dataMaster.orgRevisionId },

View file

@ -33,7 +33,7 @@ export async function CreatePosMasterHistoryOfficer(
});
if (!pm) return false;
// if (!pm.ancestorDNA) return false; // ทำให้สร้างตำแหน่งใหม่โครงสร้างปัจจุบัน(ไม่มีancestorDNA)แล้วไม่ปั๊มประวัติ
if (!pm.ancestorDNA) return false;
const _null: any = null;
const h = new PosMasterHistory();
const selectedPosition =