Skip to content

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
- coroutes skipped now just log the filename rather than the entire DTO
- refactored filtering loop
- fixed bug where origin match but no match with destination
  • Loading branch information
Lucky38i committed Jan 30, 2022
1 parent 51416d1 commit d04d604
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/coRoute/coroute.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,16 @@ export class CoRouteService {
fileBuffers.fileNames[index],
));

const validatedCoRoutes: CoRouteDto[] = [];
coRoutes.forEach((coRoute) => this.coRouteConverter.validateCoRoute(coRoute)
.then(() => {
if (coRoute.origin.icao_code === originIcao && coRoute.destination.icao_code) {
validatedCoRoutes.push(coRoute);
} else {
this.logger.debug(`coRoute didn't match req params, skipping: ${JSON.stringify(coRoute)}`);
}
})
// Should we print the entire coroute ?
.catch(() => this.logger.warn(`coRoute failed validation: ${JSON.stringify(coRoute)}`)));

return validatedCoRoutes;
return coRoutes.filter((coRoute) => this.coRouteConverter.validateCoRoute(coRoute)
.then(() => this.filterInvalidCoRoute(coRoute, originIcao, destinationIcao))
.catch(() => this.logger.warn(`coRoute failed validation: ${JSON.stringify(coRoute.name)}`)));
}

private filterInvalidCoRoute(coRoute: CoRouteDto, originIcao: String, destinationIcao: String) {
if (coRoute.origin.icao_code === originIcao && coRoute.destination.icao_code === destinationIcao) {
return true;
}
this.logger.debug(`coRoute didn't match req params, skipping: ${coRoute.name}}`);
return false;
}
}

0 comments on commit d04d604

Please sign in to comment.