DB journeys(): pass along opt.age if defined

This commit is contained in:
Jannis R 2023-09-03 13:52:55 +02:00
parent a8401f36e1
commit 0bc6ba3650
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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',