mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
fix journeys collection 🐛
This commit is contained in:
parent
7fd574f0f8
commit
8ae3fe2236
1 changed files with 12 additions and 8 deletions
20
index.js
20
index.js
|
@ -110,6 +110,9 @@ const createClient = (profile, request = _request) => {
|
||||||
const journeys = []
|
const journeys = []
|
||||||
const more = (when, journeysRef) => {
|
const more = (when, journeysRef) => {
|
||||||
const query = {
|
const query = {
|
||||||
|
outDate: profile.formatDate(profile, when),
|
||||||
|
outTime: profile.formatTime(profile, when),
|
||||||
|
ctxScr: journeysRef,
|
||||||
// numF: opt.results,
|
// numF: opt.results,
|
||||||
getPasslist: !!opt.passedStations,
|
getPasslist: !!opt.passedStations,
|
||||||
maxChg: opt.transfers,
|
maxChg: opt.transfers,
|
||||||
|
@ -126,12 +129,6 @@ const createClient = (profile, request = _request) => {
|
||||||
getIV: false, // todo: walk & bike as alternatives?
|
getIV: false, // todo: walk & bike as alternatives?
|
||||||
getPolyline: false // todo: shape for displaying on a map?
|
getPolyline: false // todo: shape for displaying on a map?
|
||||||
}
|
}
|
||||||
if (when) {
|
|
||||||
query.outDate = profile.formatDate(profile, when)
|
|
||||||
query.outTime = profile.formatTime(profile, when)
|
|
||||||
} else if (journeysRef) {
|
|
||||||
query.ctxScr = journeysRef
|
|
||||||
} else throw new Error('when or ref required')
|
|
||||||
|
|
||||||
return request(profile, {
|
return request(profile, {
|
||||||
cfg: {polyEnc: 'GPA'},
|
cfg: {polyEnc: 'GPA'},
|
||||||
|
@ -143,14 +140,21 @@ const createClient = (profile, request = _request) => {
|
||||||
const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks)
|
const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks)
|
||||||
if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB
|
if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB
|
||||||
|
|
||||||
|
let latestDep = -Infinity
|
||||||
for (let j of d.outConL) {
|
for (let j of d.outConL) {
|
||||||
journeys.push(parse(j))
|
j = parse(j)
|
||||||
|
journeys.push(j)
|
||||||
|
|
||||||
if (journeys.length === opt.results) { // collected enough
|
if (journeys.length === opt.results) { // collected enough
|
||||||
journeys.laterRef = d.outCtxScrF
|
journeys.laterRef = d.outCtxScrF
|
||||||
return journeys
|
return journeys
|
||||||
}
|
}
|
||||||
|
const dep = +new Date(j.departure)
|
||||||
|
if (dep > latestDep) latestDep = dep
|
||||||
}
|
}
|
||||||
return more(null, d.outCtxScrF) // otherwise continue
|
|
||||||
|
const when = new Date(latestDep)
|
||||||
|
return more(when, d.outCtxScrF) // otherwise continue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue