db-vendo-client/parse/trip.js

32 lines
648 B
JavaScript
Raw Normal View History

import minBy from 'lodash/minBy.js';
import maxBy from 'lodash/maxBy.js';
import last from 'lodash/last.js';
2020-06-11 15:33:45 +02:00
const parseTrip = (ctx, t) => { // t = raw trip
2024-12-08 21:42:57 +00:00
const {profile} = ctx;
2020-06-11 15:33:45 +02:00
// 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)
: {},
2020-06-11 15:33:45 +02:00
jny: t,
};
2020-06-11 15:33:45 +02:00
2024-12-07 16:16:31 +00:00
const trip = profile.parseJourneyLeg(ctx, fakeLeg);
2024-12-08 21:42:57 +00:00
trip.id = trip.tripId; // TODO journeyId
delete trip.tripId;
delete trip.reachable;
2020-06-11 15:33:45 +02:00
2024-12-07 16:16:31 +00:00
// TODO opt.scheduledDays
return trip;
};
2020-06-11 15:33:45 +02:00
2022-05-07 16:17:37 +02:00
export {
parseTrip,
};