db-rest/lib/loyalty-cards.js

37 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

import {data as cards} from 'hafas-client/p/db/loyalty-cards.js'
const typesByName = new Map([
2022-06-06 14:24:48 +02:00
// https://github.com/public-transport/hafas-client/blob/68ecd7c5e976dd2f51c5c64a81600e7e181a8996/p/db/loyalty-cards.js#L6-L11
['bahncard-1st-25', {type: cards.BAHNCARD, discount: 25, class: 1}],
['bahncard-2nd-25', {type: cards.BAHNCARD, discount: 25, class: 2}],
['bahncard-1st-50', {type: cards.BAHNCARD, discount: 50, class: 1}],
['bahncard-2nd-50', {type: cards.BAHNCARD, discount: 50, class: 2}],
['vorteilscard', {type: cards.VORTEILSCARD}],
['halbtaxabo-railplus', {type: cards.HALBTAXABO, railplus: true}],
['halbtaxabo', {type: cards.HALBTAXABO, railplus: false}],
['voordeelurenabo-railplus', {type: cards.VOORDEELURENABO, railplus: true}],
['voordeelurenabo', {type: cards.VOORDEELURENABO, railplus: false}],
['shcard', {type: cards.SHCARD}],
['generalabonnement', {type: cards.GENERALABONNEMENT}],
])
const types = Array.from(typesByName.keys())
const parseLoyaltyCard = (key, val) => {
if (typesByName.has(val)) return typesByName.get(val)
throw new Error(key + ' must be one of ' + types.join(', '))
}
const loyaltyCardParser = {
2022-06-06 14:24:48 +02:00
description: `Type of loyalty card in use.`,
type: 'string',
enum: types,
defaultStr: '*none*',
parse: parseLoyaltyCard,
}
2022-12-19 13:23:13 +01:00
export {
cards as loyaltyCards,
parseLoyaltyCard,
loyaltyCardParser,
}