mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
journeys: opt.when -> opt.departure/opt.arrival 💥
This commit is contained in:
parent
a356a26e2f
commit
c82ad234e0
2 changed files with 23 additions and 9 deletions
|
@ -40,7 +40,10 @@ With `opt`, you can override the default options, which look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
when: new Date(),
|
// Use either `departure` or `arrival` to specify a date/time.
|
||||||
|
departure: new Date(),
|
||||||
|
arrival: null,
|
||||||
|
|
||||||
earlierThan: null, // ref to get journeys earlier than the last query
|
earlierThan: null, // ref to get journeys earlier than the last query
|
||||||
laterThan: null, // ref to get journeys later than the last query
|
laterThan: null, // ref to get journeys later than the last query
|
||||||
results: 5, // how many journeys?
|
results: 5, // how many journeys?
|
||||||
|
|
27
index.js
27
index.js
|
@ -69,8 +69,8 @@ const createClient = (profile, request = _request) => {
|
||||||
if (!isNonEmptyString(opt.earlierThan)) {
|
if (!isNonEmptyString(opt.earlierThan)) {
|
||||||
throw new Error('opt.earlierThan must be a non-empty string.')
|
throw new Error('opt.earlierThan must be a non-empty string.')
|
||||||
}
|
}
|
||||||
if ('when' in opt) {
|
if (('departure' in opt) || ('arrival' in opt)) {
|
||||||
throw new Error('opt.earlierThan and opt.when are mutually exclusive.')
|
throw new Error('opt.earlierThan and opt.departure/opt.arrival are mutually exclusive.')
|
||||||
}
|
}
|
||||||
journeysRef = opt.earlierThan
|
journeysRef = opt.earlierThan
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,8 @@ const createClient = (profile, request = _request) => {
|
||||||
if (!isNonEmptyString(opt.laterThan)) {
|
if (!isNonEmptyString(opt.laterThan)) {
|
||||||
throw new Error('opt.laterThan must be a non-empty string.')
|
throw new Error('opt.laterThan must be a non-empty string.')
|
||||||
}
|
}
|
||||||
if ('when' in opt) {
|
if (('departure' in opt) || ('arrival' in opt)) {
|
||||||
throw new Error('opt.laterThan and opt.when are mutually exclusive.')
|
throw new Error('opt.laterThan and opt.departure/opt.arrival are mutually exclusive.')
|
||||||
}
|
}
|
||||||
journeysRef = opt.laterThan
|
journeysRef = opt.laterThan
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,19 @@ const createClient = (profile, request = _request) => {
|
||||||
polylines: false // return leg shapes?
|
polylines: false // return leg shapes?
|
||||||
}, opt)
|
}, opt)
|
||||||
if (opt.via) opt.via = profile.formatLocation(profile, opt.via, 'opt.via')
|
if (opt.via) opt.via = profile.formatLocation(profile, opt.via, 'opt.via')
|
||||||
opt.when = new Date(opt.when || Date.now())
|
|
||||||
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
|
if (opt.when !== undefined) {
|
||||||
|
throw new Error('opt.when is not supported anymore. Use opt.departure/opt.arrival.')
|
||||||
|
}
|
||||||
|
let when = new Date(), outFrwd = true
|
||||||
|
if (opt.departure !== undefined && opt.departure !== null) {
|
||||||
|
when = new Date(opt.departure)
|
||||||
|
if (Number.isNaN(+when)) throw new Error('opt.departure is invalid')
|
||||||
|
} else if (opt.arrival !== undefined && opt.arrival !== null) {
|
||||||
|
when = new Date(opt.arrival)
|
||||||
|
if (Number.isNaN(+when)) throw new Error('opt.arrival is invalid')
|
||||||
|
outFrwd = false
|
||||||
|
}
|
||||||
|
|
||||||
const filters = [
|
const filters = [
|
||||||
profile.formatProductsFilter(opt.products || {})
|
profile.formatProductsFilter(opt.products || {})
|
||||||
|
@ -132,10 +143,10 @@ const createClient = (profile, request = _request) => {
|
||||||
arrLocL: [to],
|
arrLocL: [to],
|
||||||
jnyFltrL: filters,
|
jnyFltrL: filters,
|
||||||
getTariff: !!opt.tickets,
|
getTariff: !!opt.tickets,
|
||||||
|
outFrwd,
|
||||||
|
|
||||||
// todo: what is req.gisFltrL?
|
// todo: what is req.gisFltrL?
|
||||||
getPT: true, // todo: what is this?
|
getPT: true, // todo: what is this?
|
||||||
outFrwd: true, // todo: what is this?
|
|
||||||
getIV: false, // todo: walk & bike as alternatives?
|
getIV: false, // todo: walk & bike as alternatives?
|
||||||
getPolyline: !!opt.polylines
|
getPolyline: !!opt.polylines
|
||||||
}
|
}
|
||||||
|
@ -172,7 +183,7 @@ const createClient = (profile, request = _request) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return more(opt.when, journeysRef)
|
return more(when, journeysRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
const locations = (query, opt = {}) => {
|
const locations = (query, opt = {}) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue