fix ประวัติคนครอง #2405
This commit is contained in:
parent
212360a764
commit
2fd99aaa94
2 changed files with 57 additions and 11 deletions
|
|
@ -6928,12 +6928,40 @@ export class CommandController extends Controller {
|
|||
await this.posMasterRepository.save(posMaster);
|
||||
|
||||
// STEP 5: กำหนด position ใหม่
|
||||
const positionNew = await this.positionRepository.findOne({
|
||||
where: {
|
||||
id: item.bodyPosition.positionId,
|
||||
posMasterId: posMaster.id, // ใช้ id ของ posMaster ตัวใหม่
|
||||
},
|
||||
});
|
||||
// เช็คว่า posMaster เปลี่ยนจากเก่าเป็นใหม่หรือไม่
|
||||
const originalPosMasterId = item.bodyPosition.posmasterId;
|
||||
const isPosMasterChanged = originalPosMasterId !== posMaster.id;
|
||||
|
||||
let positionNew = null;
|
||||
|
||||
if (isPosMasterChanged) {
|
||||
// posMaster เปลี่ยน ต้องหา position ใหม่จากคุณสมบัติของ position เก่า
|
||||
// 1. หา position เก่าจาก id ที่ส่งมา
|
||||
const positionOld = await this.positionRepository.findOne({
|
||||
where: { id: item.bodyPosition.positionId },
|
||||
});
|
||||
|
||||
if (positionOld) {
|
||||
// 2. ใช้ posTypeId + posLevelId + positionName หา position ใหม่ใน posMaster ตัวใหม่
|
||||
positionNew = await this.positionRepository.findOne({
|
||||
where: {
|
||||
posMasterId: posMaster.id, // ใช้ posMaster ตัวใหม่
|
||||
posTypeId: positionOld.posTypeId,
|
||||
posLevelId: positionOld.posLevelId,
|
||||
positionName: positionOld.positionName,
|
||||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// posMaster ไม่เปลี่ยน - ใช้วิธีเดิม
|
||||
positionNew = await this.positionRepository.findOne({
|
||||
where: {
|
||||
id: item.bodyPosition.positionId,
|
||||
posMasterId: posMaster.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
|
||||
if (positionNew != null) {
|
||||
positionNew.positionIsSelected = true;
|
||||
|
|
@ -6947,7 +6975,10 @@ export class CommandController extends Controller {
|
|||
}
|
||||
await this.positionRepository.save(positionNew, { data: req });
|
||||
}
|
||||
await CreatePosMasterHistoryOfficer(posMaster.id, req);
|
||||
// await CreatePosMasterHistoryOfficer(posMaster.id, req);
|
||||
await CreatePosMasterHistoryOfficer(posMaster.id, req, null, {
|
||||
positionId: positionNew?.id
|
||||
});
|
||||
}
|
||||
// Insignia
|
||||
if (_oldInsigniaIds.length > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue