db-vendo-client/parse/trip.js

26 lines
528 B
JavaScript
Raw Normal View History

2020-06-11 15:33:45 +02:00
'use strict'
const minBy = require('lodash/minBy')
const maxBy = require('lodash/maxBy')
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',
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