แก้ไขประเภท ระดับตำแหน่ง และจังหวัด อำเภอ ตำบลให้แสดงฟิลด์ที่เป็นชื่อให้เลือก
This commit is contained in:
parent
9fe91ce49c
commit
b2d59ef698
2 changed files with 182 additions and 10 deletions
|
|
@ -348,6 +348,69 @@ export class ApiManageController extends Controller {
|
|||
"commandId",
|
||||
]; // ฟิลด์ที่ไม่ต้องการแสดงในผลลัพธ์
|
||||
|
||||
// การแทนที่ฟิลด์ ID ด้วยฟิลด์ Name สำหรับ Profile entity
|
||||
private readonly PROFILE_FIELD_REPLACEMENTS: Record<
|
||||
string,
|
||||
{ propertyName: string; type: string; comment: string; joinTable: string; joinField: string }
|
||||
> = {
|
||||
posLevelId: {
|
||||
propertyName: "posLevelName",
|
||||
type: "string",
|
||||
comment: "ระดับตำแหน่ง",
|
||||
joinTable: "PosLevel",
|
||||
joinField: "posLevelName",
|
||||
},
|
||||
posTypeId: {
|
||||
propertyName: "posTypeName",
|
||||
type: "string",
|
||||
comment: "ประเภทตำแหน่ง",
|
||||
joinTable: "PosType",
|
||||
joinField: "posTypeName",
|
||||
},
|
||||
registrationProvinceId: {
|
||||
propertyName: "registrationProvinceName",
|
||||
type: "string",
|
||||
comment: "จังหวัดตามทะเบียนบ้าน",
|
||||
joinTable: "Province",
|
||||
joinField: "name",
|
||||
},
|
||||
registrationDistrictId: {
|
||||
propertyName: "registrationDistrictName",
|
||||
type: "string",
|
||||
comment: "เขตตามทะเบียนบ้าน",
|
||||
joinTable: "District",
|
||||
joinField: "name",
|
||||
},
|
||||
registrationSubDistrictId: {
|
||||
propertyName: "registrationSubDistrictName",
|
||||
type: "string",
|
||||
comment: "แขวงตามทะเบียนบ้าน",
|
||||
joinTable: "SubDistrict",
|
||||
joinField: "name",
|
||||
},
|
||||
currentProvinceId: {
|
||||
propertyName: "currentProvinceName",
|
||||
type: "string",
|
||||
comment: "จังหวัดตามปัจจุบัน",
|
||||
joinTable: "Province",
|
||||
joinField: "name",
|
||||
},
|
||||
currentDistrictId: {
|
||||
propertyName: "currentDistrictName",
|
||||
type: "string",
|
||||
comment: "เขตตามปัจจุบัน",
|
||||
joinTable: "District",
|
||||
joinField: "name",
|
||||
},
|
||||
currentSubDistrictId: {
|
||||
propertyName: "currentSubDistrictName",
|
||||
type: "string",
|
||||
comment: "แขวงตามปัจจุบัน",
|
||||
joinTable: "SubDistrict",
|
||||
joinField: "name",
|
||||
},
|
||||
};
|
||||
|
||||
private validateSuperAdminRole(user: any): void {
|
||||
if (!user.role.includes("SUPER_ADMIN")) {
|
||||
throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้");
|
||||
|
|
@ -385,11 +448,8 @@ export class ApiManageController extends Controller {
|
|||
|
||||
const result = this.entities
|
||||
.filter((entity) => entity.system.includes(system))
|
||||
.map(({ name, repository, description, isMain }) => ({
|
||||
tb: name,
|
||||
description,
|
||||
isMain: isMain || false,
|
||||
propertys: repository.metadata.columns
|
||||
.map(({ name, repository, description, isMain }) => {
|
||||
let columns = repository.metadata.columns
|
||||
.filter(
|
||||
(column: any) =>
|
||||
!column.isPrimary && !this.EXCLUDED_COLUMNS.includes(column.propertyName),
|
||||
|
|
@ -399,8 +459,35 @@ export class ApiManageController extends Controller {
|
|||
type: typeof column.type === "string" ? column.type : "string",
|
||||
comment: column.comment,
|
||||
key: column.propertyName,
|
||||
})),
|
||||
}));
|
||||
}));
|
||||
|
||||
// Special handling for Profile entity - replace ID fields with name fields
|
||||
if (name === "Profile") {
|
||||
const replacementKeys = Object.keys(this.PROFILE_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.PROFILE_FIELD_REPLACEMENTS[key].propertyName,
|
||||
type: "string",
|
||||
comment: this.PROFILE_FIELD_REPLACEMENTS[key].comment,
|
||||
key: this.PROFILE_FIELD_REPLACEMENTS[key].propertyName,
|
||||
}));
|
||||
|
||||
columns = [...columns, ...nameFields];
|
||||
}
|
||||
|
||||
return {
|
||||
tb: name,
|
||||
description,
|
||||
isMain: isMain || false,
|
||||
propertys: columns,
|
||||
};
|
||||
});
|
||||
|
||||
return new HttpSuccess(result);
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue