ctucx.git: oeffi-web

[nimlang] oeffisearch fork that works without javascript

commit 845a82d8d661e26d188f7a420de04e538323ae92
parent c8221c43a9c4ec00544ea7b03549f290bce7c0cf
Author: Leah (ctucx) <leah@ctu.cx>
Date: Fri, 22 Jan 2021 11:11:40 +0100

journeyView: check if distance is a none
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/formaters/renderJourney.nim b/src/formaters/renderJourney.nim
@@ -52,10 +52,17 @@ proc renderJourney*(data: CacheObject, id: string): JsonNode =
         })
 
     elif leg.isTransfer != false:
+      var distance: int
+
+      if not leg.distance.isNone:
+        distance = leg.distance.get
+      else:
+        distance = 0
+
       result["LEGS"].add(%* {
           "IS_TRANSFER":   true,
           "ARRIVAL_POINT": formatPoint(leg.arrival.point),
-          "DISTANCE":      leg.distance.get
+          "DISTANCE":      distance
         })
 
     else:

@@ -78,10 +85,6 @@ proc renderJourney*(data: CacheObject, id: string): JsonNode =
             "IS_CHANGE": true,
             "DURATION":  formatDuration(departureTime - lastArrivalTime)
           })
-
-      legDuration = arrivalTime - departureTime
-
-      lastArrival = leg.arrival
       
       if leg.line.get.product == nationalExp or leg.line.get.product == national or leg.line.get.product == regionalExp or leg.line.get.product == regional:
         hasMarudorUrl = true

@@ -189,6 +192,8 @@ proc renderJourney*(data: CacheObject, id: string): JsonNode =
               "PLATFORM_HAS_CHANGED": platformHasChanged
             })
 
+      legDuration = arrivalTime - departureTime
+      lastArrival = leg.arrival
       inc(changes)
 
       result["LEGS"].add(%* {