รายการสมรรถนะ "สมรรถนะประจำกลุ่มงาน"

This commit is contained in:
Bright 2024-05-01 13:35:12 +07:00
parent 0b49e363b5
commit 3ce3bed13a

View file

@ -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
*