update report + migrate
This commit is contained in:
parent
29fca33c2e
commit
4dc2f476d2
2 changed files with 32 additions and 6 deletions
|
|
@ -24,7 +24,10 @@ export class ReportController extends Controller {
|
|||
* @param {string} type type ประเภท report
|
||||
*/
|
||||
@Get("main")
|
||||
async GetReportDevelopemtMain(/*@Path() type: string*/) {
|
||||
async GetReportDevelopemtMain(
|
||||
@Query("year") year?: number,
|
||||
@Query("rootId") rootId?: string,
|
||||
) {
|
||||
|
||||
// const _type = type.trim().toUpperCase();
|
||||
const formattedData = {
|
||||
|
|
@ -564,7 +567,7 @@ export class ReportController extends Controller {
|
|||
*/
|
||||
@Get("report3")
|
||||
async report3(
|
||||
@Query("year") year: number,
|
||||
@Query("year") year?: number,
|
||||
@Query("rootId") rootId?: string,
|
||||
) {
|
||||
const developments = await AppDataSource.getRepository(DevelopmentScholarship)
|
||||
|
|
@ -650,7 +653,7 @@ export class ReportController extends Controller {
|
|||
*/
|
||||
@Get("report4")
|
||||
async report4(
|
||||
@Query("year") year: number,
|
||||
@Query("year") year?: number,
|
||||
) {
|
||||
const developments = await AppDataSource.getRepository(DevelopmentScholarship)
|
||||
.createQueryBuilder("developmentScholarship")
|
||||
|
|
@ -797,7 +800,7 @@ export class ReportController extends Controller {
|
|||
*/
|
||||
@Get("report5")
|
||||
async report5(
|
||||
@Query("year") year: number,
|
||||
@Query("year") year?: number,
|
||||
// @Query("rootId") rootId: string,
|
||||
) {
|
||||
|
||||
|
|
@ -861,7 +864,7 @@ export class ReportController extends Controller {
|
|||
template: "reportFund5",
|
||||
reportName: "reportFund5",
|
||||
data: {
|
||||
year: Extension.ToThaiNumber(year.toString()),
|
||||
year: year ? Extension.ToThaiNumber(year.toString()) : "-",
|
||||
data: formattedData,
|
||||
total: Extension.ToThaiNumber(total.toString()),
|
||||
totalBudgetApprove: Extension.ToThaiNumber(totalBudgetApprove.toString()),
|
||||
|
|
@ -876,7 +879,7 @@ export class ReportController extends Controller {
|
|||
*/
|
||||
@Get("report6")
|
||||
async report6(
|
||||
@Query("year") year: number,
|
||||
@Query("year") year?: number,
|
||||
) {
|
||||
const degree = [
|
||||
"ปริญญาเอก",
|
||||
|
|
|
|||
23
src/migration/1739444714910-updateView.ts
Normal file
23
src/migration/1739444714910-updateView.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateView1739444714910 implements MigrationInterface {
|
||||
name = 'UpdateView1739444714910'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId,
|
||||
MAX(\`root\`) AS root,\`degreeLevel\`,
|
||||
COUNT(*) AS numberOfRecords,
|
||||
COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes,
|
||||
SUM(\`budgetApprove\`) AS totalBudgetApprove
|
||||
FROM \`developmentScholarship\`
|
||||
GROUP BY \`rootId\`,\`degreeLevel\`
|
||||
`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue