fixes for ProfileLeave queries. Changed leaveTypeId to return leaveTypeName from LeaveType master data and added isDeleted filtering for ProfileLeave and 37 other Profile entities.
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m3s

This commit is contained in:
Warunee Tamkoo 2026-05-26 15:35:35 +07:00
parent 81e8dadd9b
commit f06be7ce77
2 changed files with 124 additions and 1 deletions

View file

@ -74,6 +74,18 @@ export class ApiWebServiceController extends Controller {
},
};
// การแทนที่ฟิลด์ ID ด้วยฟิลด์ Name สำหรับ ProfileLeave entity
private readonly PROFILELEAVE_FIELD_REPLACEMENTS: Record<
string,
{ propertyName: string; joinRelation: string; joinField: string }
> = {
leaveTypeName: {
propertyName: "leaveTypeId",
joinRelation: "leaveType",
joinField: "name",
},
};
// การแทนที่ฟิลด์ ID ด้วยฟิลด์ Name สำหรับ Position entity
private readonly POSITION_FIELD_REPLACEMENTS: Record<
string,
@ -270,7 +282,7 @@ export class ApiWebServiceController extends Controller {
let condition: string = "1=1";
if (system == "registry") {
tbMain = "Profile";
condition = `Profile.isActive = true`;
condition = `Profile.isActive = true AND Profile.isDelete = false`;
} else if (system == "registry_emp") {
tbMain = "ProfileEmployee";
condition = `ProfileEmployee.employeeClass = "PERM"`;
@ -296,6 +308,54 @@ export class ApiWebServiceController extends Controller {
let posMasterCondition: string = "1=1";
let posMasterAlias: string = "";
// Add isDeleted filtering for entities that have this field
// Profile.ts uses isDelete (singular) instead of isDeleted
if (tbMain === "Profile") {
// Already handled above in the registry system condition
} else if (
[
"ProfileAbility",
"ProfileAbilityHistory",
"ProfileAbsentLate",
"ProfileActposition",
"ProfileActpositionHistory",
"ProfileAssistance",
"ProfileAssistanceHistory",
"ProfileAssessment",
"ProfileAssessmentHistory",
"ProfileCertificate",
"ProfileCertificateHistory",
"ProfileChangeName",
"ProfileChangeNameHistory",
"ProfileChildren",
"ProfileChildrenHistory",
"ProfileDiscipline",
"ProfileDisciplineHistory",
"ProfileDevelopment",
"ProfileDevelopmentHistory",
"ProfileDuty",
"ProfileDutyHistory",
"ProfileEducation",
"ProfileEducationHistory",
"ProfileHonor",
"ProfileHonorHistory",
"ProfileInsignia",
"ProfileInsigniaHistory",
"ProfileLeave",
"ProfileNopaid",
"ProfileNopaidHistory",
"ProfileOther",
"ProfileOtherHistory",
"ProfileSalary",
"ProfileSalaryHistory",
"ProfileSalaryTemp",
"ProfileTraining",
"ProfileTrainingHistory",
].includes(tbMain)
) {
condition = `${tbMain}.isDeleted = false`;
}
// Special handling for Profile and ProfileEmployee systems with permission filtering
if (system == "registry") {
// Get current revision
@ -463,6 +523,23 @@ export class ApiWebServiceController extends Controller {
});
}
// สำหรับ ProfileLeave: ตรวจสอบฟิลด์ที่ต้องการ join และแปลง propertyKey
const profileLeaveFieldJoins: Record<string, string> = {}; // alias -> relationName
if (tbMain === "ProfileLeave") {
propertyKey = propertyKey.map((key) => {
const [table, field] = key.split(".");
if (table === "ProfileLeave") {
const replacement = this.PROFILELEAVE_FIELD_REPLACEMENTS[field];
if (replacement) {
const alias = `${table}_${replacement.joinRelation}`;
profileLeaveFieldJoins[alias] = replacement.joinRelation;
return `${alias}.${replacement.joinField}`;
}
}
return key;
});
}
const queryBuilder = repo.createQueryBuilder(tbMain);
// join กับตารารอง
@ -537,6 +614,13 @@ export class ApiWebServiceController extends Controller {
});
}
// join สำหรับฟิลด์ ProfileLeave ที่ต้องการดึงค่าจากตารางอื่น
if (tbMain === "ProfileLeave" && Object.keys(profileLeaveFieldJoins).length > 0) {
Object.entries(profileLeaveFieldJoins).forEach(([alias, relationName]) => {
queryBuilder.leftJoin(`${tbMain}.${relationName}`, alias);
});
}
// join สำหรับ PosMaster เมื่อต้องการดึงค่าจาก Profile (ข้อมูลคนครอง)
const posMasterProfileFields: string[] = [];
if (tbMain === "PosMaster") {