fixed performance function GetOfficersByAdminRoleV3

This commit is contained in:
Warunee Tamkoo 2026-05-06 14:24:24 +07:00
parent 362515a7ca
commit 9a7a8f970c

View file

@ -8593,13 +8593,29 @@ export class OrganizationDotnetController extends Controller {
where: { where: {
...typeCondition, ...typeCondition,
createdAt: LessThanOrEqual(date), createdAt: LessThanOrEqual(date),
// firstName: Not("") && Not(IsNull()),
// lastName: Not("") && Not(IsNull()),
}, },
select: [
"profileId",
"prefix",
"firstName",
"lastName",
"shortName",
"posMasterNo",
"position",
"posType",
"posLevel",
"ancestorDNA",
"rootDnaId",
"child1DnaId",
"child2DnaId",
"child3DnaId",
"child4DnaId",
"createdAt",
],
order: { order: {
firstName: "ASC", firstName: "ASC",
lastName: "ASC", lastName: "ASC",
createdAt: "DESC", // ให้ createdAt ล่าสุดอยู่ข้างบน createdAt: "DESC",
}, },
}); });
@ -8646,14 +8662,21 @@ export class OrganizationDotnetController extends Controller {
} }
} }
const profile_ = await Promise.all( const profileIds = Array.from(grouped3.values())
Array.from(grouped3.values())
.filter((x) => x.profileId != null) .filter((x) => x.profileId != null)
.map(async (item: PosMasterHistory) => { .map((x) => x.profileId);
let profile = await this.profileRepo.findOne({
where: { id: item.profileId }, const profiles = await this.profileRepo.find({
where: { id: In(profileIds) },
select: ["id", "citizenId", "dateStart", "dateAppoint", "keycloak"],
}); });
const profileMap = new Map(profiles.map((p) => [p.id, p]));
const profile_ = Array.from(grouped3.values())
.filter((x) => x.profileId != null)
.map((item: PosMasterHistory) => {
const profile = profileMap.get(item.profileId);
return { return {
id: item.profileId, id: item.profileId,
prefix: item.prefix, prefix: item.prefix,
@ -8667,15 +8690,13 @@ export class OrganizationDotnetController extends Controller {
position: item.position, position: item.position,
positionLevel: item.posLevel, positionLevel: item.posLevel,
positionType: item.posType, positionType: item.posType,
// oc: Oc,
orgRootId: item.rootDnaId, orgRootId: item.rootDnaId,
orgChild1Id: item.child1DnaId, orgChild1Id: item.child1DnaId,
orgChild2Id: item.child2DnaId, orgChild2Id: item.child2DnaId,
orgChild3Id: item.child3DnaId, orgChild3Id: item.child3DnaId,
orgChild4Id: item.child4DnaId, orgChild4Id: item.child4DnaId,
}; };
}), });
);
return new HttpSuccess( return new HttpSuccess(
(profile_ ?? []).sort((a, b) => a.posNo.localeCompare(b.posNo, undefined, { numeric: true })), (profile_ ?? []).sort((a, b) => a.posNo.localeCompare(b.posNo, undefined, { numeric: true })),