From 6e374d7992a61f76b36c76a20fbcbb3e32cb0f2e Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Feb 2025 10:28:05 +0700 Subject: [PATCH] report 3 (test) --- src/controllers/ReportController.ts | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 26a76b1..deb87af 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Route, Security, Tags, Body, Path } from "tsoa"; +import { Controller, Get, Post, Route, Security, Tags, Body, Path, Query } from "tsoa"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; @@ -563,14 +563,38 @@ export class ReportController extends Controller { * */ @Get("report3") - async report3() { - + async report3( + @Query("year") year: number, + @Query("rootId") rootId?: string, + ) { + const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) + .createQueryBuilder("developmentScholarship") + .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") + .leftJoinAndSelect("developmentScholarship.posType", "posType") + .andWhere( + year !== 0 && year != null && year != undefined + ? "developmentScholarship.scholarshipYear = :scholarshipYear" + : "1=1", + { scholarshipYear: year }, + ) + .andWhere( + rootId != "" && rootId != null && rootId != undefined + ? "developmentScholarship.rootId = :rootId" + : "1=1", + { rootId: rootId }, + ) + .orderBy("developmentScholarship.scholarshipYear", "DESC") + .addOrderBy("developmentScholarship.createdAt", "DESC") + .getManyAndCount(); return new HttpSuccess({ template: "reportFund3", reportName: "reportFund3", data: { - data: "", + year: year ? Extension.ToThaiNumber(year.toString()) : "-", + root: null, + developments: development, + total: total }, }); }