mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
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:
parent
1ab526d900
commit
f3c2ee6f5a
3 changed files with 40 additions and 3 deletions
36
p/db/ageGroup.js
Normal file
36
p/db/ageGroup.js
Normal 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
|
||||
}
|
|
@ -12,6 +12,6 @@
|
|||
},
|
||||
"endpoint": "https://reiseauskunft.bahn.de/bin/mgate.exe",
|
||||
"ext": "DB.R20.12.b",
|
||||
"ver": "1.34",
|
||||
"ver": "1.46",
|
||||
"defaultLanguage": "en"
|
||||
}
|
|
@ -19,6 +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 transformReqBody = (ctx, body) => {
|
||||
const req = body.svcReqL[0] || {}
|
||||
|
@ -159,7 +160,7 @@ const transformJourneysQuery = ({opt}, query) => {
|
|||
jnyCl: opt.firstClass === true ? 1 : 2,
|
||||
// todo [breaking]: support multiple travelers
|
||||
tvlrProf: [{
|
||||
type: 'E',
|
||||
type: opt.ageGroup || ageGroup.ADULT,
|
||||
redtnCard: opt.loyaltyCard
|
||||
? formatLoyaltyCard(opt.loyaltyCard)
|
||||
: null
|
||||
|
|
Loading…
Add table
Reference in a new issue