db-vendo-client/parse/trip.js
2024-12-07 16:17:16 +00:00

31 lines
652 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, opt} = 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,
};