fix แสดงกรณีรักษาการแทนผิด #2472
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s

This commit is contained in:
harid 2026-05-12 11:51:57 +07:00
parent 760fef5c2f
commit 60191a23d7
3 changed files with 144 additions and 8 deletions

View file

@ -89,7 +89,7 @@ import { ProfileAssistance } from "../entities/ProfileAssistance";
import { CommandRecive } from "../entities/CommandRecive";
import { CommandCode } from "../entities/CommandCode";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
import { CreatePosMasterHistoryOfficer, getTopDegrees, getPosMasterPositions } from "../services/PositionService";
import { ProfileLeaveService } from "../services/ProfileLeaveService";
// import { PostRetireToExprofile } from "./ExRetirementController";
import { getPosNumCodeSit } from "../services/CommandService";
@ -3433,7 +3433,44 @@ export class ProfileController extends Controller {
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: lists, total });
// ดึง posMasterId ทั้งหมด (36 ตัวแรกของ key) เพื่อ query positionName
const posMasterIds = lists
.map((x) => x.key?.substring(0, 36))
.filter((id) => id && id.length === 36);
const posMasterPositionMap = await getPosMasterPositions(posMasterIds);
// ปรับ positionSign สำหรับกรณีรักษาการ
const processedLists = lists.map((x: any) => {
let newPositionSign = x.positionSign;
// ตำแหน่งของคนที่เลือกไปรักษาการ
let childPosition = "";
if (x.posType === "อำนวยการ" || x.posType === "บริหาร") {
childPosition = x.posExecutiveName || "";
if (!childPosition) {
childPosition = `${x.position || ""}ระดับ${x.posLevel || ""}`.trim();
}
} else {
childPosition = `${x.position || ""}${x.posLevel || ""}`.trim();
}
// ตำแหน่งที่รักษาการแทน
const posMasterId = x.key?.substring(0, 36);
const targetPosition = x.positionSign
? x.positionSign
: posMasterPositionMap.get(posMasterId) || "";
// สร้าง positionSign ใหม่
newPositionSign = `${childPosition} รักษาการในตำแหน่ง${targetPosition}`;
return {
...x,
positionSign: newPositionSign,
};
});
return new HttpSuccess({ data: processedLists, total });
} else {
const [lists, total] = await AppDataSource.getRepository(viewDirector)
.createQueryBuilder("viewDirector")