2024-12-07 16:16:31 +00:00
|
|
|
import {parseRemarks} from './remarks.js';
|
2017-11-11 23:56:09 +01:00
|
|
|
|
2024-12-17 19:41:00 +00:00
|
|
|
const parseLocationsFromCtxRecon = (ctx, j) => {
|
|
|
|
return j.ctxRecon
|
|
|
|
.split('$')
|
|
|
|
.map(e => ctx.profile.parseLocation(ctx, {id: e}))
|
|
|
|
.filter(e => e.latitude || e.location?.latitude)
|
|
|
|
.reduce((map, e) => {
|
|
|
|
map[e.id] = e;
|
|
|
|
map[e.name] = e;
|
|
|
|
return map;
|
|
|
|
}, {});
|
|
|
|
};
|
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
const parseJourney = (ctx, j) => { // j = raw journey
|
2024-02-06 22:58:49 +01:00
|
|
|
const {profile, opt} = ctx;
|
2017-12-07 20:21:14 +01:00
|
|
|
|
2024-12-17 19:41:00 +00:00
|
|
|
const fallbackLocations = parseLocationsFromCtxRecon(ctx, j);
|
2024-02-06 22:58:49 +01:00
|
|
|
const legs = [];
|
2024-12-07 16:16:31 +00:00
|
|
|
for (const l of j.verbindungsAbschnitte) {
|
2024-12-17 19:41:00 +00:00
|
|
|
const leg = profile.parseJourneyLeg(ctx, l, null, fallbackLocations);
|
2024-02-06 22:58:49 +01:00
|
|
|
legs.push(leg);
|
2023-12-05 15:01:35 +01:00
|
|
|
}
|
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const res = {
|
|
|
|
type: 'journey',
|
|
|
|
legs,
|
2024-12-07 16:16:31 +00:00
|
|
|
refreshToken: j.ctxRecon || null,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2018-12-02 01:05:19 +01:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
// TODO freq
|
2018-06-11 11:29:32 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
if (opt.remarks) {
|
|
|
|
res.remarks = parseRemarks(ctx, j);
|
2019-10-20 00:19:11 +02:00
|
|
|
}
|
2018-07-23 20:42:22 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
// TODO
|
|
|
|
if (opt.scheduledDays && j.serviceDays) {
|
2022-11-16 15:18:12 +01:00
|
|
|
// todo [breaking]: rename to scheduledDates
|
2024-12-08 21:42:57 +00:00
|
|
|
// res.scheduledDays = profile.parseScheduledDays(ctx, j.serviceDays);
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2024-12-21 15:26:49 +00:00
|
|
|
res.price = profile.parsePrice(ctx, j);
|
|
|
|
const tickets = profile.parseTickets(ctx, j);
|
|
|
|
if (tickets) {
|
|
|
|
res.tickets = tickets;
|
|
|
|
}
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
return res;
|
|
|
|
};
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
parseJourney,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|