From 2c04e2f7280df7e809bea9fd1741e4aac0534261 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 20 Jul 2020 16:17:31 +0200 Subject: [PATCH] =?UTF-8?q?journeys:=20async=20fn=20->=20.then,=20don't=20?= =?UTF-8?q?check=20profile.journeysNumF=20=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 9cd2a83e..44a81e23 100644 --- a/index.js +++ b/index.js @@ -82,7 +82,7 @@ const createClient = (profile, userAgent, opt = {}) => { return _stationBoard(station, 'ARR', profile.parseArrival, opt) } - const journeys = async (from, to, opt = {}) => { + const journeys = (from, to, opt = {}) => { from = profile.formatLocation(profile, from, 'from') to = profile.formatLocation(profile, to, 'to') @@ -198,30 +198,29 @@ const createClient = (profile, userAgent, opt = {}) => { query.outDate = profile.formatDate(profile, when) query.outTime = profile.formatTime(profile, when) } - if (profile.journeysNumF && opt.results !== null) query.numF = opt.results + if (opt.results !== null) query.numF = opt.results if (profile.journeysOutFrwd) query.outFrwd = outFrwd - const { - res, common, - } = await profile.request({profile, opt}, userAgent, { + return profile.request({profile, opt}, userAgent, { cfg: {polyEnc: 'GPA'}, meth: 'TripSearch', req: profile.transformJourneysQuery({profile, opt}, query) }) + .then(({res, common}) => { + if (!Array.isArray(res.outConL)) return [] + // todo: outConGrpL - if (!Array.isArray(res.outConL)) return [] - // todo: outConGrpL + const ctx = {profile, opt, common, res} + const journeys = res.outConL + .map(j => profile.parseJourney(ctx, j)) - const ctx = {profile, opt, common, res} - const journeys = res.outConL - .map(j => profile.parseJourney(ctx, j)) - - return { - earlierRef: res.outCtxScrB, - laterRef: res.outCtxScrF, - journeys, - realtimeDataFrom: res.planrtTS ? parseInt(res.planrtTS) : null, - } + return { + earlierRef: res.outCtxScrB, + laterRef: res.outCtxScrF, + journeys, + realtimeDataFrom: res.planrtTS ? parseInt(res.planrtTS) : null, + } + }) } const refreshJourney = (refreshToken, opt = {}) => {