complete api web service registry add org id
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m4s

This commit is contained in:
Warunee Tamkoo 2026-05-22 21:36:46 +07:00
parent 605c48be57
commit 33bd92af11

View file

@ -563,7 +563,7 @@ export class ApiWebServiceController extends Controller {
// สำหรับ registry system: เก็บ posMaster เพื่อดึง org IDs แล้วค่อย query ancestorDNA
let includeOrgAncestorDna = false;
if (system === "registry") {
if (system === "registry" || system === "registry_emp" || system === "registry_temp") {
// Always join posMaster for registry systems (inner join to exclude profiles without current posMaster)
// Only include posMaster from current revision
if (tbMain === "Profile") {
@ -578,12 +578,28 @@ export class ApiWebServiceController extends Controller {
propertyKey.push("posMaster.orgChild4Id");
} else if (tbMain === "ProfileEmployee") {
// For registry_emp and registry_temp, also use inner join with current revision
if (posMasterAlias === "employeeTempPosMaster") {
if (system === "registry_temp") {
queryBuilder.innerJoin("ProfileEmployee.current_holderTemps", "employeeTempPosMaster", "employeeTempPosMaster.orgRevisionId = :currentRevisionId");
queryBuilder.setParameter("currentRevisionId", this.currentRevisionId);
// Add org ID fields from employeeTempPosMaster to propertyKey
propertyKey.push("employeeTempPosMaster.orgRootId");
propertyKey.push("employeeTempPosMaster.orgChild1Id");
propertyKey.push("employeeTempPosMaster.orgChild2Id");
propertyKey.push("employeeTempPosMaster.orgChild3Id");
propertyKey.push("employeeTempPosMaster.orgChild4Id");
} else {
// registry_emp
queryBuilder.innerJoin("ProfileEmployee.current_holders", "employeePosMaster", "employeePosMaster.orgRevisionId = :currentRevisionId");
queryBuilder.setParameter("currentRevisionId", this.currentRevisionId);
// Add org ID fields from employeePosMaster to propertyKey
propertyKey.push("employeePosMaster.orgRootId");
propertyKey.push("employeePosMaster.orgChild1Id");
propertyKey.push("employeePosMaster.orgChild2Id");
propertyKey.push("employeePosMaster.orgChild3Id");
propertyKey.push("employeePosMaster.orgChild4Id");
}
queryBuilder.setParameter("currentRevisionId", this.currentRevisionId);
}
// Mark that we need to include ancestorDNA fields
@ -643,7 +659,7 @@ export class ApiWebServiceController extends Controller {
.getManyAndCount();
}
// สำหรับ registry: ดึง ancestorDNA จาก org tables
// สำหรับ registry systems: ดึง ancestorDNA จาก org tables
let orgRootAncestorMap: Record<string, string> = {};
let orgChild1AncestorMap: Record<string, string> = {};
let orgChild2AncestorMap: Record<string, string> = {};
@ -659,6 +675,7 @@ export class ApiWebServiceController extends Controller {
const orgChild4Ids = new Set<string>();
items.forEach((item) => {
// Handle Profile (registry) - current_holders
if (item["current_holders"] && Array.isArray(item["current_holders"]) && item["current_holders"].length > 0) {
const posMaster = item["current_holders"][0];
if (posMaster.orgRootId) orgRootIds.add(posMaster.orgRootId);
@ -667,6 +684,24 @@ export class ApiWebServiceController extends Controller {
if (posMaster.orgChild3Id) orgChild3Ids.add(posMaster.orgChild3Id);
if (posMaster.orgChild4Id) orgChild4Ids.add(posMaster.orgChild4Id);
}
// Handle ProfileEmployee (registry_emp) - current_holders
if (item["current_holders"] && Array.isArray(item["current_holders"]) && item["current_holders"].length > 0) {
const posMaster = item["current_holders"][0];
if (posMaster.orgRootId) orgRootIds.add(posMaster.orgRootId);
if (posMaster.orgChild1Id) orgChild1Ids.add(posMaster.orgChild1Id);
if (posMaster.orgChild2Id) orgChild2Ids.add(posMaster.orgChild2Id);
if (posMaster.orgChild3Id) orgChild3Ids.add(posMaster.orgChild3Id);
if (posMaster.orgChild4Id) orgChild4Ids.add(posMaster.orgChild4Id);
}
// Handle ProfileEmployee (registry_temp) - current_holderTemps
if (item["current_holderTemps"] && Array.isArray(item["current_holderTemps"]) && item["current_holderTemps"].length > 0) {
const posMaster = item["current_holderTemps"][0];
if (posMaster.orgRootId) orgRootIds.add(posMaster.orgRootId);
if (posMaster.orgChild1Id) orgChild1Ids.add(posMaster.orgChild1Id);
if (posMaster.orgChild2Id) orgChild2Ids.add(posMaster.orgChild2Id);
if (posMaster.orgChild3Id) orgChild3Ids.add(posMaster.orgChild3Id);
if (posMaster.orgChild4Id) orgChild4Ids.add(posMaster.orgChild4Id);
}
});
// Query org tables to get ancestorDNA
@ -788,6 +823,31 @@ export class ApiWebServiceController extends Controller {
delete flattened[config.joinRelation];
}
});
// แปลง ancestorDNA เป็น orgRootId, orgChild1Id, etc. (สำหรับ registry_emp และ registry_temp)
if (includeOrgAncestorDna) {
const posMasterKey = system === "registry_temp" ? "current_holderTemps" : "current_holders";
if (rest[posMasterKey] && Array.isArray(rest[posMasterKey]) && rest[posMasterKey].length > 0) {
const posMaster = rest[posMasterKey][0];
// Always set the fields, use null if no value
flattened.orgRootId = (posMaster.orgRootId && orgRootAncestorMap[posMaster.orgRootId]) ? orgRootAncestorMap[posMaster.orgRootId] : null;
flattened.orgChild1Id = (posMaster.orgChild1Id && orgChild1AncestorMap[posMaster.orgChild1Id]) ? orgChild1AncestorMap[posMaster.orgChild1Id] : null;
flattened.orgChild2Id = (posMaster.orgChild2Id && orgChild2AncestorMap[posMaster.orgChild2Id]) ? orgChild2AncestorMap[posMaster.orgChild2Id] : null;
flattened.orgChild3Id = (posMaster.orgChild3Id && orgChild3AncestorMap[posMaster.orgChild3Id]) ? orgChild3AncestorMap[posMaster.orgChild3Id] : null;
flattened.orgChild4Id = (posMaster.orgChild4Id && orgChild4AncestorMap[posMaster.orgChild4Id]) ? orgChild4AncestorMap[posMaster.orgChild4Id] : null;
} else {
// No posMaster data, set all to null
flattened.orgRootId = null;
flattened.orgChild1Id = null;
flattened.orgChild2Id = null;
flattened.orgChild3Id = null;
flattened.orgChild4Id = null;
}
// Delete the posMaster array
delete flattened[posMasterKey];
}
return flattened;
}