From dd7c8ea67093298e21dc2d3ef4cd302ad8925bbb Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 27 Jun 2024 18:14:43 +0700 Subject: [PATCH] fix api --- src/controllers/ReportController.ts | 33 ++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 4e3e588..49cf9fc 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -22,6 +22,7 @@ import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; import { off } from "process"; import Extension from "../interfaces/extension"; import { KpiRole } from "../entities/kpiRole"; +import { KpiPlan } from "../entities/kpiPlan"; @Route("api/v1/kpi/report") @Tags("Report") @@ -30,6 +31,7 @@ export class ReportController extends Controller { private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod); private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation); private kpiRoleRepository = AppDataSource.getRepository(KpiRole); + private kpiPlanRepository = AppDataSource.getRepository(KpiPlan); @Post("announcement") async GetReportAnnouncement( @@ -135,15 +137,40 @@ export class ReportController extends Controller { @Post("kpi9/{periodId}") async GetReportKpi9( - @Path() periodId?: string | null, + @Path() profileId?: string | null, ) { - + let formattedData: any; + if (profileId) { + const kpiUserEvaluation = await this.kpiUserEvaluationRepository.findOne({ + relations: ["kpiUserRoles", "kpiUserPlanneds", "kpiUserSpecials", "kpiUserCapacitys"], + where: { profileId: profileId }, + }); + if (!kpiUserEvaluation) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ประเมิน"); + //period + const period = await this.kpiPeriodRepository.findOneBy({ + id: kpiUserEvaluation?.kpiPeriodId, + }); + if (!period) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงวดการประเมิน"); + + const kpiRole = await this.kpiRoleRepository.find({ + where: { kpiPeriodId: period?.id }, + }); + + const kpiPlan = await this.kpiPlanRepository.find({ + where: { kpiPeriodId: period?.id }, + }); + + formattedData = { + + }; + } return new HttpSuccess({ template: "KPI9", reportName: "KPI9", - data: {}, + data: formattedData, }); } }