mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 10:06:32 +02:00 
			
		
		
		
	DB: add routingModes option 📝✅
closes #295 fixes #287 Co-Authored-By: Jannis R <mail@jannisr.de>
This commit is contained in:
		
							parent
							
								
									92bbc63590
								
							
						
					
					
						commit
						5ce0129c36
					
				
					 5 changed files with 861 additions and 137 deletions
				
			
		| 
						 | 
				
			
			@ -23,12 +23,18 @@ const baseProfile = require('./base.json')
 | 
			
		|||
import {products} from './products.js'
 | 
			
		||||
import {formatLoyaltyCard} from './loyalty-cards.js'
 | 
			
		||||
import {ageGroup, ageGroupFromAge} from './ageGroup.js'
 | 
			
		||||
import {routingModes} from './routing-modes.js'
 | 
			
		||||
 | 
			
		||||
const transformReqBody = (ctx, body) => {
 | 
			
		||||
	const req = body.svcReqL[0] || {}
 | 
			
		||||
 | 
			
		||||
	// see https://pastebin.com/qZ9WS3Cx
 | 
			
		||||
	req.cfg = {...req.cfg, rtMode: 'REALTIME'}
 | 
			
		||||
	const rtMode = ('routingMode' in ctx.opt) ? ctx.opt.routingMode :  routingModes.REALTIME
 | 
			
		||||
 | 
			
		||||
	req.cfg = {
 | 
			
		||||
		...req.cfg,
 | 
			
		||||
		rtMode,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return body
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,3 +82,15 @@ hafas.journeys(from, to, {
 | 
			
		|||
	loyaltyCard: {type: data.BAHNCARD, discount: 25}
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Using the `routingMode` option
 | 
			
		||||
 | 
			
		||||
The default option is `REALTIME`. An explaination about different routing options can be found in [https://pastebin.com/qZ9WS3Cx](https://pastebin.com/qZ9WS3Cx). The option `HYBRID` is the default option (as of 18.07.2023) in the iOS DB mobile application and also shows cancelled trains (in contrast to the default option `REALTIME`).
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
import {routingModes} from 'hafas-client/p/db/routing-modes.js'
 | 
			
		||||
 | 
			
		||||
await hafas.journeys(from, to, {
 | 
			
		||||
	routingMode: routingModes.HYBRID,
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										13
									
								
								p/db/routing-modes.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								p/db/routing-modes.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
// see https://pastebin.com/qZ9WS3Cx
 | 
			
		||||
const routingModes = {
 | 
			
		||||
	OFF: 'OFF',
 | 
			
		||||
	INFOS: 'INFOS',
 | 
			
		||||
	FULL: 'FULL',
 | 
			
		||||
	REALTIME: 'REALTIME',
 | 
			
		||||
	SERVER_DEFAULT: 'SERVER_DEFAULT',
 | 
			
		||||
	HYBRID: 'HYBRID',
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export {
 | 
			
		||||
	routingModes,
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -7,6 +7,7 @@ import last from 'lodash/last.js'
 | 
			
		|||
import {createWhen} from './lib/util.js'
 | 
			
		||||
import {createClient} from '../../index.js'
 | 
			
		||||
import {profile as dbProfile} from '../../p/db/index.js'
 | 
			
		||||
import {routingModes} from '../../p/db/routing-modes.js'
 | 
			
		||||
import {
 | 
			
		||||
    createValidateStation,
 | 
			
		||||
	createValidateTrip
 | 
			
		||||
| 
						 | 
				
			
			@ -177,6 +178,18 @@ tap.test('journeys: via works – with detour', async (t) => {
 | 
			
		|||
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
 | 
			
		||||
// todo: without detour
 | 
			
		||||
 | 
			
		||||
tap.test('journeys – all routing modes work', async (t) => {
 | 
			
		||||
	for (const mode in routingModes) {
 | 
			
		||||
		await client.journeys(berlinHbf, münchenHbf, {
 | 
			
		||||
			results: 1,
 | 
			
		||||
			departure: when,
 | 
			
		||||
			routingMode: mode,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	t.end()
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
// todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future
 | 
			
		||||
tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
 | 
			
		||||
	await testEarlierLaterJourneys({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	Add table
		
		Reference in a new issue