From d0c2fb3a63e49c81772119385322b2b4f026c615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Tue, 11 May 2021 18:20:47 +0200 Subject: [PATCH] Automatically append last stop if missing --- src/tam/courses.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/tam/courses.js b/src/tam/courses.js index e64a280..510bd2f 100644 --- a/src/tam/courses.js +++ b/src/tam/courses.js @@ -1,5 +1,10 @@ -const path = require("path"); -const fs = require("fs").promises; +/** + * @fileoverview + * + * Fetch and aggregate information about vehicles in transit on the TaM network + * from the official endpoints. + */ + const tam = require("./sources/tam"); const network = require("./network.json"); @@ -112,8 +117,12 @@ const fetch = async (kind = 'realtime') => { ) ); + const lastPassing = course.passings[course.passings.length - 1]; + if (course.finalStopId === undefined) { - course.finalStopId = course.passings[course.passings.length - 1][0]; + course.finalStopId = lastPassing[0]; + } else if (course.finalStopId !== lastPassing[0]) { + course.passings.push([course.finalStopId, lastPassing[1] + 30000]); } }