parseTrip: handle stopL[] items without idx 🐛

This commit is contained in:
Jannis R 2020-09-16 16:46:22 +02:00 committed by Jannis Redmann
parent 11ca3b171a
commit 92fb29d687

View file

@ -2,6 +2,7 @@
const minBy = require('lodash/minBy') const minBy = require('lodash/minBy')
const maxBy = require('lodash/maxBy') const maxBy = require('lodash/maxBy')
const last = require('lodash/last')
const parseTrip = (ctx, t) => { // t = raw trip const parseTrip = (ctx, t) => { // t = raw trip
const {profile} = ctx const {profile} = ctx
@ -9,8 +10,8 @@ const parseTrip = (ctx, t) => { // t = raw trip
// pretend the trip is a leg in a journey // pretend the trip is a leg in a journey
const fakeLeg = { const fakeLeg = {
type: 'JNY', type: 'JNY',
dep: minBy(t.stopL, 'idx'), dep: minBy(t.stopL, 'idx') || t.stopL[0],
arr: maxBy(t.stopL, 'idx'), arr: maxBy(t.stopL, 'idx') || last(t.stopL),
jny: t, jny: t,
} }
const trip = profile.parseJourneyLeg(ctx, fakeLeg, t.date) const trip = profile.parseJourneyLeg(ctx, fakeLeg, t.date)