Skip to content

Commit

Permalink
Add impact report service and controller scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Dec 19, 2023
1 parent 1ef8f2c commit 0e923f1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
44 changes: 44 additions & 0 deletions api/src/modules/impact/impact-report.controller.ts
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);
}
}
7 changes: 6 additions & 1 deletion api/src/modules/impact/impact.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { AuthorizationModule } from 'modules/authorization/authorization.module'
import { ImpactViewUpdater } from 'modules/impact/views/impact-view.updater';
import { BaseImpactService } from 'modules/impact/base-impact.service';
import { ImpactRepository } from 'modules/impact/impact.repository';
import { ImpactReportController } from 'modules/impact/impact-report.controller';
import { ImpactReportService } from 'modules/impact/impact.report';
import { ReportsModule } from 'modules/reports/reports.module';

@Module({
imports: [
Expand All @@ -26,6 +29,7 @@ import { ImpactRepository } from 'modules/impact/impact.repository';
MaterialsModule,
SourcingLocationsModule,
AuthorizationModule,
ReportsModule,
],
providers: [
ImpactRepository,
Expand All @@ -35,8 +39,9 @@ import { ImpactRepository } from 'modules/impact/impact.repository';
ScenarioVsScenarioImpactService,
MaterialsService,
ImpactViewUpdater,
ImpactReportService,
],
controllers: [ImpactController],
controllers: [ImpactController, ImpactReportController],
exports: [
ImpactService,
ActualVsScenarioImpactService,
Expand Down
17 changes: 17 additions & 0 deletions api/src/modules/impact/impact.report.ts
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, {});
}
}

0 comments on commit 0e923f1

Please sign in to comment.