db-vendo-client/parse/arrival-or-departure.js

48 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-12-07 16:16:31 +00:00
import {parseRemarks} from './remarks.js';
2018-06-26 15:49:50 +02:00
const ARRIVAL = 'a';
const DEPARTURE = 'd';
const createParseArrOrDep = (prefix) => {
if (prefix !== ARRIVAL && prefix !== DEPARTURE) {
throw new Error('invalid prefix');
}
2018-06-26 15:49:50 +02:00
const parseArrOrDep = (ctx, d) => { // d = raw arrival/departure
const {profile, opt} = ctx;
2018-06-26 15:49:50 +02:00
const res = {
2024-12-10 22:49:11 +00:00
tripId: d.journeyID || d.train.journeyId,
2024-12-07 22:46:04 +00:00
stop: profile.parseLocation(ctx, d.station),
2024-12-10 17:51:20 +00:00
...profile.parseWhen(ctx, null, d.timeSchedule ? d.timeSchedule : d.time, d.timePredicted ? d.timePredicted : d.time, d.canceled),
...profile.parsePlatform(ctx, d.platformSchedule ? d.platformSchedule : d.platform, d.platformPredicted ? d.platformPredicted : d.platform, d.canceled),
2024-12-08 21:42:57 +00:00
// prognosisType: TODO
2024-12-10 17:51:20 +00:00
direction: d.transport?.direction?.stopPlaces?.length > 0 && profile.parseStationName(ctx, d.transport?.direction?.stopPlaces[0].name) || profile.parseStationName(ctx, d.destination?.name) || null,
provenance: profile.parseStationName(ctx, d.transport?.origin?.name) || profile.parseStationName(ctx, d.origin?.name) || null,
2024-12-07 22:46:04 +00:00
line: profile.parseLine(ctx, d) || null,
remarks: [],
2024-12-10 17:51:20 +00:00
origin: profile.parseLocation(ctx, d.transport?.origin || d.origin) || null,
destination: profile.parseLocation(ctx, d.transport?.destination || d.destination) || null,
};
2024-12-07 22:46:04 +00:00
// TODO pos
2024-12-07 22:46:04 +00:00
if (d.canceled) {
res.cancelled = true;
Object.defineProperty(res, 'canceled', {value: true});
2018-06-26 15:49:50 +02:00
}
2018-06-28 13:45:56 +02:00
if (opt.remarks) {
2024-12-07 22:46:04 +00:00
res.remarks = parseRemarks(ctx, d);
2018-06-28 13:45:56 +02:00
}
2024-12-07 22:46:04 +00:00
// TODO opt.stopovers
return res;
};
2018-06-26 15:49:50 +02:00
return parseArrOrDep;
};
2018-06-26 15:49:50 +02:00
2022-05-07 16:17:37 +02:00
export {
createParseArrOrDep,
};