db-vendo-client/p/db/loyalty-cards.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-12-16 12:02:47 +00:00
const c = {
NONE: Symbol('no loyalty card'),
BAHNCARD: Symbol('Bahncard'),
VORTEILSCARD: Symbol('VorteilsCard'),
HALBTAXABO: Symbol('HalbtaxAbo'),
VOORDEELURENABO: Symbol('Voordeelurenabo'),
SHCARD: Symbol('SH-Card'),
GENERALABONNEMENT: Symbol('General-Abonnement'),
};
2017-11-12 23:51:39 +01:00
// see https://gist.github.com/juliuste/202bb04f450a79f8fa12a2ec3abcd72d
const formatLoyaltyCard = (data) => {
2024-12-07 23:48:08 +00:00
if (!data) {
return {
2024-12-08 21:42:57 +00:00
art: 'KEINE_ERMAESSIGUNG',
klasse: 'KLASSENLOS',
};
2024-12-07 23:48:08 +00:00
}
const cls = data.class === 1 ? 'KLASSE_1' : 'KLASSE_2';
2024-12-16 12:02:47 +00:00
if (data.type.toString() === c.BAHNCARD.toString()) {
2024-12-07 23:48:08 +00:00
return {
2024-12-08 21:42:57 +00:00
art: 'BAHNCARD' + data.discount,
klasse: cls,
};
2017-11-12 23:51:39 +01:00
}
2024-12-16 12:02:47 +00:00
if (data.type.toString() === c.VORTEILSCARD.toString()) {
2024-12-07 23:48:08 +00:00
return {
art: 'A-VORTEILSCARD',
2024-12-08 21:42:57 +00:00
klasse: 'KLASSENLOS',
};
}
2024-12-16 12:02:47 +00:00
if (data.type.toString() === c.HALBTAXABO.toString()) {
2024-12-07 23:48:08 +00:00
return {
art: 'CH-HALBTAXABO_OHNE_RAILPLUS',
2024-12-08 21:42:57 +00:00
klasse: 'KLASSENLOS',
};
}
2024-12-07 23:48:08 +00:00
// TODO Rest
2024-12-16 12:02:47 +00:00
if (data.type.toString() === c.GENERALABONNEMENT.toString()) {
2024-12-07 23:48:08 +00:00
return {
art: 'CH-GENERAL-ABONNEMENT',
2024-12-08 21:42:57 +00:00
klasse: cls,
};
}
2024-12-07 23:48:08 +00:00
return {
2024-12-08 21:42:57 +00:00
art: 'KEINE_ERMAESSIGUNG',
klasse: 'KLASSENLOS',
};
};
2022-05-07 16:17:37 +02:00
export {
c as data,
2024-12-08 21:42:57 +00:00
formatLoyaltyCard,
};