diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index cf1bb8c..ea9b08c 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -35,47 +35,91 @@ export class ReportController extends Controller { async GetReportAnnouncement( @Body() requestBody: { - root: string; - periodId: string; + type: string; + root?: string | null; + periodId?: string | null; + filters?: string | null; + keyword?: string | null; }, ) { - const getPeriod = await this.kpiPeriodRepository.findOne({ - where: { id: requestBody.periodId }, - }); - if (!getPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่มีรอบการประเมินนี้อยู่ในระบบ"); + let templateName: any; + let reportName: any; + let formattedData: any; + if (requestBody.type == "KPI1") { + templateName = "KPI1"; + reportName = "KPI1"; } - 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: getEvaluations - ? `${evaluation.prefix} ${evaluation.firstName} ${evaluation.lastName}` - : "", - position: getEvaluations ? evaluation.position : "", - posLevel: getEvaluations ? evaluation.posLevelName : "", - result: "ดีเด่น", - })); + if (requestBody.type == "KPI2") { + templateName = "KPI2"; + reportName = "KPI2"; + } + if (requestBody.type == "KPI3") { + templateName = "KPI3"; + reportName = "KPI3"; + } + if (requestBody.type == "KPI4") { + templateName = "KPI4"; + reportName = "KPI4"; + //use_filter + } + if (requestBody.type == "KPI5") { + templateName = "KPI5"; + reportName = "KPI5"; + //use_filter + } + if (requestBody.type == "KPI6") { + templateName = "KPI6"; + reportName = "KPI6"; + //use_filter + } + if (requestBody.type == "KPI7") { + templateName = "KPI7"; + reportName = "KPI7"; + } + if (requestBody.type == "KPI8") { + templateName = "KPI8"; + reportName = "KPI8"; + //use_filter + } + if (requestBody.type == "KPI9") { + templateName = "KPI8"; + reportName = "KPI8"; + } + // if (requestBody.root && requestBody.periodId) { - const formattedData = { - periodId: requestBody.periodId, - authorizedFullName: "นาย สมหมาย นครชัยศรี", - authorizedPosition: "ผู้อำนวยการต้น", - announceYear: Extension.ToThaiNumber(getPeriod.year.toString()), - oc: getRoot ? getRoot.root : "", - organizationName: "กรุงเทพมหานคร", - announceDate: "๑๒ สิงหาคม ๒๕๖๔", - roundNo: "๑ (๒๕๖๔) ", - officer: officer, - }; + // const getEvaluations = await this.kpiUserEvaluationRepository.find({ + // where: { kpiPeriodId: requestBody.periodId }, + // }); + // const getRoot = await this.kpiRoleRepository.findOne({ + // where: { rootId: requestBody.root }, + // }); + // const officer = getEvaluations.map((evaluation) => ({ + // fullName: getEvaluations + // ? `${evaluation.prefix} ${evaluation.firstName} ${evaluation.lastName}` + // : "", + // position: getEvaluations ? evaluation.position : "", + // posLevel: getEvaluations ? evaluation.posLevelName : "", + // result: "ดีเด่น", + // })); + // const formattedData = { + // periodId: requestBody.periodId, + // authorizedFullName: "นาย สมหมาย นครชัยศรี", + // authorizedPosition: "ผู้อำนวยการต้น", + // announceYear: Extension.ToThaiNumber(getPeriod.year.toString()), + // oc: getRoot ? getRoot.root : "", + // organizationName: "กรุงเทพมหานคร", + // announceDate: "๑๒ สิงหาคม ๒๕๖๔", + // roundNo: "๑ (๒๕๖๔) ", + // officer: officer, + // }; + + // } + // if (requestBody.filters && requestBody.keyword) { + // } return new HttpSuccess({ - template: "announce", - reportName: "announce", + template: templateName, + reportName: reportName, data: formattedData, }); }