2020-06-11 15:33:45 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const minBy = require('lodash/minBy')
|
|
|
|
const maxBy = require('lodash/maxBy')
|
2020-09-16 16:46:22 +02:00
|
|
|
const last = require('lodash/last')
|
2020-06-11 15:33:45 +02:00
|
|
|
|
|
|
|
const parseTrip = (ctx, t) => { // t = raw trip
|
|
|
|
const {profile} = ctx
|
|
|
|
|
|
|
|
// pretend the trip is a leg in a journey
|
|
|
|
const fakeLeg = {
|
|
|
|
type: 'JNY',
|
2020-09-16 16:46:22 +02:00
|
|
|
dep: minBy(t.stopL, 'idx') || t.stopL[0],
|
|
|
|
arr: maxBy(t.stopL, 'idx') || last(t.stopL),
|
2020-06-11 15:33:45 +02:00
|
|
|
jny: t,
|
|
|
|
}
|
|
|
|
const trip = profile.parseJourneyLeg(ctx, fakeLeg, t.date)
|
|
|
|
|
|
|
|
trip.id = trip.tripId
|
|
|
|
delete trip.tripId
|
|
|
|
|
|
|
|
return trip
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = parseTrip
|