db-vendo-client/p/dbweb/journeys-req.js

77 lines
2.1 KiB
JavaScript
Raw Normal View History

2024-12-21 15:51:25 +00:00
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);
2024-12-21 15:51:25 +00:00
// TODO opt.accessibility
2024-12-21 23:04:05 +00:00
// TODO routingMode
2024-12-21 15:51:25 +00:00
let query = {
maxUmstiege: transfers,
2024-12-21 15:51:25 +00:00
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;
}
2024-12-21 15:26:49 +00:00
query = Object.assign(query, ctx.profile.formatTravellers(ctx));
return {
endpoint: ctx.profile.journeysEndpoint,
body: query,
method: 'post',
};
};
2025-01-03 11:39:55 +00:00
// TODO poly conditional other endpoint
2024-12-21 15:26:49 +00:00
const formatRefreshJourneyReq = (ctx, refreshToken) => {
2025-01-14 21:12:23 +00:00
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',
};
}
2024-12-21 15:26:49 +00:00
};
export {
formatJourneysReq,
formatRefreshJourneyReq,
};