From fd3e4726583158573e00b667f8b995d39e130480 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Fri, 14 Jun 2024 15:33:35 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=20report?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 38 ++++++++++++++++++----------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 2f47d78..cf1bb8c 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -21,6 +21,7 @@ import { KpiPeriod } from "../entities/kpiPeriod"; import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; import { off } from "process"; import Extension from "../interfaces/extension"; +import { KpiRole } from "../entities/kpiRole"; @Route("api/v1/kpi/report") @Tags("Report") @@ -28,36 +29,45 @@ import Extension from "../interfaces/extension"; export class ReportController extends Controller { private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod); private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation); - @Post("announcement/{id}") + private kpiRoleRepository = AppDataSource.getRepository(KpiRole); + + @Post("announcement") async GetReportAnnouncement( - @Path() id: string, @Body() - requestBody: { root: string; periodId: string }, + requestBody: { + root: string; + periodId: string; + }, ) { - const getEvaluations = await this.kpiUserEvaluationRepository.find({ - where: { kpiPeriodId: id }, - }); const getPeriod = await this.kpiPeriodRepository.findOne({ - where: { id: id }, + where: { id: requestBody.periodId }, }); if (!getPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่มีรอบการประเมินนี้อยู่ในระบบ"); } + const getEvaluations = await this.kpiUserEvaluationRepository.find({ + where: { kpiPeriodId: requestBody.periodId }, + }); + const getRoot = await this.kpiRoleRepository.findOne({ + where: { rootId: requestBody.root }, + }); + console.log("============Result========", getRoot?.root); const officer = getEvaluations.map((evaluation) => ({ - fullName: `${evaluation.prefix} ${evaluation.firstName} ${evaluation.lastName}`, - position: evaluation.position, - posLevel: evaluation.posLevelName, + fullName: getEvaluations + ? `${evaluation.prefix} ${evaluation.firstName} ${evaluation.lastName}` + : "", + position: getEvaluations ? evaluation.position : "", + posLevel: getEvaluations ? evaluation.posLevelName : "", result: "ดีเด่น", })); const formattedData = { periodId: requestBody.periodId, - root: requestBody.root, authorizedFullName: "นาย สมหมาย นครชัยศรี", - authorizedPosition: "เจ้าหน้าที่พิเศษ", + authorizedPosition: "ผู้อำนวยการต้น", announceYear: Extension.ToThaiNumber(getPeriod.year.toString()), - oc: "test", - organizationName: "test", + oc: getRoot ? getRoot.root : "", + organizationName: "กรุงเทพมหานคร", announceDate: "๑๒ สิงหาคม ๒๕๖๔", roundNo: "๑ (๒๕๖๔) ", officer: officer,