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";
|
2024-06-14 14:15:30 +07:00
|
|
|
import { off } from "process";
|
|
|
|
|
import Extension from "../interfaces/extension";
|
|
|
|
|
|
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);
|
|
|
|
|
@Post("announcement/{id}")
|
|
|
|
|
async GetReportAnnouncement(
|
|
|
|
|
@Path() id: string,
|
|
|
|
|
@Body()
|
|
|
|
|
requestBody: { root: string; periodId: string },
|
|
|
|
|
) {
|
|
|
|
|
const getEvaluations = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
where: { kpiPeriodId: id },
|
|
|
|
|
});
|
|
|
|
|
const getPeriod = await this.kpiPeriodRepository.findOne({
|
|
|
|
|
where: { id: id },
|
|
|
|
|
});
|
|
|
|
|
if (!getPeriod) {
|
2024-06-14 14:15:30 +07:00
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่มีรอบการประเมินนี้อยู่ในระบบ");
|
2024-06-14 11:01:34 +07:00
|
|
|
}
|
2024-06-14 14:15:30 +07:00
|
|
|
const officer = getEvaluations.map((evaluation) => ({
|
2024-06-14 11:01:34 +07:00
|
|
|
fullName: `${evaluation.prefix} ${evaluation.firstName} ${evaluation.lastName}`,
|
|
|
|
|
position: evaluation.position,
|
|
|
|
|
posLevel: evaluation.posLevelName,
|
|
|
|
|
result: "ดีเด่น",
|
2024-06-14 14:15:30 +07:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const formattedData = {
|
|
|
|
|
periodId: requestBody.periodId,
|
|
|
|
|
root: requestBody.root,
|
|
|
|
|
authorizedFullName: "นาย สมหมาย นครชัยศรี",
|
|
|
|
|
authorizedPosition: "เจ้าหน้าที่พิเศษ",
|
|
|
|
|
announceYear: Extension.ToThaiNumber(getPeriod.year.toString()),
|
2024-06-14 11:01:34 +07:00
|
|
|
oc: "test",
|
|
|
|
|
organizationName: "test",
|
2024-06-14 14:15:30 +07:00
|
|
|
announceDate: "๑๒ สิงหาคม ๒๕๖๔",
|
|
|
|
|
roundNo: "๑ (๒๕๖๔) ",
|
|
|
|
|
officer: officer,
|
|
|
|
|
};
|
2024-06-13 11:34:25 +07:00
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
|
|
|
|
template: "announce",
|
|
|
|
|
reportName: "announce",
|
|
|
|
|
data: formattedData,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|