From 5b8e4cc3ad7d2ba2ae0893b6d4a9149af89a36f5 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 29 Jan 2024 14:14:10 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=A5?= =?UTF-8?q?=E0=B8=B0=E0=B9=80=E0=B8=AD=E0=B8=B5=E0=B8=A2=E0=B8=94=E0=B9=82?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=E0=B8=A3=E0=B8=B0=E0=B8=94=E0=B8=B1=E0=B8=9A=20root,?= =?UTF-8?q?=20=E0=B8=A3=E0=B8=B0=E0=B8=94=E0=B8=B1=E0=B8=9A1-2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrgChild1Controller.ts | 75 +++++++++----------------- src/controllers/OrgChild2Controller.ts | 32 +++++++++++ src/controllers/OrgRootController.ts | 32 +++++++++++ 3 files changed, 90 insertions(+), 49 deletions(-) diff --git a/src/controllers/OrgChild1Controller.ts b/src/controllers/OrgChild1Controller.ts index 6a97aeb6..a3b72bc7 100644 --- a/src/controllers/OrgChild1Controller.ts +++ b/src/controllers/OrgChild1Controller.ts @@ -38,60 +38,37 @@ export class OrgChild1Controller { private child3Repository = AppDataSource.getRepository(OrgChild3); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); - /** - * API รายละเอียดโครงสร้างระดับ1 + * API รายละเอียดโครงสร้างระดับ 1 * * @summary ORG_017 - รายละเอียดโครงสร้างระดับ1 (ADMIN) #17 * - * @param {string} id id โครงสร้างระดับ1 + * @param {string} id Id Child1 */ - // @Get("{id}") - // async Get(@Path() id: string) { - // try { - // const child2s = await this.child2Repository.find({ - // where: { - // orgChild1Id: id, - // }, - // select: ["id", "orgChild2Name", "orgChild2ShortName", "orgChild2Code", "orgChild2Order", "orgRootId"], - // order: { - // orgChild2Order: "ASC", - // }, - // }); - - // const orgRoots = await Promise.all(child2s.map(async (child2) => { - // const orgRoot = await this.orgRootRepository.findOne({ - // where: { - // id: child2.orgRootId, - // }, - // select: ["orgRootCode"], - // }); - - // const orgChild3s = await this.child3Repository.find({ - // where: { - // orgChild2Id: child2.id, - // }, - // select: ["id"], - // }); - - // const orgChild3Ids = orgChild3s.map((orgChild3) => orgChild3.id); - - // return { - // orgChild2Id: child2.id, - // orgChild3Id: orgChild3Ids, - // orgChild2Name: child2.orgChild2Name, - // orgChild2ShortName: child2.orgChild2ShortName, - // orgChild2Code: child2.orgChild2Code, - // orgChild2Order: child2.orgChild2Order, - // orgRootCode: orgRoot?.orgRootCode, - // }; - // })); - - // return new HttpSuccess(orgRoots); - // } catch (error) { - // return error; - // } - // } + @Get("{id}") + async GetChild1(@Path() id: string) { + try { + const orgChild1 = await this.child1Repository.findOne({ where: { id } }); + if (!orgChild1) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + const getOrgChild1 = { + "orgChild1Id" : orgChild1.id, + "orgChild1Name" : orgChild1.orgChild1Name, + "orgChild1ShortName" : orgChild1.orgChild1ShortName, + "orgChild1Code" : orgChild1.orgChild1Code, + "orgChild1Order" : orgChild1.orgChild1Order, + "orgChild1PhoneEx" : orgChild1.orgChild1PhoneEx, + "orgChild1PhoneIn" : orgChild1.orgChild1PhoneIn, + "orgChild1Fax" : orgChild1.orgChild1Fax, + "orgRevisionId" : orgChild1.orgRevisionId, + "orgCode" : orgChild1.orgChild1Code+"00" + } + return new HttpSuccess(getOrgChild1); + } catch (error) { + return error; + } + } /** * API สร้างโครงสร้างระดับ1 diff --git a/src/controllers/OrgChild2Controller.ts b/src/controllers/OrgChild2Controller.ts index a9676790..709c1806 100644 --- a/src/controllers/OrgChild2Controller.ts +++ b/src/controllers/OrgChild2Controller.ts @@ -37,6 +37,38 @@ export class OrgChild2Controller extends Controller { private child3Repository = AppDataSource.getRepository(OrgChild3); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + /** + * API รายละเอียดโครงสร้างระดับ 2 + * + * @summary ORG_018 - รายละเอียดโครงสร้างระดับ2 (ADMIN) #20 + * + * @param {string} id Id Child2 + */ + @Get("{id}") + async GetChild2(@Path() id: string) { + try { + const orgChild2 = await this.child2Repository.findOne({ where: { id } }); + if (!orgChild2) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + const getOrgChild2 = { + "orgChild2Id" : orgChild2.id, + "orgChild2Name" : orgChild2.orgChild2Name, + "orgChild2ShortName" : orgChild2.orgChild2ShortName, + "orgChild2Code" : orgChild2.orgChild2Code, + "orgChild2Order" : orgChild2.orgChild2Order, + "orgChild2PhoneEx" : orgChild2.orgChild2PhoneEx, + "orgChild2PhoneIn" : orgChild2.orgChild2PhoneIn, + "orgChild2Fax" : orgChild2.orgChild2Fax, + "orgRevisionId" : orgChild2.orgRevisionId, + "orgCode" : orgChild2.orgChild2Code+"00" + } + return new HttpSuccess(getOrgChild2); + } catch (error) { + return error; + } + } + /** * สร้างโครงสร้างระดับ2 Child2 * diff --git a/src/controllers/OrgRootController.ts b/src/controllers/OrgRootController.ts index 19687488..700ebad2 100644 --- a/src/controllers/OrgRootController.ts +++ b/src/controllers/OrgRootController.ts @@ -29,6 +29,38 @@ export class OrgRootController extends Controller { private orgChild1Repository = AppDataSource.getRepository(OrgChild1); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + /** + * API รายละเอียดโครงสร้างระดับ Root + * + * @summary ORG_016 - รายละเอียดโครงสร้างระดับ Root (ADMIN) #16 + * + * @param {string} id Id Root + */ + @Get("root/{id}") + async GetRoot(@Path() id: string) { + try { + const orgRoot = await this.orgRootRepository.findOne({ where: { id } }); + if (!orgRoot) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + const getOrgRoot = { + "orgRootId" : orgRoot.id, + "orgRootName" : orgRoot.orgRootName, + "orgRootShortName" : orgRoot.orgRootShortName, + "orgRootCode" : orgRoot.orgRootCode, + "orgRootOrder" : orgRoot.orgRootOrder, + "orgRootPhoneEx" : orgRoot.orgRootPhoneEx, + "orgRootPhoneIn" : orgRoot.orgRootPhoneIn, + "orgRootFax" : orgRoot.orgRootFax, + "orgRevisionId" : orgRoot.orgRevisionId, + "orgCode" : orgRoot.orgRootCode+"00" + } + return new HttpSuccess(getOrgRoot); + } catch (error) { + return error; + } + } + /** * สร้างโครงสร้างระดับ Root *