From 32e682d05ec8ef2f0d0f2c10da491e88957e2428 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Fri, 2 Jan 2026 21:43:57 +0700 Subject: [PATCH 1/2] search dna --- src/controllers/OrganizationController.ts | 147 ++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index edbd1f97..3050285d 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -5484,6 +5484,153 @@ export class OrganizationController extends Controller { } } + /** + * API เช็ค node detail + * + * @summary เช็ค node detail (ADMIN) + * + */ + @Post("find/allv2") + async findNodeAllDetailV2(@Body() requestBody: { node: number; nodeId: string }) { + switch (requestBody.node) { + case 0: { + const data = await this.orgRootRepository.findOne({ + where: { ancestorDNA: requestBody.nodeId }, + order: { createdAt: "DESC" }, + }); + if (data == null) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId."); + } + return new HttpSuccess({ + rootId: data.id, + rootDnaId: data.ancestorDNA, + root: data.orgRootName, + rootShortName: data.orgRootShortName, + }); + } + case 1: { + const data = await this.child1Repository.findOne({ + where: { ancestorDNA: requestBody.nodeId }, + relations: { + orgRoot: true, + }, + order: { createdAt: "DESC" }, + }); + if (data == null) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1."); + } + return new HttpSuccess({ + rootId: data.orgRootId, + rootDnaId: data.orgRoot == null ? null : data.orgRoot.ancestorDNA, + root: data.orgRoot == null ? null : data.orgRoot.orgRootName, + rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName, + child1Id: data.id, + child1DnaId: data.ancestorDNA, + child1: data.orgChild1Name, + child1ShortName: data.orgChild1ShortName, + }); + } + case 2: { + const data = await this.child2Repository.findOne({ + where: { ancestorDNA: requestBody.nodeId }, + relations: { + orgRoot: true, + orgChild1: true, + }, + order: { createdAt: "DESC" }, + }); + if (data == null) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2."); + } + return new HttpSuccess({ + rootId: data.orgRootId, + rootDnaId: data.orgRoot == null ? null : data.orgRoot.ancestorDNA, + root: data.orgRoot == null ? null : data.orgRoot.orgRootName, + rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName, + child1Id: data.orgChild1Id, + child1DnaId: data.orgChild1 == null ? null : data.orgChild1.ancestorDNA, + child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name, + child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName, + child2Id: data.id, + child2DnaId: data.ancestorDNA, + child2: data.orgChild2Name, + child2ShortName: data.orgChild2ShortName, + }); + } + case 3: { + const data = await this.child3Repository.findOne({ + where: { ancestorDNA: requestBody.nodeId }, + relations: { + orgRoot: true, + orgChild1: true, + orgChild2: true, + }, + order: { createdAt: "DESC" }, + }); + if (data == null) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3."); + } + return new HttpSuccess({ + rootId: data.orgRootId, + rootDnaId: data.orgRoot == null ? null : data.orgRoot.ancestorDNA, + root: data.orgRoot == null ? null : data.orgRoot.orgRootName, + rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName, + child1Id: data.orgChild1Id, + child1DnaId: data.orgChild1 == null ? null : data.orgChild1.ancestorDNA, + child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name, + child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName, + child2Id: data.orgChild2Id, + child2DnaId: data.orgChild2 == null ? null : data.orgChild2.ancestorDNA, + child2: data.orgChild2 == null ? null : data.orgChild2.orgChild2Name, + child2ShortName: data.orgChild2 == null ? null : data.orgChild2.orgChild2ShortName, + child3Id: data.id, + child3DnaId: data.ancestorDNA, + child3: data.orgChild3Name, + child3ShortName: data.orgChild3ShortName, + }); + } + case 4: { + const data = await this.child4Repository.findOne({ + where: { ancestorDNA: requestBody.nodeId }, + relations: { + orgRoot: true, + orgChild1: true, + orgChild2: true, + orgChild3: true, + }, + order: { createdAt: "DESC" }, + }); + if (data == null) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4."); + } + return new HttpSuccess({ + rootId: data.orgRootId, + rootDnaId: data.orgRoot == null ? null : data.orgRoot.ancestorDNA, + root: data.orgRoot == null ? null : data.orgRoot.orgRootName, + rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName, + child1Id: data.orgChild1Id, + child1DnaId: data.orgChild1 == null ? null : data.orgChild1.ancestorDNA, + child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name, + child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName, + child2Id: data.orgChild2Id, + child2DnaId: data.orgChild2 == null ? null : data.orgChild2.ancestorDNA, + child2: data.orgChild2 == null ? null : data.orgChild2.orgChild2Name, + child2ShortName: data.orgChild2 == null ? null : data.orgChild2.orgChild2ShortName, + child3Id: data.orgChild3Id, + child3DnaId: data.orgChild3 == null ? null : data.orgChild3.ancestorDNA, + child3: data.orgChild3 == null ? null : data.orgChild3.orgChild3Name, + child3ShortName: data.orgChild3 == null ? null : data.orgChild3.orgChild3ShortName, + child4Id: data.id, + child4DnaId: data.ancestorDNA, + child4: data.orgChild4Name, + child4ShortName: data.orgChild4ShortName, + }); + } + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: " + requestBody.node); + } + } + /** * API หาสำนักทั้งหมด * From a69220556c1c4739ac3de4612605bd19bd2e4651 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Wed, 7 Jan 2026 01:42:32 +0700 Subject: [PATCH 2/2] update search dna --- .../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_);