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