api web service add position system
This commit is contained in:
parent
4318a7b631
commit
6563fa825d
2 changed files with 53 additions and 6 deletions
|
|
@ -104,7 +104,11 @@ export class ApiManageController extends Controller {
|
|||
},
|
||||
{
|
||||
code: "organization",
|
||||
name: "ข้อมูลโครงสร้างและอัตรากำลัง",
|
||||
name: "ข้อมูลโครงสร้าง",
|
||||
},
|
||||
{
|
||||
code: "position",
|
||||
name: "ข้อมูลอัตรากำลัง",
|
||||
},
|
||||
];
|
||||
|
||||
|
|
@ -277,7 +281,7 @@ export class ApiManageController extends Controller {
|
|||
system: ["position"],
|
||||
},
|
||||
{
|
||||
name: "position",
|
||||
name: "Position",
|
||||
repository: this.positionRepository,
|
||||
description: "ข้อมูลตำแหน่ง",
|
||||
system: ["position"],
|
||||
|
|
@ -312,6 +316,12 @@ export class ApiManageController extends Controller {
|
|||
description: "ข้อมูลส่วนราชการ ระดับที่ 4",
|
||||
system: ["position"],
|
||||
},
|
||||
{
|
||||
name: "Profile",
|
||||
repository: this.profileRepository,
|
||||
description: "ข้อมูลคนครอง",
|
||||
system: ["position"],
|
||||
},
|
||||
];
|
||||
|
||||
private readonly DEFAULT_PAGE_SIZE = 10; // ขนาดหน้าเริ่มต้น
|
||||
|
|
|
|||
|
|
@ -62,13 +62,20 @@ export class ApiWebServiceController extends Controller {
|
|||
} else if (system == "registry_temp") {
|
||||
tbMain = "ProfileEmployee";
|
||||
condition = `ProfileEmployee.employeeClass = "TEMP"`;
|
||||
} else {
|
||||
} else if (system == "organization") {
|
||||
tbMain = "OrgRoot";
|
||||
const revision = await this.orgRevisionRepository.findOne({
|
||||
select: ["id"],
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
condition = `OrgRoot.orgRevisionId = "${revision?.id}"`;
|
||||
} else if (system == "position") {
|
||||
tbMain = "PosMaster";
|
||||
const revision = await this.orgRevisionRepository.findOne({
|
||||
select: ["id"],
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
condition = `PosMaster.orgRevisionId = "${revision?.id}"`;
|
||||
}
|
||||
|
||||
const repo = AppDataSource.getRepository(tbMain);
|
||||
|
|
@ -92,7 +99,10 @@ export class ApiWebServiceController extends Controller {
|
|||
propertyOtherKey.forEach((tb) => {
|
||||
const relationName = relationMap[tb];
|
||||
if (relationName) {
|
||||
queryBuilder.leftJoin(`${tbMain}.${relationName}`, tb);
|
||||
queryBuilder.leftJoin(
|
||||
`${tbMain}.${relationName === "next_holder" ? "current_holder" : relationName}`, // เช็คว่าถ้าเป็น next_holder ให้ใช้ current_holder แทน
|
||||
tb,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -135,7 +145,7 @@ export class ApiWebServiceController extends Controller {
|
|||
return x;
|
||||
});
|
||||
|
||||
console.log("queryBuilder ===> ", queryBuilder.getQuery());
|
||||
// console.log("queryBuilder ===> ", queryBuilder.getQuery());
|
||||
|
||||
// save api history after query success
|
||||
const history = {
|
||||
|
|
@ -158,6 +168,33 @@ export class ApiWebServiceController extends Controller {
|
|||
lastUpdateFullName: request.user.name,
|
||||
};
|
||||
await this.apiHistoryRepository.save(history);
|
||||
return new HttpSuccess({ data, total });
|
||||
|
||||
const results = data.map((item) => {
|
||||
const flattenedItem: any = {};
|
||||
|
||||
// Extract nested object properties to top level
|
||||
Object.keys(item).forEach((key) => {
|
||||
const value = item[key];
|
||||
if (value && typeof value === "object") {
|
||||
// if (Array.isArray(value) && value.length === 1) {
|
||||
// // If array has single item, extract it as object
|
||||
// Object.assign(flattenedItem, value[0]);
|
||||
// } else
|
||||
if (!Array.isArray(value)) {
|
||||
// Merge nested object properties to top level
|
||||
Object.assign(flattenedItem, value);
|
||||
} else {
|
||||
// Keep arrays with multiple items or empty arrays as is
|
||||
flattenedItem[key] = value;
|
||||
}
|
||||
} else {
|
||||
// Keep primitive values as is
|
||||
flattenedItem[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return flattenedItem;
|
||||
});
|
||||
return new HttpSuccess({ data: results, total });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue