hrms-api-kpi/src/controllers/ReportController.ts

83 lines
2.7 KiB
TypeScript
Raw Normal View History

2024-06-13 11:34:25 +07:00
import {
Controller,
Get,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { Brackets, Not } from "typeorm";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
2024-06-14 11:01:34 +07:00
import { KpiPeriod } from "../entities/kpiPeriod";
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
import { off } from "process";
import Extension from "../interfaces/extension";
2024-06-14 15:33:35 +07:00
import { KpiRole } from "../entities/kpiRole";
2024-06-13 11:34:25 +07:00
@Route("api/v1/kpi/report")
@Tags("Report")
@Security("bearerAuth")
export class ReportController extends Controller {
2024-06-14 11:01:34 +07:00
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
2024-06-14 15:33:35 +07:00
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
@Post("announcement")
2024-06-14 11:01:34 +07:00
async GetReportAnnouncement(
@Body()
2024-06-14 15:33:35 +07:00
requestBody: {
root: string;
periodId: string;
},
2024-06-14 11:01:34 +07:00
) {
const getPeriod = await this.kpiPeriodRepository.findOne({
2024-06-14 15:33:35 +07:00
where: { id: requestBody.periodId },
2024-06-14 11:01:34 +07:00
});
if (!getPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่มีรอบการประเมินนี้อยู่ในระบบ");
2024-06-14 11:01:34 +07:00
}
2024-06-14 15:33:35 +07:00
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) => ({
2024-06-14 15:33:35 +07:00
fullName: getEvaluations
? `${evaluation.prefix} ${evaluation.firstName} ${evaluation.lastName}`
: "",
position: getEvaluations ? evaluation.position : "",
posLevel: getEvaluations ? evaluation.posLevelName : "",
2024-06-14 11:01:34 +07:00
result: "ดีเด่น",
}));
const formattedData = {
periodId: requestBody.periodId,
authorizedFullName: "นาย สมหมาย นครชัยศรี",
2024-06-14 15:33:35 +07:00
authorizedPosition: "ผู้อำนวยการต้น",
announceYear: Extension.ToThaiNumber(getPeriod.year.toString()),
2024-06-14 15:33:35 +07:00
oc: getRoot ? getRoot.root : "",
organizationName: "กรุงเทพมหานคร",
announceDate: "๑๒ สิงหาคม ๒๕๖๔",
roundNo: "๑ (๒๕๖๔) ",
officer: officer,
};
2024-06-13 11:34:25 +07:00
return new HttpSuccess({
template: "announce",
reportName: "announce",
data: formattedData,
});
}
}