Update ReportController.ts
This commit is contained in:
parent
af92abf24a
commit
830a6ab307
1 changed files with 37 additions and 8 deletions
|
|
@ -17,18 +17,47 @@ import { Brackets, Not } from "typeorm";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
import { KpiPeriod } from "../entities/kpiPeriod";
|
||||||
|
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||||
@Route("api/v1/kpi/report")
|
@Route("api/v1/kpi/report")
|
||||||
@Tags("Report")
|
@Tags("Report")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
export class ReportController extends Controller {
|
export class ReportController extends Controller {
|
||||||
// private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship);
|
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
||||||
|
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
|
||||||
@Get("announcement/{id}")
|
@Post("announcement/{id}")
|
||||||
async GetReportAnnouncement(@Path() id: string) {
|
async GetReportAnnouncement(
|
||||||
const formattedData = {
|
@Path() id: string,
|
||||||
periodId: "",
|
@Body()
|
||||||
root: "",
|
requestBody: { root: string; periodId: string },
|
||||||
};
|
) {
|
||||||
|
const getEvaluations = await this.kpiUserEvaluationRepository.find({
|
||||||
|
where: { kpiPeriodId: id },
|
||||||
|
});
|
||||||
|
const getPeriod = await this.kpiPeriodRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
});
|
||||||
|
if (!getEvaluations || getEvaluations.length === 0) {
|
||||||
|
console.log("No evaluations found for the given kpiPeriodId: ", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getPeriod) {
|
||||||
|
console.log("No period data found for the given id: ", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const formattedData = getEvaluations.map((evaluation) => ({
|
||||||
|
periodId: requestBody.periodId,
|
||||||
|
root: requestBody.root,
|
||||||
|
fullName: `${evaluation.prefix} ${evaluation.firstName} ${evaluation.lastName}`,
|
||||||
|
position: evaluation.position,
|
||||||
|
posLevel: evaluation.posLevelName,
|
||||||
|
announceYear: getPeriod.year,
|
||||||
|
result: "ดีเด่น",
|
||||||
|
oc: "test",
|
||||||
|
organizationName: "test",
|
||||||
|
announceDate: "testDATE",
|
||||||
|
roundNo: "1",
|
||||||
|
}));
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
template: "announce",
|
template: "announce",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue