2022-12-19 13:23:13 +01:00
|
|
|
import _loyaltyCards from 'hafas-client/p/db/loyalty-cards.js'
|
|
|
|
const {data: cards} = _loyaltyCards
|
2022-04-02 17:02:25 +02:00
|
|
|
|
|
|
|
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
|
2022-04-02 17:02:25 +02:00
|
|
|
['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.`,
|
2022-04-02 17:02:25 +02:00
|
|
|
type: 'string',
|
|
|
|
enum: types,
|
|
|
|
defaultStr: '*none*',
|
|
|
|
parse: parseLoyaltyCard,
|
|
|
|
}
|
|
|
|
|
2022-12-19 13:23:13 +01:00
|
|
|
export {
|
|
|
|
cards as loyaltyCards,
|
2022-04-02 17:02:25 +02:00
|
|
|
parseLoyaltyCard,
|
|
|
|
loyaltyCardParser,
|
|
|
|
}
|