mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 01:56:33 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			86 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import {getHeaders} from './header.js';
 | 
						|
 | 
						|
const formatBaseJourneysReq = (ctx) => {
 | 
						|
	// TODO opt.accessibility
 | 
						|
	// TODO routingMode
 | 
						|
	const travellers = ctx.profile.formatTravellers(ctx);
 | 
						|
	return {
 | 
						|
		autonomeReservierung: false,
 | 
						|
		einstiegsTypList: [
 | 
						|
			'STANDARD',
 | 
						|
		],
 | 
						|
		klasse: travellers.klasse,
 | 
						|
		reisendenProfil: {
 | 
						|
			reisende: travellers.reisende.map(t => {
 | 
						|
				return {
 | 
						|
					ermaessigungen: [
 | 
						|
						t.ermaessigungen[0].art + ' ' + t.ermaessigungen[0].klasse,
 | 
						|
					],
 | 
						|
					reisendenTyp: t.typ,
 | 
						|
					alter: t.alter.length && parseInt(t.alter[0]) || undefined,
 | 
						|
				};
 | 
						|
			}),
 | 
						|
		},
 | 
						|
		reservierungsKontingenteVorhanden: false,
 | 
						|
	};
 | 
						|
};
 | 
						|
 | 
						|
const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => {
 | 
						|
	const {profile, opt} = ctx;
 | 
						|
 | 
						|
	from = profile.formatLocation(profile, from, 'from');
 | 
						|
	to = profile.formatLocation(profile, to, 'to');
 | 
						|
	const filters = profile.formatProductsFilter({profile}, opt.products || {}, 'dbnav');
 | 
						|
	const transfers = profile.formatTransfers(opt.transfers) ?? undefined; // `dbnav` does not allow `null` here
 | 
						|
	// TODO opt.accessibility
 | 
						|
	// TODO routingMode
 | 
						|
	let query = formatBaseJourneysReq(ctx);
 | 
						|
	query.reiseHin = {
 | 
						|
		wunsch: {
 | 
						|
			abgangsLocationId: from.lid,
 | 
						|
			verkehrsmittel: filters,
 | 
						|
			zeitWunsch: {
 | 
						|
				reiseDatum: profile.formatTime(profile, when, true),
 | 
						|
				zeitPunktArt: outFrwd ? 'ABFAHRT' : 'ANKUNFT',
 | 
						|
			},
 | 
						|
			viaLocations: opt.via
 | 
						|
				? [{locationId: profile.formatLocation(profile, opt.via, 'opt.via').lid}]
 | 
						|
				: undefined,
 | 
						|
			zielLocationId: to.lid,
 | 
						|
			maxUmstiege: transfers,
 | 
						|
			minUmstiegsdauer: opt.transferTime || undefined,
 | 
						|
			fahrradmitnahme: opt.bike,
 | 
						|
		},
 | 
						|
	};
 | 
						|
	if (journeysRef) {
 | 
						|
		query.reiseHin.wunsch.context = journeysRef;
 | 
						|
	}
 | 
						|
	return {
 | 
						|
		endpoint: ctx.profile.journeysEndpoint,
 | 
						|
		body: query,
 | 
						|
		headers: getHeaders('application/x.db.vendo.mob.verbindungssuche.v8+json'),
 | 
						|
		method: 'post',
 | 
						|
	};
 | 
						|
};
 | 
						|
 | 
						|
const formatRefreshJourneyReq = (ctx, refreshToken) => {
 | 
						|
	const {profile, opt} = ctx;
 | 
						|
	let query = {
 | 
						|
		reconCtx: refreshToken,
 | 
						|
	};
 | 
						|
	if (opt.tickets) {
 | 
						|
		query = formatBaseJourneysReq(ctx);
 | 
						|
		query.verbindungHin = {kontext: refreshToken};
 | 
						|
	}
 | 
						|
	return {
 | 
						|
		endpoint: opt.tickets ? profile.refreshJourneysEndpointTickets : profile.refreshJourneysEndpointPolyline,
 | 
						|
		body: query,
 | 
						|
		headers: getHeaders('application/x.db.vendo.mob.verbindungssuche.v8+json'),
 | 
						|
		method: 'post',
 | 
						|
	};
 | 
						|
};
 | 
						|
 | 
						|
export {
 | 
						|
	formatJourneysReq,
 | 
						|
	formatRefreshJourneyReq,
 | 
						|
};
 |