From 1236cf63a0b97230c46dca79dab5c6b3ded83ff2 Mon Sep 17 00:00:00 2001 From: roehrt Date: Sat, 23 Apr 2022 20:32:05 +0200 Subject: [PATCH] DB: support age group by age API --- p/db/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/p/db/index.js b/p/db/index.js index d00aa86b..fd50a8b6 100644 --- a/p/db/index.js +++ b/p/db/index.js @@ -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