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
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m3s
This commit is contained in:
parent
81e8dadd9b
commit
f06be7ce77
2 changed files with 124 additions and 1 deletions
|
|
@ -375,6 +375,11 @@ export class ApiManageController extends Controller {
|
||||||
"isUpload",
|
"isUpload",
|
||||||
"isDeleted",
|
"isDeleted",
|
||||||
"isEntry",
|
"isEntry",
|
||||||
|
"prefixId",
|
||||||
|
"leaveId",
|
||||||
|
"leaveTypeId",
|
||||||
|
"isDeputy",
|
||||||
|
"isCommission",
|
||||||
]; // ฟิลด์ที่ไม่ต้องการแสดงในผลลัพธ์
|
]; // ฟิลด์ที่ไม่ต้องการแสดงในผลลัพธ์
|
||||||
|
|
||||||
// การแทนที่ฟิลด์ ID ด้วยฟิลด์ Name สำหรับ Profile entity
|
// การแทนที่ฟิลด์ ID ด้วยฟิลด์ Name สำหรับ Profile entity
|
||||||
|
|
@ -489,6 +494,20 @@ export class ApiManageController extends Controller {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// การแทนที่ฟิลด์ ID ด้วยฟิลด์ Name สำหรับ ProfileLeave entity
|
||||||
|
private readonly PROFILELEAVE_FIELD_REPLACEMENTS: Record<
|
||||||
|
string,
|
||||||
|
{ propertyName: string; type: string; comment: string; joinTable: string; joinField: string }
|
||||||
|
> = {
|
||||||
|
leaveTypeId: {
|
||||||
|
propertyName: "leaveTypeName",
|
||||||
|
type: "string",
|
||||||
|
comment: "ประเภทการลา",
|
||||||
|
joinTable: "LeaveType",
|
||||||
|
joinField: "name",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
private validateSuperAdminRole(user: any): void {
|
private validateSuperAdminRole(user: any): void {
|
||||||
if (!user.role.includes("SUPER_ADMIN")) {
|
if (!user.role.includes("SUPER_ADMIN")) {
|
||||||
throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้");
|
throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้");
|
||||||
|
|
@ -599,6 +618,26 @@ export class ApiManageController extends Controller {
|
||||||
columns = [...columns, ...nameFields];
|
columns = [...columns, ...nameFields];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special handling for ProfileLeave entity - replace ID fields with name fields
|
||||||
|
if (name === "ProfileLeave") {
|
||||||
|
const replacementKeys = Object.keys(this.PROFILELEAVE_FIELD_REPLACEMENTS);
|
||||||
|
|
||||||
|
// Remove ID fields that should be replaced
|
||||||
|
columns = columns.filter(
|
||||||
|
(col: { propertyName: string }) => !replacementKeys.includes(col.propertyName),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add the corresponding name fields
|
||||||
|
const nameFields = replacementKeys.map((key) => ({
|
||||||
|
propertyName: this.PROFILELEAVE_FIELD_REPLACEMENTS[key].propertyName,
|
||||||
|
type: "string",
|
||||||
|
comment: this.PROFILELEAVE_FIELD_REPLACEMENTS[key].comment,
|
||||||
|
key: this.PROFILELEAVE_FIELD_REPLACEMENTS[key].propertyName,
|
||||||
|
}));
|
||||||
|
|
||||||
|
columns = [...columns, ...nameFields];
|
||||||
|
}
|
||||||
|
|
||||||
// Special handling for PosMaster entity - add Profile fields for holder information
|
// Special handling for PosMaster entity - add Profile fields for holder information
|
||||||
if (name === "PosMaster") {
|
if (name === "PosMaster") {
|
||||||
// Add Profile fields that are accessible via current_holder relation
|
// Add Profile fields that are accessible via current_holder relation
|
||||||
|
|
|
||||||
|
|
@ -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
|
// การแทนที่ฟิลด์ ID ด้วยฟิลด์ Name สำหรับ Position entity
|
||||||
private readonly POSITION_FIELD_REPLACEMENTS: Record<
|
private readonly POSITION_FIELD_REPLACEMENTS: Record<
|
||||||
string,
|
string,
|
||||||
|
|
@ -270,7 +282,7 @@ export class ApiWebServiceController extends Controller {
|
||||||
let condition: string = "1=1";
|
let condition: string = "1=1";
|
||||||
if (system == "registry") {
|
if (system == "registry") {
|
||||||
tbMain = "Profile";
|
tbMain = "Profile";
|
||||||
condition = `Profile.isActive = true`;
|
condition = `Profile.isActive = true AND Profile.isDelete = false`;
|
||||||
} else if (system == "registry_emp") {
|
} else if (system == "registry_emp") {
|
||||||
tbMain = "ProfileEmployee";
|
tbMain = "ProfileEmployee";
|
||||||
condition = `ProfileEmployee.employeeClass = "PERM"`;
|
condition = `ProfileEmployee.employeeClass = "PERM"`;
|
||||||
|
|
@ -296,6 +308,54 @@ export class ApiWebServiceController extends Controller {
|
||||||
let posMasterCondition: string = "1=1";
|
let posMasterCondition: string = "1=1";
|
||||||
let posMasterAlias: string = "";
|
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
|
// Special handling for Profile and ProfileEmployee systems with permission filtering
|
||||||
if (system == "registry") {
|
if (system == "registry") {
|
||||||
// Get current revision
|
// 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);
|
const queryBuilder = repo.createQueryBuilder(tbMain);
|
||||||
|
|
||||||
// join กับตารารอง
|
// 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 (ข้อมูลคนครอง)
|
// join สำหรับ PosMaster เมื่อต้องการดึงค่าจาก Profile (ข้อมูลคนครอง)
|
||||||
const posMasterProfileFields: string[] = [];
|
const posMasterProfileFields: string[] = [];
|
||||||
if (tbMain === "PosMaster") {
|
if (tbMain === "PosMaster") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue