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 หาสำนักทั้งหมด *