move refreshJourneyReq-formatter to own function

This commit is contained in:
Simeon Keske 2020-02-07 02:31:51 +01:00 committed by Jannis R
parent 542a9eea02
commit 1c67350b48
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
5 changed files with 40 additions and 10 deletions

View file

@ -0,0 +1,18 @@
'use strict'
const formatRefreshJourneyReq = (ctx, refreshToken) => {
const {profile, opt} = ctx
return {
meth: 'Reconstruction',
req: {
ctxRecon: refreshToken,
getIST: true, // todo: make an option
getPasslist: !!opt.stopovers,
getPolyline: !!opt.polylines,
getTariff: !!opt.tickets
}
}
}
module.exports = formatRefreshJourneyReq

View file

@ -249,16 +249,9 @@ const createClient = (profile, userAgent, opt = {}) => {
remarks: true // parse & expose hints & warnings?
}, opt)
return profile.request({profile, opt}, userAgent, {
meth: 'Reconstruction',
req: {
ctxRecon: refreshToken,
getIST: true, // todo: make an option
getPasslist: !!opt.stopovers,
getPolyline: !!opt.polylines,
getTariff: !!opt.tickets
}
})
const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken)
return profile.request({profile, opt}, userAgent, req)
.then(({res, common}) => {
if (!Array.isArray(res.outConL) || !res.outConL[0]) {
throw new Error('invalid response')

View file

@ -9,6 +9,7 @@ const formatNearbyReq = require('../format/nearby-req')
const formatTripReq = require('../format/trip-req')
const formatRadarReq = require('../format/radar-req')
const formatReachableFromReq = require('../format/reachable-from-req')
const formatRefreshJourneyReq = require('../format/refresh-journey-req')
const parseDateTime = require('../parse/date-time')
const parsePlatform = require('../parse/platform')
@ -59,6 +60,7 @@ const defaultProfile = {
formatTripReq,
formatRadarReq,
formatReachableFromReq,
formatRefreshJourneyReq,
transformJourneysQuery: id,
parseDateTime,

View file

@ -15,6 +15,7 @@ const types = {
formatTripReq: 'function',
formatRadarReq: 'function',
formatReachableFromReq: 'function',
formatRefreshJourneyReq: 'function',
transformJourneysQuery: 'function',
products: 'array',

View file

@ -11,6 +11,21 @@ const transformReqBody = (ctx, body) => {
return body
}
const formatRefreshJourneyReq = (ctx, refreshToken) => {
const {profile, opt} = ctx
return {
meth: 'Reconstruction',
req: {
outReconL: [{ctx: refreshToken}],
getIST: true, // todo: make an option
getPasslist: !!opt.stopovers,
getPolyline: !!opt.polylines,
getTariff: !!opt.tickets
}
}
}
const vsnProfile = {
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -22,6 +37,7 @@ const vsnProfile = {
addMicMac: true,
transformReqBody,
formatRefreshJourneyReq,
products: products,