DB: support age group by age API

This commit is contained in:
roehrt 2022-04-23 20:32:05 +02:00 committed by Jannis R
parent 7a3fd4fca5
commit 1236cf63a0
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -19,7 +19,7 @@ const {bike} = require('../../format/filters')
const products = require('./products')
const baseProfile = require('./base.json')
const formatLoyaltyCard = require('./loyalty-cards').format
const {ageGroup} = require('./ageGroup')
const {ageGroup, ageGroupFromAge} = require('./ageGroup')
const transformReqBody = (ctx, body) => {
const req = body.svcReqL[0] || {}
@ -156,11 +156,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.')
const tvlrAgeGroup = ('age' in opt) ? ageGroupFromAge(opt.age) : opt.ageGroup
query.trfReq = {
jnyCl: opt.firstClass === true ? 1 : 2,
// todo [breaking]: support multiple travelers
tvlrProf: [{
type: opt.ageGroup || ageGroup.ADULT,
type: tvlrAgeGroup || ageGroup.ADULT,
redtnCard: opt.loyaltyCard
? formatLoyaltyCard(opt.loyaltyCard)
: null