From 62acc5c6610afeb8289cd08b8f27568cc7241774 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 14 Jul 2025 13:23:07 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=AB=E0=B8=99?= =?UTF-8?q?=E0=B9=88=E0=B8=A7=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99=20?= =?UTF-8?q?=E0=B8=AA=E0=B9=88=E0=B8=A7=E0=B8=99=E0=B8=A3=E0=B8=B2=E0=B8=8A?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationDotnetController.ts | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 8693c955..a2010ddb 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -21,6 +21,10 @@ import { Profile } from "../entities/Profile"; import { Brackets, In, IsNull, Not } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; import { OrgRoot } from "../entities/OrgRoot"; +import { OrgChild1 } from "../entities/OrgChild1"; +import { OrgChild2 } from "../entities/OrgChild2"; +import { OrgChild3 } from "../entities/OrgChild3"; +import { OrgChild4 } from "../entities/OrgChild4"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { Position } from "../entities/Position"; import { Insignia } from "../entities/Insignia"; @@ -40,6 +44,10 @@ import Extension from "../interfaces/extension"; @SuccessResponse(HttpStatus.OK, "สำเร็จ") export class OrganizationDotnetController extends Controller { private orgRootRepo = AppDataSource.getRepository(OrgRoot); + private orgChild1Repo = AppDataSource.getRepository(OrgChild1); + private orgChild2Repo = AppDataSource.getRepository(OrgChild2); + private orgChild3Repo = AppDataSource.getRepository(OrgChild3); + private orgChild4Repo = AppDataSource.getRepository(OrgChild4); private orgRevisionRepo = AppDataSource.getRepository(OrgRevision); private profileRepo = AppDataSource.getRepository(Profile); private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); @@ -4187,6 +4195,115 @@ export class OrganizationDotnetController extends Controller { return new HttpSuccess(profile_); } + /** + * ค้นหาชื่อหน่วยงาน ส่วนราชการ + * + * @summary ค้นหาชื่อหน่วยงาน ส่วนราชการ + * + */ + @Post("find-node-name") + async findNodeName( + @Request() req: RequestWithUser, + @Body() + body: { + node: number; + nodeId: string; + }, + ) { + let findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } + }); + switch (body.node) { + case 0: + let orgRoot = await this.orgRootRepo.findOne({ + where: { + id: body.nodeId, + orgRevisionId: findRevision?.id + } + }); + return new HttpSuccess({ + rootName: orgRoot?.orgRootName ?? null, + child1Name: null, + child2Name: null, + child3Name: null, + child4Name: null, + }); + + case 1: + let orgChild1 = await this.orgChild1Repo.findOne({ + relations: ["orgRoot"], + where: { + id: body.nodeId, + orgRevisionId: findRevision?.id + } + }); + return new HttpSuccess({ + rootName: orgChild1?.orgRoot.orgRootName ?? null, + child1Name: orgChild1?.orgChild1Name ?? null, + child2Name: null, + child3Name: null, + child4Name: null, + }); + + case 2: + let orgChild2 = await this.orgChild2Repo.findOne({ + relations: ["orgRoot", "orgChild1"], + where: { + id: body.nodeId, + orgRevisionId: findRevision?.id + } + }); + return new HttpSuccess({ + rootName: orgChild2?.orgRoot.orgRootName ?? null, + child1Name: orgChild2?.orgChild1.orgChild1Name ?? null, + child2Name: orgChild2?.orgChild2Name ?? null, + child3Name: null, + child4Name: null, + }); + + case 3: + let orgChild3 = await this.orgChild3Repo.findOne({ + relations: ["orgRoot", "orgChild1", "orgChild2"], + where: { + id: body.nodeId, + orgRevisionId: findRevision?.id + } + }); + return new HttpSuccess({ + rootName: orgChild3?.orgRoot.orgRootName ?? null, + child1Name: orgChild3?.orgChild1.orgChild1Name ?? null, + child2Name: orgChild3?.orgChild2.orgChild2Name ?? null, + child3Name: orgChild3?.orgChild3Name ?? null, + child4Name: null, + }); + + case 4: + let orgChild4 = await this.orgChild4Repo.findOne({ + relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3"], + where: { + id: body.nodeId, + orgRevisionId: findRevision?.id + } + }); + return new HttpSuccess({ + rootName: orgChild4?.orgRoot.orgRootName ?? null, + child1Name: orgChild4?.orgChild1.orgChild1Name ?? null, + child2Name: orgChild4?.orgChild2.orgChild2Name ?? null, + child3Name: orgChild4?.orgChild3.orgChild3Name ?? null, + child4Name: orgChild4?.orgChild4Name ?? null, + }); + + default: + return new HttpSuccess({ + rootName: null, + child1Name: null, + child2Name: null, + child3Name: null, + child4Name: null, + });; + } + } + /** * รายชื่อขรก. ตามสิทธิ์ admin *