mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
DB: add parseLoyaltyCard utility function
Co-Authored-By: Jannis R <mail@jannisr.de>
This commit is contained in:
parent
c4966aeca7
commit
191b9abb6d
1 changed files with 32 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
import {deepStrictEqual as eql} from 'node:assert';
|
||||
|
||||
// todo: generate from https://reiseauskunft.bahn.de/addons/fachkonfig-utf8.cfg ?
|
||||
const c = {
|
||||
NONE: Symbol('no loyalty card'),
|
||||
|
@ -45,7 +47,37 @@ const formatLoyaltyCard = (data) => {
|
|||
return 0;
|
||||
};
|
||||
|
||||
const parseLoyaltyCard = (cardId) => {
|
||||
switch (cardId) {
|
||||
case 1:
|
||||
case 2: return {type: c.BAHNCARD, discount: 25, class: cardId === 1 ? 1 : 2};
|
||||
case 3:
|
||||
case 4: return {type: c.BAHNCARD, discount: 50, class: cardId === 3 ? 1 : 2};
|
||||
case 9: return {type: c.VORTEILSCARD};
|
||||
case 10:
|
||||
case 11: return {type: c.HALBTAXABO, railplus: cardId === 10};
|
||||
case 12:
|
||||
case 13: return {type: c.VOORDEELURENABO, railplus: cardId === 12};
|
||||
case 14: return {type: c.SHCARD};
|
||||
case 15: return {type: c.GENERALABONNEMENT};
|
||||
default: return {type: c.NONE};
|
||||
}
|
||||
};
|
||||
|
||||
const bcFirst50 = {
|
||||
type: c.BAHNCARD,
|
||||
class: 1,
|
||||
discount: 50,
|
||||
};
|
||||
eql(parseLoyaltyCard(formatLoyaltyCard(bcFirst50)), bcFirst50);
|
||||
const halbtaxRailplus = {
|
||||
type: c.HALBTAXABO,
|
||||
railplus: true,
|
||||
};
|
||||
eql(parseLoyaltyCard(formatLoyaltyCard(halbtaxRailplus)), halbtaxRailplus);
|
||||
|
||||
export {
|
||||
c as data,
|
||||
formatLoyaltyCard,
|
||||
parseLoyaltyCard,
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue