From 0bc6ba36508eb463c68d92731a79314ee4d7311b Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 3 Sep 2023 13:52:55 +0200 Subject: [PATCH] =?UTF-8?q?DB=20journeys():=20pass=20along=20opt.age=20if?= =?UTF-8?q?=20defined=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- p/db/index.js | 10 +++++++--- test/format/db-journeys-query.js | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/p/db/index.js b/p/db/index.js index 3eceeecc..865854e7 100644 --- a/p/db/index.js +++ b/p/db/index.js @@ -178,13 +178,16 @@ const transformJourneysQuery = ({opt}, query) => { const filters = query.jnyFltrL if (opt.bike) filters.push(bike) - if (('age' in opt) && ('ageGroup' in opt)) - throw new TypeError('opt.age and opt.ageGroup are mutually exclusive.') + if (('age' in opt) && ('ageGroup' in opt)) { + throw new TypeError(`\ +opt.age and opt.ageGroup are mutually exclusive. +Pass in just opt.age, and the age group will calculated automatically.`) + } const tvlrAgeGroup = ('age' in opt) ? ageGroupFromAge(opt.age) : opt.ageGroup query.trfReq = { - // todo: + // todo: what are these? // "directESuiteCall": true, // "rType": "DB-PE", @@ -192,6 +195,7 @@ const transformJourneysQuery = ({opt}, query) => { // todo [breaking]: support multiple travelers tvlrProf: [{ type: tvlrAgeGroup || ageGroup.ADULT, + ...(('age' in opt) ? {age: opt.age} : {}), redtnCard: opt.loyaltyCard ? formatLoyaltyCard(opt.loyaltyCard) : null diff --git a/test/format/db-journeys-query.js b/test/format/db-journeys-query.js index 6177e146..0cd1d123 100644 --- a/test/format/db-journeys-query.js +++ b/test/format/db-journeys-query.js @@ -27,6 +27,7 @@ const opt = { products: {}, firstClass: false, + age: 24, loyaltyCard: { type: loyaltyCards.BAHNCARD, discount: 25, @@ -73,7 +74,8 @@ tap.test('formats a journeys() request correctly (DB)', (t) => { trfReq: { jnyCl: 2, tvlrProf: [{ - type: 'E', // "adult" + type: 'Y', // "young" + age: 24, redtnCard: 2, // BahnCard 25 }], cType: 'PK',