From 248adb5f7221980bd11df0ce404e9da0f6ee18a9 Mon Sep 17 00:00:00 2001 From: Paul Sutter Date: Tue, 26 Dec 2023 13:27:06 +0100 Subject: [PATCH] DB refreshJourney(): optionally request ticket infos Co-Authored-By: Jannis R --- p/db/index.js | 55 ++++++++++++++----- .../db-journey-overnight-0.expected.json | 8 ++- .../db-journey-overnight-1.expected.js | 4 ++ test/fixtures/db-journey-polyline.js | 4 ++ test/fixtures/db-journey.js | 4 ++ 5 files changed, 60 insertions(+), 15 deletions(-) diff --git a/p/db/index.js b/p/db/index.js index cdacad7c..5110d08c 100644 --- a/p/db/index.js +++ b/p/db/index.js @@ -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, diff --git a/test/fixtures/db-journey-overnight-0.expected.json b/test/fixtures/db-journey-overnight-0.expected.json index 70f05f5f..2fc155a4 100644 --- a/test/fixtures/db-journey-overnight-0.expected.json +++ b/test/fixtures/db-journey-overnight-0.expected.json @@ -194,5 +194,11 @@ "amount": 55.9, "currency": "EUR", "hint": null - } + }, + "tickets": [ + { + "name": "To offer selection", + "priceObj": {"amount": 5590} + } + ] } diff --git a/test/fixtures/db-journey-overnight-1.expected.js b/test/fixtures/db-journey-overnight-1.expected.js index 7402ed5d..93fdd192 100644 --- a/test/fixtures/db-journey-overnight-1.expected.js +++ b/test/fixtures/db-journey-overnight-1.expected.js @@ -306,6 +306,10 @@ const overnightJourney = { remarks: [], price: {amount: 108.9, currency: 'EUR', hint: null}, + tickets: [{ + name: 'To offer selection', + priceObj: {amount: 10890}, + }], }; export { diff --git a/test/fixtures/db-journey-polyline.js b/test/fixtures/db-journey-polyline.js index 236ac6c2..35fdc2b3 100644 --- a/test/fixtures/db-journey-polyline.js +++ b/test/fixtures/db-journey-polyline.js @@ -3975,6 +3975,10 @@ const dbJourneyPolyline = { currency: 'EUR', hint: null, }, + tickets: [{ + name: 'Continue to booking', + priceObj: {amount: 6990}, + }], }; export { diff --git a/test/fixtures/db-journey.js b/test/fixtures/db-journey.js index a72e2dd5..d8ead52d 100644 --- a/test/fixtures/db-journey.js +++ b/test/fixtures/db-journey.js @@ -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 {