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:
Milan 2019-01-06 15:59:00 +01:00 committed by Jannis R
parent cb535cdabe
commit fcc53b5d2a
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -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