diff --git a/p/db/ageGroup.js b/p/db/ageGroup.js new file mode 100644 index 00000000..43bf558e --- /dev/null +++ b/p/db/ageGroup.js @@ -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 +} diff --git a/p/db/base.json b/p/db/base.json index 2d52b303..e094c419 100644 --- a/p/db/base.json +++ b/p/db/base.json @@ -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" -} +} \ No newline at end of file diff --git a/p/db/index.js b/p/db/index.js index 7dae4bc1..d00aa86b 100644 --- a/p/db/index.js +++ b/p/db/index.js @@ -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