artificially filter for includeRelatedStations and direction

This commit is contained in:
Traines 2025-02-13 20:09:18 +00:00
parent 2a23e1ad9b
commit 6ff406ea79
4 changed files with 13 additions and 7 deletions

8
api.js
View file

@ -47,10 +47,10 @@ const config = {
}; };
const profiles = { const profiles = {
'db': dbProfile, db: dbProfile,
'dbnav': dbnavProfile, dbnav: dbnavProfile,
'dbweb': dbwebProfile dbweb: dbwebProfile,
} };
const start = async () => { const start = async () => {
const vendo = createClient( const vendo = createClient(

View file

@ -106,9 +106,15 @@ const createClient = (profile, userAgent, opt = {}) => {
const {res} = await profile.request({profile, opt}, userAgent, req); const {res} = await profile.request({profile, opt}, userAgent, req);
const ctx = {profile, opt, common, res}; const ctx = {profile, opt, common, res};
const results = (res[resultsField] || res.items || res.bahnhofstafelAbfahrtPositionen || res.bahnhofstafelAnkunftPositionen || res.entries) let results = (res[resultsField] || res.items || res.bahnhofstafelAbfahrtPositionen || res.bahnhofstafelAnkunftPositionen || res.entries)
.map(res => parse(ctx, res)); // TODO sort?, slice .map(res => parse(ctx, res)); // TODO sort?, slice
if (!opt.includeRelatedStations) {
results = results.filter(r => !r.stop?.id || r.stop.id == station);
}
if (opt.direction) {
results = results.filter(r => !r.nextStopovers || r.nextStopovers.find(s => s.stop?.id == opt.direction || s.stop?.name == opt.direction));
}
return { return {
[resultsField]: results, [resultsField]: results,
realtimeDataUpdatedAt: null, // TODO realtimeDataUpdatedAt: null, // TODO

View file

@ -8,7 +8,7 @@ const formatStationBoardReq = (ctx, station, type) => {
ortExtId: station, ortExtId: station,
zeit: profile.formatTimeOfDay(profile, opt.when), zeit: profile.formatTimeOfDay(profile, opt.when),
datum: profile.formatDate(profile, opt.when), datum: profile.formatDate(profile, opt.when),
mitVias: opt.stopovers || undefined, mitVias: opt.stopovers || Boolean(opt.direction) || undefined,
verkehrsmittel: profile.formatProductsFilter(ctx, opt.products || {}), verkehrsmittel: profile.formatProductsFilter(ctx, opt.products || {}),
}, },
method: 'GET', method: 'GET',

View file

@ -40,7 +40,7 @@ const createParseArrOrDep = (prefix) => {
res.remarks = profile.parseRemarks(ctx, d); res.remarks = profile.parseRemarks(ctx, d);
} }
if (opt.stopovers && Array.isArray(d.ueber)) { if ((opt.stopovers || opt.direction) && Array.isArray(d.ueber)) {
const stopovers = d.ueber const stopovers = d.ueber
.map(viaName => profile.parseStopover(ctx, {name: viaName}, null)); .map(viaName => profile.parseStopover(ctx, {name: viaName}, null));