-
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.
- Loading branch information
Showing
7 changed files
with
53 additions
and
46 deletions.
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 |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import { AsyncParser } from '@json2csv/node'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { IReportService } from 'modules/reports/report-service.interface'; | ||
import { ParserOptions } from '@json2csv/plainjs'; | ||
|
||
// import { AsyncParser } from '@json2csv/node'; | ||
// Above blows because of node module resolution. if updated to node16 or nodenext, other | ||
// dependencies cant be transpiled. We could update some, but i.e class-validator is at its last version | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { AsyncParser } = require('@json2csv/node'); | ||
|
||
@Injectable() | ||
export class CSVReportService { | ||
async generateImportErrorReportStream(errors: any): Promise<string> { | ||
const json2csvOptions: any = { | ||
fields: ['line', 'error'], | ||
}; | ||
const asyncParser: AsyncParser<any, any> = new AsyncParser(json2csvOptions); | ||
return asyncParser.parse(errors).promise(); | ||
export class CSVReportService implements IReportService { | ||
private getParser(parserOptions: ParserOptions): typeof AsyncParser { | ||
return new AsyncParser(parserOptions); | ||
} | ||
|
||
generateReport(data: any, options: ParserOptions): Promise<string> { | ||
return this.getParser(options).parse(data).promise(); | ||
} | ||
} |
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,3 @@ | ||
export interface IReportService { | ||
generateReport(data: any, options: object): Promise<string>; | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { CSVReportService } from 'modules/reports/csv-report.service'; | ||
|
||
export const IReportService: string = 'IReportService'; | ||
export const ReportServiceToken: string = 'IReportService'; | ||
|
||
@Module({ | ||
providers: [{ provide: IReportService, useClass: CSVReportService }], | ||
exports: [IReportService], | ||
providers: [{ provide: ReportServiceToken, useClass: CSVReportService }], | ||
exports: [ReportServiceToken], | ||
}) | ||
export class ReportsModule {} |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { IReportService } from 'modules/reports/report-service.interface'; | ||
import { ReportServiceToken } from 'modules/reports/reports.module'; | ||
|
||
export interface ErrorRecord { | ||
line: number; | ||
error: string; | ||
} | ||
|
||
@Injectable() | ||
export class TaskReportService { | ||
constructor( | ||
@Inject(ReportServiceToken) private reportService: IReportService, | ||
) {} | ||
|
||
async createImportErrorReport(errors: ErrorRecord[]): Promise<string> { | ||
const parserOptions: { fields: ['line', 'error'] } = { | ||
fields: ['line', 'error'], | ||
}; | ||
return this.reportService.generateReport(errors, parserOptions); | ||
} | ||
} |
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