fix แสดงกรณีรักษาการแทนผิด #2472
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
This commit is contained in:
parent
760fef5c2f
commit
60191a23d7
3 changed files with 144 additions and 8 deletions
|
|
@ -12,6 +12,67 @@ import { Position } from "../entities/Position";
|
|||
import { ProfileEducation } from "../entities/ProfileEducation";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
/**
|
||||
* function สำหรับดึงตำแหน่งที่รักษาการแทน
|
||||
* ใช้กรณี positionSign ว่าง
|
||||
* - ถ้า posType = "อำนวยการ" หรือ "บริหาร" ใช้ posExecutiveName
|
||||
* - ถ้า posType อื่นๆ ใช้ positionName + posLevel
|
||||
*/
|
||||
export async function getPosMasterPositions(
|
||||
posMasterIds: string[]
|
||||
): Promise<Map<string, string>> {
|
||||
if (posMasterIds.length === 0) {
|
||||
return new Map();
|
||||
}
|
||||
|
||||
const positionRepo = AppDataSource.getRepository(Position);
|
||||
|
||||
// Query รอบที่ 1: หา position ที่มีคนครอง
|
||||
const positionsWithHolder = await positionRepo.find({
|
||||
where: {
|
||||
posMasterId: In(posMasterIds),
|
||||
positionIsSelected: true,
|
||||
},
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
});
|
||||
|
||||
// หา posMasterId ที่ยังไม่ได้ผลลัพธ์
|
||||
const foundMasterIds = new Set(positionsWithHolder.map((p) => p.posMasterId));
|
||||
const missingMasterIds = posMasterIds.filter((id) => !foundMasterIds.has(id));
|
||||
|
||||
// Query รอบที่ 2: เฉพาะที่ขาด (กรณีไม่มีคนครอง)
|
||||
let positionsWithoutHolder: Position[] = [];
|
||||
if (missingMasterIds.length > 0) {
|
||||
positionsWithoutHolder = await positionRepo.find({
|
||||
where: {
|
||||
posMasterId: In(missingMasterIds),
|
||||
},
|
||||
order: { createdAt: "ASC" },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
});
|
||||
}
|
||||
|
||||
// รวม positions และสร้าง Map
|
||||
const allPositions = [...positionsWithHolder, ...positionsWithoutHolder];
|
||||
const positionMap = new Map<string, string>();
|
||||
|
||||
for (const pos of allPositions) {
|
||||
const posTypeName = pos.posType?.posTypeName || "";
|
||||
let positionText = "";
|
||||
|
||||
if (posTypeName === "อำนวยการ" || posTypeName === "บริหาร") {
|
||||
positionText = pos.posExecutive?.posExecutiveName || `${pos.positionName || ""}ระดับ${pos.posLevel?.posLevelName || ""}`.trim();
|
||||
} else {
|
||||
positionText = `${pos.positionName || ""}${pos.posLevel?.posLevelName || ""}`.trim();
|
||||
}
|
||||
|
||||
positionMap.set(pos.posMasterId, positionText);
|
||||
}
|
||||
|
||||
return positionMap;
|
||||
}
|
||||
|
||||
|
||||
export async function CreatePosMasterHistoryOfficer(
|
||||
posMasterId: string,
|
||||
request: RequestWithUser | null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue