Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add routingModes option to db profile #295

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/db-routing-modes.js
Original file line number Diff line number Diff line change
@@ -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,
}
4 changes: 3 additions & 1 deletion p/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ 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 '../../lib/db-routing-modes.js'

const transformReqBody = (ctx, body) => {
const req = body.svcReqL[0] || {}

// see https://pastebin.com/qZ9WS3Cx
req.cfg = {...req.cfg, rtMode: 'REALTIME'}
const routingMode = ('routingMode' in ctx.opt) ? ctx.opt.routingMode : routingModes.REALTIME
req.cfg = {...req.cfg, rtMode: routingMode}

return body
}
Expand Down
12 changes: 12 additions & 0 deletions p/db/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 as routingModes} from 'hafas-client/lib/db-routing-modes.js'

hafas.journeys(from, to, {
routingMode: routingModes.HYBRID
})
```
22 changes: 22 additions & 0 deletions test/e2e/db-routing-modes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import tap from 'tap'

import {createClient} from '../../index.js'
import {profile as dbProfile} from '../../p/db/index.js'
import {routingModes as routingModes} from '../../lib/db-routing-modes.js'

const client = createClient(dbProfile, 'public-transport/hafas-client:test')

const berlinHbf = '8011160'
const münchenHbf = '8000261'

tap.test('journeys – check all routing modes', async (t) => {
for (let mode in routingModes) {
const res = await client.journeys(berlinHbf, münchenHbf,
{
results: 1, tickets: true, routingMode: mode
}
)
}

t.end()
})
Loading