mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
31 lines
648 B
JavaScript
31 lines
648 B
JavaScript
import minBy from 'lodash/minBy.js';
|
|
import maxBy from 'lodash/maxBy.js';
|
|
import last from 'lodash/last.js';
|
|
|
|
const parseTrip = (ctx, t) => { // t = raw trip
|
|
const {profile} = ctx;
|
|
|
|
// pretend the trip is a leg in a journey
|
|
const fakeLeg = {
|
|
type: 'JNY',
|
|
dep: Array.isArray(t.stopL)
|
|
? minBy(t.stopL, 'idx') || t.stopL[0]
|
|
: {},
|
|
arr: Array.isArray(t.stopL)
|
|
? maxBy(t.stopL, 'idx') || last(t.stopL)
|
|
: {},
|
|
jny: t,
|
|
};
|
|
|
|
const trip = profile.parseJourneyLeg(ctx, fakeLeg);
|
|
trip.id = trip.tripId; // TODO journeyId
|
|
delete trip.tripId;
|
|
delete trip.reachable;
|
|
|
|
// TODO opt.scheduledDays
|
|
return trip;
|
|
};
|
|
|
|
export {
|
|
parseTrip,
|
|
};
|