db-vendo-client/p/dbweb/journeys-req.js
dabund24 c671e995cb
bahn.de boards (#12)
* parse bahn.de boards

* add optional chaining in line.js

* unit tests for bahn.de boards

* fix product check in line.js for bahn.de boards

* add integration tests for bahn.de boards

* allow letting hafas decide the amount of vias

* split dbweb and dbregioguide profiles; add db profile

* commit location-filter.js (forgot that in the last commit)

* simplify how db profile works

* remove `ezGleis` from coalesce for scheduled platform

* un-break parsing of remarks

* determine fahrtNr by removing all non-digits

* employ enrichStations for board stop property

* prevent timeouts in dbweb e2e test from calling `end()` twice

* use promises in dbweb e2e tests when waiting for enrichStations to work

* replace vias option with stopovers option for dbweb profile; enrich stations when only name is known

* change dbweb-departures test covering enrichStation feature for stop and stopovers

* remove check for not existing option

* move verkehrsmittel.name in front of verkehrsmittel.langText when parsing name in line.js
2025-02-09 00:46:21 +01:00

76 lines
2.1 KiB
JavaScript

const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => {
const {profile, opt} = ctx;
from = profile.formatLocation(profile, from, 'from');
to = profile.formatLocation(profile, to, 'to');
const filters = profile.formatProductsFilter({profile}, opt.products || {});
const transfers = profile.formatTransfers(opt.transfers);
// TODO opt.accessibility
// TODO routingMode
let query = {
maxUmstiege: transfers,
minUmstiegszeit: opt.transferTime,
deutschlandTicketVorhanden: false,
nurDeutschlandTicketVerbindungen: false,
reservierungsKontingenteVorhanden: false,
schnelleVerbindungen: true,
sitzplatzOnly: false,
abfahrtsHalt: from.lid,
zwischenhalte: opt.via
? [{id: profile.formatLocation(profile, opt.via, 'opt.via').lid}]
: null,
ankunftsHalt: to.lid,
produktgattungen: filters,
bikeCarriage: opt.bike,
// TODO
// todo: this is actually "take additional stations nearby the given start and destination station into account"
// see rest.exe docs
// ushrp: Boolean(opt.startWithWalking),
};
query.anfrageZeitpunkt = profile.formatTime(profile, when);
if (journeysRef) {
query.pagingReference = journeysRef;
}
query.ankunftSuche = outFrwd ? 'ABFAHRT' : 'ANKUNFT';
if (opt.results !== null) {
// TODO query.numF = opt.results;
}
query = Object.assign(query, ctx.profile.formatTravellers(ctx));
return {
endpoint: ctx.profile.journeysEndpoint,
body: query,
method: 'post',
};
};
// TODO poly conditional other endpoint
const formatRefreshJourneyReq = (ctx, refreshToken) => {
const {profile, opt} = ctx;
if (opt.tickets) {
let query = {
ctxRecon: refreshToken,
deutschlandTicketVorhanden: false,
nurDeutschlandTicketVerbindungen: false,
reservierungsKontingenteVorhanden: false,
};
query = Object.assign(query, profile.formatTravellers(ctx));
return {
endpoint: profile.refreshJourneysEndpointTickets,
body: query,
method: 'post',
};
} else {
return {
endpoint: profile.refreshJourneysEndpointPolyline,
body: {
ctxRecon: refreshToken,
poly: true,
},
method: 'post',
};
}
};
export {
formatJourneysReq,
formatRefreshJourneyReq,
};