update #141
This commit is contained in:
parent
b10f17b5dc
commit
b92419c4d4
2 changed files with 18 additions and 37 deletions
|
|
@ -59,7 +59,6 @@ export class ApiWebServiceController extends Controller {
|
||||||
}
|
}
|
||||||
await isPermissionRequest(request, apiName.id);
|
await isPermissionRequest(request, apiName.id);
|
||||||
const offset = (page - 1) * pageSize;
|
const offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
const propertyKey = apiName.apiAttributes.map((attr) => `${attr.tbName}.${attr.propertyKey}`);
|
const propertyKey = apiName.apiAttributes.map((attr) => `${attr.tbName}.${attr.propertyKey}`);
|
||||||
|
|
||||||
let Main:string = ""
|
let Main:string = ""
|
||||||
|
|
@ -81,7 +80,7 @@ export class ApiWebServiceController extends Controller {
|
||||||
select: ["id"],
|
select: ["id"],
|
||||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }
|
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }
|
||||||
});
|
});
|
||||||
condition = `OrgRoot.orgRevisionId = '${revision?.id}'`
|
condition = `OrgRoot.orgRevisionId = "${revision?.id}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const repo = AppDataSource.getRepository(Main);
|
const repo = AppDataSource.getRepository(Main);
|
||||||
|
|
@ -109,48 +108,26 @@ export class ApiWebServiceController extends Controller {
|
||||||
propertyOtherKey.forEach((tb) => {
|
propertyOtherKey.forEach((tb) => {
|
||||||
const relationName = relationMap[tb];
|
const relationName = relationMap[tb];
|
||||||
if (relationName) {
|
if (relationName) {
|
||||||
queryBuilder.leftJoinAndSelect(`${Main}.${relationName}`, tb);
|
queryBuilder.leftJoin(`${Main}.${relationName}`, tb);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// เพิ่ม Main.id เพราะจะใช้ pk ในการแมบและนับจำนวน
|
||||||
|
if (!propertyKey.includes(`${Main}.id`)) {
|
||||||
|
propertyKey.push(`${Main}.id`);
|
||||||
|
}
|
||||||
|
|
||||||
const [items, total] = await queryBuilder
|
const [items, total] = await queryBuilder
|
||||||
|
.select(propertyKey)
|
||||||
.where(condition)
|
.where(condition)
|
||||||
.orderBy(`${Main}.createdAt`, "DESC")
|
// .orderBy(`${Main}.createdAt`, "DESC")
|
||||||
.skip(offset)
|
.skip(offset)
|
||||||
.take(pageSize)
|
.take(pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
||||||
const results = items.map(item => {
|
// ลบ Main.id
|
||||||
const result: any = {};
|
const results = items.map(({ id, ...x }) => x);
|
||||||
propertyKey.forEach(key => {
|
|
||||||
const [table, field] = key.split(".");
|
|
||||||
|
|
||||||
if (table === Main) {
|
|
||||||
result[field] = item[field];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const relationName = relationMap[table];
|
|
||||||
if (!relationName) return;
|
|
||||||
if (!Array.isArray(result[relationName])) {
|
|
||||||
result[relationName] = item[relationName]
|
|
||||||
? item[relationName].map((relItem: any) => {
|
|
||||||
const filteredRel: any = {};
|
|
||||||
propertyKey
|
|
||||||
.filter(k => k.startsWith(`${table}.`))
|
|
||||||
.forEach(k => {
|
|
||||||
const [, relField] = k.split(".");
|
|
||||||
filteredRel[relField] = relItem[relField];
|
|
||||||
});
|
|
||||||
return filteredRel;
|
|
||||||
})
|
|
||||||
: [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
|
|
||||||
return new HttpSuccess({ items: results, total });
|
return new HttpSuccess({ items: results, total });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -693,7 +693,11 @@ export class OrganizationDotnetController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let positionLeaveName = profile.posLevel?.posLevelName ?? null;
|
let positionLeaveName =
|
||||||
|
profile.posType == null && profile.posLevel == null
|
||||||
|
? ""
|
||||||
|
: `${profile.posType?.posTypeShortName ?? ""} ${profile.posLevel?.posLevelName ?? ""}`
|
||||||
|
|
||||||
const _profileCurrent = profile?.current_holders?.find(
|
const _profileCurrent = profile?.current_holders?.find(
|
||||||
(x) =>
|
(x) =>
|
||||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue