mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
DB refreshJourney(): optionally request ticket infos
Co-Authored-By: Jannis R <mail@jannisr.de>
This commit is contained in:
parent
fd90abdeca
commit
248adb5f72
5 changed files with 60 additions and 15 deletions
|
@ -194,12 +194,7 @@ const parseArrOrDepWithLoadFactor = ({parsed, res, opt}, d) => {
|
||||||
return parsed;
|
return parsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
const transformJourneysQuery = ({opt}, query) => {
|
const trfReq = (opt, refreshJourney) => {
|
||||||
const filters = query.jnyFltrL;
|
|
||||||
if (opt.bike) {
|
|
||||||
filters.push(bike);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('age' in opt && 'ageGroup' in opt) {
|
if ('age' in opt && 'ageGroup' in opt) {
|
||||||
throw new TypeError(`\
|
throw new TypeError(`\
|
||||||
opt.age and opt.ageGroup are mutually exclusive.
|
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)
|
? ageGroupFromAge(opt.age)
|
||||||
: opt.ageGroup;
|
: opt.ageGroup;
|
||||||
|
|
||||||
query.trfReq = {
|
const basicCtrfReq = {
|
||||||
// todo: what are these?
|
jnyCl: opt.firstClass === true ? 1 : 2,
|
||||||
// "directESuiteCall": true,
|
|
||||||
// "rType": "DB-PE",
|
|
||||||
|
|
||||||
jnyCl: opt.firstClass === true
|
|
||||||
? 1
|
|
||||||
: 2,
|
|
||||||
// todo [breaking]: support multiple travelers
|
// todo [breaking]: support multiple travelers
|
||||||
tvlrProf: [{
|
tvlrProf: [{
|
||||||
type: tvlrAgeGroup || ageGroup.ADULT,
|
type: tvlrAgeGroup || ageGroup.ADULT,
|
||||||
|
@ -230,10 +219,47 @@ Pass in just opt.age, and the age group will calculated automatically.`);
|
||||||
}],
|
}],
|
||||||
cType: 'PK',
|
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;
|
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
|
// todo: fix this
|
||||||
// line: {
|
// line: {
|
||||||
// type: 'line',
|
// type: 'line',
|
||||||
|
@ -595,6 +621,7 @@ const profile = {
|
||||||
transformReqBody,
|
transformReqBody,
|
||||||
transformReq,
|
transformReq,
|
||||||
transformJourneysQuery,
|
transformJourneysQuery,
|
||||||
|
formatRefreshJourneyReq,
|
||||||
|
|
||||||
products: products,
|
products: products,
|
||||||
|
|
||||||
|
|
|
@ -194,5 +194,11 @@
|
||||||
"amount": 55.9,
|
"amount": 55.9,
|
||||||
"currency": "EUR",
|
"currency": "EUR",
|
||||||
"hint": null
|
"hint": null
|
||||||
}
|
},
|
||||||
|
"tickets": [
|
||||||
|
{
|
||||||
|
"name": "To offer selection",
|
||||||
|
"priceObj": {"amount": 5590}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,6 +306,10 @@ const overnightJourney = {
|
||||||
|
|
||||||
remarks: [],
|
remarks: [],
|
||||||
price: {amount: 108.9, currency: 'EUR', hint: null},
|
price: {amount: 108.9, currency: 'EUR', hint: null},
|
||||||
|
tickets: [{
|
||||||
|
name: 'To offer selection',
|
||||||
|
priceObj: {amount: 10890},
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
4
test/fixtures/db-journey-polyline.js
vendored
4
test/fixtures/db-journey-polyline.js
vendored
|
@ -3975,6 +3975,10 @@ const dbJourneyPolyline = {
|
||||||
currency: 'EUR',
|
currency: 'EUR',
|
||||||
hint: null,
|
hint: null,
|
||||||
},
|
},
|
||||||
|
tickets: [{
|
||||||
|
name: 'Continue to booking',
|
||||||
|
priceObj: {amount: 6990},
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
4
test/fixtures/db-journey.js
vendored
4
test/fixtures/db-journey.js
vendored
|
@ -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$',
|
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},
|
price: {amount: 49.9, currency: 'EUR', hint: null},
|
||||||
|
tickets: [{
|
||||||
|
name: 'Continue to booking',
|
||||||
|
priceObj: {amount: 4990},
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
Loading…
Add table
Reference in a new issue