api web service add position system

This commit is contained in:
Warunee Tamkoo 2025-08-14 12:20:59 +07:00
parent 4318a7b631
commit 6563fa825d
2 changed files with 53 additions and 6 deletions

View file

@ -104,7 +104,11 @@ export class ApiManageController extends Controller {
}, },
{ {
code: "organization", code: "organization",
name: "ข้อมูลโครงสร้างและอัตรากำลัง", name: "ข้อมูลโครงสร้าง",
},
{
code: "position",
name: "ข้อมูลอัตรากำลัง",
}, },
]; ];
@ -277,7 +281,7 @@ export class ApiManageController extends Controller {
system: ["position"], system: ["position"],
}, },
{ {
name: "position", name: "Position",
repository: this.positionRepository, repository: this.positionRepository,
description: "ข้อมูลตำแหน่ง", description: "ข้อมูลตำแหน่ง",
system: ["position"], system: ["position"],
@ -312,6 +316,12 @@ export class ApiManageController extends Controller {
description: "ข้อมูลส่วนราชการ ระดับที่ 4", description: "ข้อมูลส่วนราชการ ระดับที่ 4",
system: ["position"], system: ["position"],
}, },
{
name: "Profile",
repository: this.profileRepository,
description: "ข้อมูลคนครอง",
system: ["position"],
},
]; ];
private readonly DEFAULT_PAGE_SIZE = 10; // ขนาดหน้าเริ่มต้น private readonly DEFAULT_PAGE_SIZE = 10; // ขนาดหน้าเริ่มต้น

View file

@ -62,13 +62,20 @@ export class ApiWebServiceController extends Controller {
} else if (system == "registry_temp") { } else if (system == "registry_temp") {
tbMain = "ProfileEmployee"; tbMain = "ProfileEmployee";
condition = `ProfileEmployee.employeeClass = "TEMP"`; condition = `ProfileEmployee.employeeClass = "TEMP"`;
} else { } else if (system == "organization") {
tbMain = "OrgRoot"; tbMain = "OrgRoot";
const revision = await this.orgRevisionRepository.findOne({ const revision = await this.orgRevisionRepository.findOne({
select: ["id"], select: ["id"],
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
condition = `OrgRoot.orgRevisionId = "${revision?.id}"`; 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); const repo = AppDataSource.getRepository(tbMain);
@ -92,7 +99,10 @@ export class ApiWebServiceController extends Controller {
propertyOtherKey.forEach((tb) => { propertyOtherKey.forEach((tb) => {
const relationName = relationMap[tb]; const relationName = relationMap[tb];
if (relationName) { 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; return x;
}); });
console.log("queryBuilder ===> ", queryBuilder.getQuery()); // console.log("queryBuilder ===> ", queryBuilder.getQuery());
// save api history after query success // save api history after query success
const history = { const history = {
@ -158,6 +168,33 @@ export class ApiWebServiceController extends Controller {
lastUpdateFullName: request.user.name, lastUpdateFullName: request.user.name,
}; };
await this.apiHistoryRepository.save(history); 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 });
} }
} }