DB refreshJourney(): optionally request ticket infos

Co-Authored-By: Jannis R <mail@jannisr.de>
This commit is contained in:
Paul Sutter 2023-12-26 13:27:06 +01:00 committed by Jannis R
parent fd90abdeca
commit 248adb5f72
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
5 changed files with 60 additions and 15 deletions

View file

@ -194,12 +194,7 @@ const parseArrOrDepWithLoadFactor = ({parsed, res, opt}, d) => {
return parsed;
};
const transformJourneysQuery = ({opt}, query) => {
const filters = query.jnyFltrL;
if (opt.bike) {
filters.push(bike);
}
const trfReq = (opt, refreshJourney) => {
if ('age' in opt && 'ageGroup' in opt) {
throw new TypeError(`\
opt.age and opt.ageGroup are mutually exclusive.
@ -210,14 +205,8 @@ Pass in just opt.age, and the age group will calculated automatically.`);
? ageGroupFromAge(opt.age)
: opt.ageGroup;
query.trfReq = {
// todo: what are these?
// "directESuiteCall": true,
// "rType": "DB-PE",
jnyCl: opt.firstClass === true
? 1
: 2,
const basicCtrfReq = {
jnyCl: opt.firstClass === true ? 1 : 2,
// todo [breaking]: support multiple travelers
tvlrProf: [{
type: tvlrAgeGroup || ageGroup.ADULT,
@ -230,10 +219,47 @@ Pass in just opt.age, and the age group will calculated automatically.`);
}],
cType: 'PK',
};
if (refreshJourney && opt.tickets) {
// todo: what are these?
// basicCtrfReq.directESuiteCall = true
// If called with "Reconstruction"
// 'DB-PE' causes the response to contain the tariff information.
basicCtrfReq.rType = 'DB-PE';
}
return basicCtrfReq;
};
const transformJourneysQuery = ({opt}, query) => {
const filters = query.jnyFltrL;
if (opt.bike) {
filters.push(bike);
}
query.trfReq = trfReq(opt, false);
return query;
};
const formatRefreshJourneyReq = (ctx, refreshToken) => {
const {profile, opt} = ctx;
const req = {
getIST: true,
getPasslist: Boolean(opt.stopovers),
getPolyline: Boolean(opt.polylines),
getTariff: Boolean(opt.tickets),
};
if (profile.refreshJourneyUseOutReconL) {
req.outReconL = [{ctx: refreshToken}];
} else {
req.ctxRecon = refreshToken;
}
req.trfReq = trfReq(opt, true);
return {
meth: 'Reconstruction',
req,
};
};
// todo: fix this
// line: {
// type: 'line',
@ -595,6 +621,7 @@ const profile = {
transformReqBody,
transformReq,
transformJourneysQuery,
formatRefreshJourneyReq,
products: products,

View file

@ -194,5 +194,11 @@
"amount": 55.9,
"currency": "EUR",
"hint": null
}
},
"tickets": [
{
"name": "To offer selection",
"priceObj": {"amount": 5590}
}
]
}

View file

@ -306,6 +306,10 @@ const overnightJourney = {
remarks: [],
price: {amount: 108.9, currency: 'EUR', hint: null},
tickets: [{
name: 'To offer selection',
priceObj: {amount: 10890},
}],
};
export {

View file

@ -3975,6 +3975,10 @@ const dbJourneyPolyline = {
currency: 'EUR',
hint: null,
},
tickets: [{
name: 'Continue to booking',
priceObj: {amount: 6990},
}],
};
export {

View file

@ -195,6 +195,10 @@ const dbJourney = {
],
refreshToken: '¶HKI¶D$A=1@O=Köln Hbf@L=8000207@a=128@$A=1@O=Köln Messe/Deutz Gl.11-12@L=8073368@a=128@$202004110517$202004110520$$$1$§T$A=1@O=Köln Messe/Deutz Gl.11-12@L=8073368@a=128@$A=1@O=Nürnberg Hbf@L=8000284@a=128@$202004110520$202004110901$ICE 523$$1$',
price: {amount: 49.9, currency: 'EUR', hint: null},
tickets: [{
name: 'Continue to booking',
priceObj: {amount: 4990},
}],
};
export {