From 3ce3bed13a972bd23650db1c0e6292a72f1fcad5 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 1 May 2024 13:35:12 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=AA=E0=B8=A1=E0=B8=A3=E0=B8=A3=E0=B8=96=E0=B8=99?= =?UTF-8?q?=E0=B8=B0=20"=E0=B8=AA=E0=B8=A1=E0=B8=A3=E0=B8=A3=E0=B8=96?= =?UTF-8?q?=E0=B8=99=E0=B8=B0=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3?= =?UTF-8?q?=E0=B8=81=E0=B8=A5=E0=B8=B8=E0=B9=88=E0=B8=A1=E0=B8=87=E0=B8=B2?= =?UTF-8?q?=E0=B8=99"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiCapacityController.ts | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/controllers/KpiCapacityController.ts b/src/controllers/KpiCapacityController.ts index 0db5792..d6629f1 100644 --- a/src/controllers/KpiCapacityController.ts +++ b/src/controllers/KpiCapacityController.ts @@ -21,6 +21,7 @@ import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { KpiCapacity, createKpiCapacity, updateKpiCapacity } from "../entities/kpiCapacity"; +import { Position } from "../entities/position"; import { KpiCapacityDetail, createKpiCapacityDetail, @@ -39,6 +40,7 @@ import { Like, In } from "typeorm"; export class kpiCapacityController extends Controller { private kpiCapacityRepository = AppDataSource.getRepository(KpiCapacity); private kpiCapacityDetailRepository = AppDataSource.getRepository(KpiCapacityDetail); + private positionRepository = AppDataSource.getRepository(Position); /** * API สร้างรายการสมรรถนะ @@ -203,6 +205,48 @@ export class kpiCapacityController extends Controller { return new HttpSuccess(mapData); } + /** + * API รายละเอียดรายการสมรรถนะ "สมรรถนะประจำกลุ่มงาน" + * + * @summary รายละเอียดดรายการสมรรถนะ "สมรรถนะประจำกลุ่มงาน" + * + */ + @Get("group") + async GetKpiCapacityTypeGROUP( + @Query("positionName") positionName: string + ) { + + const position = await this.positionRepository.findOne({ + where: { name: Like(`%${positionName}%`) }, + relations: ["kpiLink.kpiCapacitys"] + }) + if(position == null){ + throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลตำแหน่งนี้: ${positionName}`); + } + + let positionLinkId: any + positionLinkId = position != null ? position : null + const kpiCapacityIds = positionLinkId.kpiLink.kpiCapacitys.map((kpiCapacity:any) => kpiCapacity.id) + + const kpiCapacity = await this.kpiCapacityRepository.find({ + where: { + id: In(kpiCapacityIds), + type: In(["GROUP"]), + kpiCapacityDetails: { level: "2" } + }, + select: ["id", "name"], + relations: ["kpiCapacityDetails",], + }); + + const mapData = kpiCapacity.map((x) => ({ + id: x.id, + name: x.name, + level: x.kpiCapacityDetails.length > 0 ? x.kpiCapacityDetails[0].level : null, + description: x.kpiCapacityDetails.length > 0 ? x.kpiCapacityDetails[0].description : null, + })); + return new HttpSuccess(mapData); + } + /** * API รายละเอียดรายการสมรรถนะ *