Skip to content

Commit

Permalink
Add check for undefined fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignas-rgb committed Feb 13, 2024
1 parent be8a918 commit 2009b75
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ export class ReportService {

private static docToReportStatistics(e: any): ReportStatisticsDto {
return new ReportStatisticsDto(
e.filter((stat: { _id: string }) => stat._id == 'gautas')[0].count ?? 0,
e.filter((stat: { _id: string }) => stat._id == 'tiriamas')[0].count ?? 0,
e.filter((stat: { _id: string }) => stat._id == 'ištirtas')[0].count ?? 0,
e.filter((stat: { _id: string }) => stat._id == 'sutvarkyta')[0].count ??
0,
e.filter((stat: { _id: string }) => stat._id == 'nepasitvirtino')[0]
.count ?? 0,
ReportService.filterStatistics(e, 'gautas'),
ReportService.filterStatistics(e, 'tiriamas'),
ReportService.filterStatistics(e, 'ištirtas'),
ReportService.filterStatistics(e, 'sutvarkyta'),
ReportService.filterStatistics(e, 'nepasitvirtino'),
);
}

private static filterStatistics(e: any, status: string): number {
return e.filter((stat: { _id: string }) => stat._id == status).length > 0
? e.filter((stat: { _id: string }) => stat._id == status)[0].count ?? 0
: 0;
}

private static docToPublicReport(e: Report): PublicReportDto {
return new PublicReportDto(
e.name,
Expand Down

0 comments on commit 2009b75

Please sign in to comment.