2024-02-06 22:58:49 +01:00
|
|
|
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-02-06 22:58:49 +01:00
|
|
|
const {profile, opt} = ctx;
|
2020-06-11 15:33:45 +02:00
|
|
|
|
|
|
|
// pretend the trip is a leg in a journey
|
|
|
|
const fakeLeg = {
|
|
|
|
type: 'JNY',
|
2021-10-24 16:36:29 +02:00
|
|
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2020-06-11 15:33:45 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
const trip = profile.parseJourneyLeg(ctx, fakeLeg);
|
|
|
|
trip.id = trip.tripId; //TODO journeyId
|
2024-02-06 22:58:49 +01:00
|
|
|
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
|
2024-02-06 22:58:49 +01:00
|
|
|
return trip;
|
|
|
|
};
|
2020-06-11 15:33:45 +02:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
parseTrip,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|