From d40b7db749c62dcde0dd16c0821f5bf6cb08c96f Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 30 Jan 2024 13:16:40 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB?= =?UTF-8?q?=E0=B8=99=E0=B9=88=E0=B8=87,=20=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B9=80=E0=B8=A0=E0=B8=97,=20=E0=B8=A5=E0=B8=B3=E0=B8=94?= =?UTF-8?q?=E0=B8=B1=E0=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 128 +++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 43b0c9d8..5da09792 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -26,7 +26,9 @@ import { OrgRoot } from "../entities/OrgRoot"; import { OrgChild2 } from "../entities/OrgChild2"; import { OrgChild3 } from "../entities/OrgChild3"; import { OrgChild4 } from "../entities/OrgChild4"; - +import { PosExecutive } from "../entities/PosExecutive"; +import { PosType } from "../entities/PosType"; +import { PosLevel } from "../entities/PosLevel"; @Route("api/v1/org") @Tags("Organization") @Security("bearerAuth") @@ -42,7 +44,9 @@ export class OrganizationController extends Controller { private child2Repository = AppDataSource.getRepository(OrgChild2); private child3Repository = AppDataSource.getRepository(OrgChild3); private child4Repository = AppDataSource.getRepository(OrgChild4); - + private posExecutiveRepository = AppDataSource.getRepository(PosExecutive); + private posTypeRepository = AppDataSource.getRepository(PosType) + private posLevelRepository = AppDataSource.getRepository(PosLevel); /** * API รายการประวัติโครงสร้าง * @@ -540,4 +544,124 @@ export class OrganizationController extends Controller { return error; } } + + /** + * API รายการตำแหน่งทางการบริหาร + * + * @summary ORG_026 - รายการตำแหน่งทางการบริหาร (ADMIN) #28 + * + */ + @Get("pos/executive") + @Example([ + { + id: "00000000-0000-0000-0000-000000000000", + posExecutiveName: "นักบริหาร", + posExecutivePriority: 1 + }, + ]) + async GetPosExecutive() { + try { + const posExecutive = await this.posExecutiveRepository.find({ + select: [ + "id", + "posExecutiveName", + "posExecutivePriority" + ] + }); + if (!posExecutive) { + return new HttpSuccess([]); + } + return new HttpSuccess(posExecutive); + } catch (error) { + return error; + } + } + + /** + * API รายการประเภทตำแหน่ง + * + * @summary ORG_027 - รายการประเภทตำแหน่ง (ADMIN) #29 + * + */ + @Get("pos/type") + @Example([ + { + id: "00000000-0000-0000-0000-000000000000", + posTypeName: "นักบริหาร", + posTypeRank: 1 + }, + ]) + async GetPosType() { + try { + const posType = await this.posTypeRepository.find({ + select: [ + "id", + "posTypeName", + "posTypeRank", + ] + }); + if (!posType) { + return new HttpSuccess([]); + } + return new HttpSuccess(posType); + } catch (error) { + return error; + } + } + + /** + * API รายการระดับตำแหน่ง + * + * @summary ORG_028 - รายการระดับตำแหน่ง (ADMIN) #30 + * + */ + @Get("pos/level") + @Example([ + { + id: "00000000-0000-0000-0000-000000000000", + posLevelName: "นักบริหาร", + posLevelRank: 1, + posLevelAuthority: "HEAD", + posTypes: [ + { + id: "00000000-0000-0000-0000-000000000000", + posTypeName: "นักบริหาร", + posTypeRank: 1 + } + ] + }, + ]) + async GetPosLevel() { + try { + const posLevel = await this.posLevelRepository.find({ + select: [ + "id", + "posLevelName", + "posLevelRank", + "posLevelAuthority", + "posTypeId" + ], + relations: ["posType"], + }); + if (!posLevel) { + return new HttpSuccess([]); + } + const mapPosLevel = posLevel.map(item => ({ + id: item.id, + posLevelName: item.posLevelName, + posLevelRank: item.posLevelRank, + posLevelAuthority: item.posLevelAuthority, + posTypes: [ + { + id: item.posType.id, + posTypeName: item.posType.posTypeName, + posTypeRank: item.posType.posTypeRank, + } + ] + })); + return new HttpSuccess(mapPosLevel); + } catch (error) { + return error; + } + } }