From d04d6048895c31349a7a27b979173f85ab372b97 Mon Sep 17 00:00:00 2001 From: Alex McBean Date: Sun, 30 Jan 2022 17:09:24 +0000 Subject: [PATCH] Minor bug fixes - 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 --- src/coRoute/coroute.service.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/coRoute/coroute.service.ts b/src/coRoute/coroute.service.ts index 48978339..97d49c93 100644 --- a/src/coRoute/coroute.service.ts +++ b/src/coRoute/coroute.service.ts @@ -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; } }