@@ -107,6 +107,7 @@ const profile = {
107
107
parseJourney,
108
108
parseJourneyLeg,
109
109
parseStopover,
110
+ parseArrivalOrDeparture,
110
111
parseLocation,
111
112
formatDate,
112
113
formatTime
@@ -263,19 +264,20 @@ const tripAlternatives = async (tripCtx, origin, destination) => {
263
264
return res . Trip . map ( parseJourney ( profile , opt ) )
264
265
}
265
266
266
- const departures = async ( stop , opt = { } ) => {
267
+ const _stationBoard = async ( method , stop , opt ) => {
267
268
const stopId = 'string' === typeof stop ? stop : stop . id
268
269
if ( 'string' !== typeof stopId ) {
269
270
throw new TypeError ( 'stop must be a stop object or a string.' )
270
271
}
271
272
272
273
opt = {
273
- direction : null , // only show departures stopping by this station
274
- duration : 10 , // show departures for the next n minutes
275
- results : null , // number of departures – `null` means "whatever HAFAS returns"
274
+ // todo: for arrivals(), this is actually a station it *has already* stopped by
275
+ direction : null , // only show arrivals/departures stopping by this station
276
+ duration : 10 , // show arrivals/departures for the next n minutes
277
+ results : null , // number of arrivals/departures – `null` means "whatever HAFAS returns"
276
278
products : { } , // enabled/disable certain products to search for
277
279
remarks : true , // parse & expose hints & warnings?
278
- // departures at related stations
280
+ // arrivals/ departures at related stations
279
281
// e.g. those that belong together on the metro map.
280
282
includeRelatedStations : true ,
281
283
...opt
@@ -304,20 +306,23 @@ const departures = async (stop, opt = {}) => {
304
306
query . date = profile . formatDate ( profile , when )
305
307
query . time = profile . formatTime ( profile , when )
306
308
307
- const res = await request ( 'departureBoard' , query )
308
- const parse = parseArrivalOrDeparture ( profile , opt , { } )
309
- return res . departureAndMessage ? res . departureAndMessage . map ( d => parse ( d . Departure ) ) : [ ]
309
+ return await request ( method , query )
310
310
}
311
311
312
- const arrivals = async ( stop ) => {
313
- const res = await request ( 'arrivalBoard' , {
314
- extId : '8000152' ,
315
- // todo: direction, date, time, duration, products, operators, lines
316
- // todo: maxJourneys, filterEquiv, attributes, rtMode
317
- } )
312
+ const departures = async ( stop , opt = { } ) => {
313
+ const res = await _stationBoard ( 'departureBoard' , stop , opt )
314
+ const results = res . departureAndMessage || [ ]
315
+
316
+ const parse = profile . parseArrivalOrDeparture ( profile , opt , { } , 'departure' )
317
+ return results . map ( result => parse ( result . Departure ) )
318
+ }
319
+
320
+ const arrivals = async ( stop , opt = { } ) => {
321
+ const res = await _stationBoard ( 'arrivalBoard' , stop , opt )
322
+ const results = res . arrivalAndMessage || [ ]
318
323
319
- const parse = parseArrivalOrDeparture ( profile , opt , { } )
320
- return res . arrivalAndMessage . map ( d => parse ( d . Arrival ) )
324
+ const parse = profile . parseArrivalOrDeparture ( profile , opt , { } , 'arrival' )
325
+ return results . map ( result => parse ( result . Arrival ) )
321
326
}
322
327
323
328
const trip = async ( id ) => {
0 commit comments