From dea1b11e1bf53e331dca2e8dc6007018bd49559d Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Wed, 7 Jan 2026 01:44:18 +0700 Subject: [PATCH] update search --- .../OrganizationDotnetController.ts | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index bfac03bc..b5803029 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -6161,8 +6161,8 @@ export class OrganizationDotnetController extends Controller { where: { ...typeCondition, createdAt: LessThanOrEqual(date), - firstName: Not("") && Not(IsNull()), - lastName: Not("") && Not(IsNull()), + // firstName: Not("") && Not(IsNull()), + // lastName: Not("") && Not(IsNull()), }, order: { firstName: "ASC", @@ -6171,10 +6171,10 @@ export class OrganizationDotnetController extends Controller { }, }); - // group by firstName + lastName แล้วเลือก create_at ล่าสุด + // group by ancestorDNA แล้วเลือก create_at ล่าสุด const grouped = new Map(); for (const item of profile) { - const key = `${item.firstName}-${item.lastName}`; + const key = `${item.ancestorDNA}`; if (!grouped.has(key)) { grouped.set(key, item); } else { @@ -6187,32 +6187,34 @@ export class OrganizationDotnetController extends Controller { } const profile_ = await Promise.all( - Array.from(grouped.values()).map(async (item: PosMasterHistory) => { - let profile = await this.profileRepo.findOne({ - where: { id: item.profileId }, - }); + Array.from(grouped.values()) + .filter((x) => x.profileId != null) + .map(async (item: PosMasterHistory) => { + let profile = await this.profileRepo.findOne({ + where: { id: item.profileId }, + }); - return { - id: item.id, - prefix: item.prefix, - firstName: item.firstName, - lastName: item.lastName, - citizenId: profile?.citizenId ?? null, - dateStart: profile?.dateStart ?? null, - dateAppoint: profile?.dateAppoint ?? null, - keycloak: profile?.keycloak ?? null, - posNo: item.shortName, - position: item.position, - positionLevel: item.posLevel, - positionType: item.posType, - // oc: Oc, - orgRootId: item.rootDnaId, - orgChild1Id: item.child1DnaId, - orgChild2Id: item.child2DnaId, - orgChild3Id: item.child3DnaId, - orgChild4Id: item.child4DnaId, - }; - }), + return { + id: item.id, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + citizenId: profile?.citizenId ?? null, + dateStart: profile?.dateStart ?? null, + dateAppoint: profile?.dateAppoint ?? null, + keycloak: profile?.keycloak ?? null, + posNo: item.shortName, + position: item.position, + positionLevel: item.posLevel, + positionType: item.posType, + // oc: Oc, + orgRootId: item.rootDnaId, + orgChild1Id: item.child1DnaId, + orgChild2Id: item.child2DnaId, + orgChild3Id: item.child3DnaId, + orgChild4Id: item.child4DnaId, + }; + }), ); return new HttpSuccess(profile_);