DB: support age-based tariffs

The supported age groups are now:
- 'B' (baby, infant)
- 'K' (kind, child)
- 'Y' (young)
- 'E' (Erwachsener, adult)
- 'S' (Senior)
This commit is contained in:
roehrt 2022-04-21 18:49:12 +02:00 committed by Jannis R
parent 1ab526d900
commit f3c2ee6f5a
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 40 additions and 3 deletions

36
p/db/ageGroup.js Normal file
View file

@ -0,0 +1,36 @@
'use strict'
const ageGroup = {
BABY: 'B',
CHILD: 'K',
YOUNG: 'Y',
ADULT: 'E',
SENIOR: 'S',
upperBoundOf: {
BABY: 6,
CHILD: 15,
YOUNG: 27,
ADULT: 65,
SENIOR: Infinity
}
}
const ageGroupFromAge = (age) => {
const {upperBoundOf} = ageGroup
if (age < upperBoundOf.BABY)
return ageGroup.BABY
if (age < upperBoundOf.CHILD)
return ageGroup.CHILD
if (age < upperBoundOf.YOUNG)
return ageGroup.YOUNG
if (age < upperBoundOf.ADULT)
return ageGroup.ADULT
if (age < upperBoundOf.SENIOR)
return ageGroup.SENIOR
throw new TypeError(`Invalid age '${age}'`)
}
module.exports = {
ageGroup,
ageGroupFromAge
}

View file

@ -12,6 +12,6 @@
}, },
"endpoint": "https://reiseauskunft.bahn.de/bin/mgate.exe", "endpoint": "https://reiseauskunft.bahn.de/bin/mgate.exe",
"ext": "DB.R20.12.b", "ext": "DB.R20.12.b",
"ver": "1.34", "ver": "1.46",
"defaultLanguage": "en" "defaultLanguage": "en"
} }

View file

@ -19,6 +19,7 @@ const {bike} = require('../../format/filters')
const products = require('./products') const products = require('./products')
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const formatLoyaltyCard = require('./loyalty-cards').format const formatLoyaltyCard = require('./loyalty-cards').format
const {ageGroup} = require('./ageGroup')
const transformReqBody = (ctx, body) => { const transformReqBody = (ctx, body) => {
const req = body.svcReqL[0] || {} const req = body.svcReqL[0] || {}
@ -159,7 +160,7 @@ const transformJourneysQuery = ({opt}, query) => {
jnyCl: opt.firstClass === true ? 1 : 2, jnyCl: opt.firstClass === true ? 1 : 2,
// todo [breaking]: support multiple travelers // todo [breaking]: support multiple travelers
tvlrProf: [{ tvlrProf: [{
type: 'E', type: opt.ageGroup || ageGroup.ADULT,
redtnCard: opt.loyaltyCard redtnCard: opt.loyaltyCard
? formatLoyaltyCard(opt.loyaltyCard) ? formatLoyaltyCard(opt.loyaltyCard)
: null : null