db-vendo-client/parse/journey.js

55 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-12-07 16:16:31 +00:00
import {parseRemarks} from './remarks.js';
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
const {profile, opt} = ctx;
2024-12-17 19:41:00 +00:00
const fallbackLocations = parseLocationsFromCtxRecon(ctx, j);
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);
legs.push(leg);
}
const res = {
type: 'journey',
legs,
2024-12-07 16:16:31 +00:00
refreshToken: j.ctxRecon || null,
};
2018-12-02 01:05:19 +01:00
2024-12-07 16:16:31 +00:00
// TODO freq
2024-12-07 16:16:31 +00:00
if (opt.remarks) {
res.remarks = parseRemarks(ctx, j);
}
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;
}
return res;
};
2017-11-11 22:35:41 +01:00
2022-05-07 16:17:37 +02:00
export {
parseJourney,
};