From 1f0a39adc616df283e451c967bb3221e46d07652 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 16 Apr 2024 21:31:09 +0100 Subject: [PATCH] Fix bug where cancelled service is not processed and sent to client due to no stops arrray being present. Signed-off-by: Fred Boniface --- src/services/trainService.services.ts | 1 + .../processors/timetable/timetableProcessor.utils.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/services/trainService.services.ts b/src/services/trainService.services.ts index d2b2df2..46d2e2e 100644 --- a/src/services/trainService.services.ts +++ b/src/services/trainService.services.ts @@ -38,6 +38,7 @@ export async function findByHeadcode( scheduleEndDate: { $gte: searchDate }, daysRun: { $in: [shortDay] }, }; + console.log(JSON.stringify(query)) const pipeline = getFindByHeadcodePipeline(query); const result: SimpleService[] = (await queryAggregate( diff --git a/src/utils/processors/timetable/timetableProcessor.utils.ts b/src/utils/processors/timetable/timetableProcessor.utils.ts index a75e1c5..849056c 100644 --- a/src/utils/processors/timetable/timetableProcessor.utils.ts +++ b/src/utils/processors/timetable/timetableProcessor.utils.ts @@ -36,6 +36,14 @@ export function formatTimetableDetail( } function formatStops(stops: Stop[]): OB_TrainTT_stopDetail[] { + if (!stops) { + return [] + } + + if (!stops.length) { + return [] + } + // Cleanly coerce Stop[] to OB_TrainTT_stopDetail[] const formattedStops: OB_TrainTT_stopDetail[] = [];