-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add impact report service and controller scaffold
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Query, | ||
UseInterceptors, | ||
ValidationPipe, | ||
} from '@nestjs/common'; | ||
import { ImpactService } from 'modules/impact/impact.service'; | ||
import { ActualVsScenarioImpactService } from 'modules/impact/comparison/actual-vs-scenario.service'; | ||
import { ScenarioVsScenarioImpactService } from 'modules/impact/comparison/scenario-vs-scenario.service'; | ||
import { ApiOkResponse, ApiOperation } from '@nestjs/swagger'; | ||
import { | ||
ImpactTable, | ||
PaginatedImpactTable, | ||
} from './dto/response-impact-table.dto'; | ||
import { JSONAPIPaginationQueryParams } from '../../decorators/json-api-parameters.decorator'; | ||
import { SetScenarioIdsInterceptor } from './set-scenario-ids.interceptor'; | ||
import { GetImpactTableDto } from './dto/impact-table.dto'; | ||
import { ImpactReportService } from './impact.report'; | ||
|
||
@Controller('/api/v1/impact') | ||
export class ImpactReportController { | ||
constructor( | ||
private readonly impactService: ImpactService, | ||
private readonly impactReports: ImpactReportService, | ||
private readonly actualVsScenarioImpactService: ActualVsScenarioImpactService, | ||
private readonly scenarioVsScenarioService: ScenarioVsScenarioImpactService, | ||
) {} | ||
|
||
@ApiOperation({ | ||
description: 'Get a Impact Table CSV Report', | ||
}) | ||
@JSONAPIPaginationQueryParams() | ||
@UseInterceptors(SetScenarioIdsInterceptor) | ||
@Get('table/report') | ||
async getImpactTable( | ||
@Query(ValidationPipe) impactTableDto: GetImpactTableDto, | ||
): Promise<string> { | ||
const table: any = await this.impactService.getImpactTable(impactTableDto, { | ||
disablePagination: true, | ||
}); | ||
return this.impactReports.generateImpactReport(table); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { IReportService } from 'modules/reports/report-service.interface'; | ||
import { ReportServiceToken } from 'modules/reports/reports.module'; | ||
|
||
@Injectable() | ||
export class ImpactReportService { | ||
constructor( | ||
@Inject(ReportServiceToken) private reportService: IReportService, | ||
) {} | ||
|
||
async generateImpactReport(data: any): Promise<string> { | ||
const parserOptions: { fields: ['line', 'error'] } = { | ||
fields: ['line', 'error'], | ||
}; | ||
return this.reportService.generateReport(data, {}); | ||
} | ||
} |