mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
journeys: return object with journeys, earlierRef, laterRef 💥
Previously, an array with additional attributes `earlierRef` and `laterRef` was returned. When JSON-stringified, the attributes were missing.
This commit is contained in:
parent
cb535cdabe
commit
fcc53b5d2a
1 changed files with 8 additions and 3 deletions
11
index.js
11
index.js
|
@ -185,6 +185,7 @@ const createClient = (profile, userAgent, request = _request) => {
|
||||||
// until we have enough.
|
// until we have enough.
|
||||||
// todo: revert this change, see https://github.com/public-transport/hafas-client/issues/76#issuecomment-424448449
|
// todo: revert this change, see https://github.com/public-transport/hafas-client/issues/76#issuecomment-424448449
|
||||||
const journeys = []
|
const journeys = []
|
||||||
|
let earlierRef, laterRef
|
||||||
const more = (when, journeysRef) => {
|
const more = (when, journeysRef) => {
|
||||||
const query = {
|
const query = {
|
||||||
outDate: profile.formatDate(profile, when),
|
outDate: profile.formatDate(profile, when),
|
||||||
|
@ -224,7 +225,7 @@ const createClient = (profile, userAgent, request = _request) => {
|
||||||
polylines: opt.polylines && d.common.polyL || []
|
polylines: opt.polylines && d.common.polyL || []
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB
|
if (!earlierRef) earlierRef = d.outCtxScrB
|
||||||
|
|
||||||
let latestDep = -Infinity
|
let latestDep = -Infinity
|
||||||
for (let j of d.outConL) {
|
for (let j of d.outConL) {
|
||||||
|
@ -232,8 +233,12 @@ const createClient = (profile, userAgent, request = _request) => {
|
||||||
journeys.push(j)
|
journeys.push(j)
|
||||||
|
|
||||||
if (journeys.length >= opt.results) { // collected enough
|
if (journeys.length >= opt.results) { // collected enough
|
||||||
journeys.laterRef = d.outCtxScrF
|
laterRef = d.outCtxScrF
|
||||||
return journeys
|
return {
|
||||||
|
earlierRef,
|
||||||
|
laterRef,
|
||||||
|
journeys
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const dep = +new Date(j.legs[0].departure)
|
const dep = +new Date(j.legs[0].departure)
|
||||||
if (dep > latestDep) latestDep = dep
|
if (dep > latestDep) latestDep = dep
|
||||||
|
|
Loading…
Add table
Reference in a new issue