fix ส่งออกคำสั่งรายชื่อผู้สอบผ่าน รายชื่อไม่แสดงในโครงสร้าง #2402
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m14s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m14s
This commit is contained in:
parent
d553c1406c
commit
b69f8a6c08
1 changed files with 33 additions and 4 deletions
|
|
@ -6844,12 +6844,36 @@ export class CommandController extends Controller {
|
|||
}
|
||||
//Position
|
||||
if (item.bodyPosition && item.bodyPosition != null) {
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
where: { id: item.bodyPosition.posmasterId },
|
||||
// STEP 1: หา posMaster ที่จะใช้งานตาม id ที่ส่งมา (อาจเป็นตำแหน่งเก่าหรือใหม่ก็ได้)
|
||||
let posMaster = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
id: item.bodyPosition.posmasterId,
|
||||
},
|
||||
relations: { orgRevision: true }
|
||||
});
|
||||
|
||||
// เช็คว่า posMaster ที่หามาอยู่ในโครงสร้างปัจจุบันหรือไม่
|
||||
const isCurrent = posMaster?.orgRevision?.orgRevisionIsCurrent === true &&
|
||||
posMaster?.orgRevision?.orgRevisionIsDraft === false;
|
||||
|
||||
// ถ้าไม่อยู่ในโครงสร้างปัจจุบัน ให้หาตัวใหม่จาก ancestorDNA
|
||||
if (!isCurrent && posMaster?.ancestorDNA) {
|
||||
posMaster = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
ancestorDNA: posMaster.ancestorDNA,
|
||||
orgRevision: {
|
||||
orgRevisionIsCurrent: true,
|
||||
orgRevisionIsDraft: false
|
||||
}
|
||||
},
|
||||
relations: { orgRevision: true }
|
||||
});
|
||||
}
|
||||
|
||||
if (posMaster == null)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||
|
||||
// STEP 2: เคลียร์ข้อมูลตำแหน่งเก่าที่ครองอยู่ ในโครงสร้างปัจจุบัน
|
||||
const posMasterOld = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
current_holderId: profile.id,
|
||||
|
|
@ -6857,10 +6881,12 @@ export class CommandController extends Controller {
|
|||
},
|
||||
});
|
||||
if (posMasterOld != null) {
|
||||
// เคลียร์คนครองเก่าออกจากตำแหน่งเดิม
|
||||
posMasterOld.current_holderId = null;
|
||||
posMasterOld.lastUpdatedAt = new Date();
|
||||
}
|
||||
|
||||
// หา position เก่าที่เลือกไว้ แล้วเคลียร์การเลือก
|
||||
const positionOld = await this.positionRepository.findOne({
|
||||
where: {
|
||||
posMasterId: posMasterOld?.id,
|
||||
|
|
@ -6872,9 +6898,10 @@ export class CommandController extends Controller {
|
|||
await this.positionRepository.save(positionOld);
|
||||
}
|
||||
|
||||
// STEP 3: เคลียร์ position ที่เลือกไว้อื่นๆ ใน posMaster ตัวใหม่
|
||||
const checkPosition = await this.positionRepository.find({
|
||||
where: {
|
||||
posMasterId: item.bodyPosition.posmasterId,
|
||||
posMasterId: posMaster.id,
|
||||
positionIsSelected: true,
|
||||
},
|
||||
});
|
||||
|
|
@ -6886,6 +6913,7 @@ export class CommandController extends Controller {
|
|||
await this.positionRepository.save(clearPosition);
|
||||
}
|
||||
|
||||
// STEP 4: กำหนดคนครองใหม่ให้กับ posMaster
|
||||
posMaster.current_holderId = profile.id;
|
||||
posMaster.lastUpdatedAt = new Date();
|
||||
// posMaster.conditionReason = _null;
|
||||
|
|
@ -6896,10 +6924,11 @@ 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: item.bodyPosition.posmasterId,
|
||||
posMasterId: posMaster.id, // ใช้ id ของ posMaster ตัวใหม่
|
||||
},
|
||||
});
|
||||
if (positionNew != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue