mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
30 lines
755 B
JavaScript
30 lines
755 B
JavaScript
|
const formatTravellers = ({profile, opt}) => {
|
||
|
if ('age' in opt && 'ageGroup' in opt) {
|
||
|
throw new TypeError(`\
|
||
|
opt.age and opt.ageGroup are mutually exclusive.
|
||
|
Pass in just opt.age, and the age group will calculated automatically.`);
|
||
|
}
|
||
|
|
||
|
const tvlrAgeGroup = 'age' in opt
|
||
|
? profile.ageGroupFromAge(opt.age)
|
||
|
: opt.ageGroup;
|
||
|
|
||
|
const basicCtrfReq = {
|
||
|
klasse: opt.firstClass === true ? 'KLASSE_1' : 'KLASSE_2',
|
||
|
// todo [breaking]: support multiple travelers
|
||
|
reisende: [{
|
||
|
typ: profile.ageGroupLabel[tvlrAgeGroup || profile.ageGroup.ADULT],
|
||
|
anzahl: 1,
|
||
|
alter: 'age' in opt
|
||
|
? [String(opt.age)]
|
||
|
: [],
|
||
|
ermaessigungen: [profile.formatLoyaltyCard(opt.loyaltyCard)],
|
||
|
}],
|
||
|
};
|
||
|
return basicCtrfReq;
|
||
|
};
|
||
|
|
||
|
export {
|
||
|
formatTravellers,
|
||
|
};
|