mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
move refreshJourneyReq-formatter to own function
This commit is contained in:
parent
542a9eea02
commit
1c67350b48
5 changed files with 40 additions and 10 deletions
18
format/refresh-journey-req.js
Normal file
18
format/refresh-journey-req.js
Normal 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
|
13
index.js
13
index.js
|
@ -249,16 +249,9 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
remarks: true // parse & expose hints & warnings?
|
remarks: true // parse & expose hints & warnings?
|
||||||
}, opt)
|
}, opt)
|
||||||
|
|
||||||
return profile.request({profile, opt}, userAgent, {
|
const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken)
|
||||||
meth: 'Reconstruction',
|
|
||||||
req: {
|
return profile.request({profile, opt}, userAgent, req)
|
||||||
ctxRecon: refreshToken,
|
|
||||||
getIST: true, // todo: make an option
|
|
||||||
getPasslist: !!opt.stopovers,
|
|
||||||
getPolyline: !!opt.polylines,
|
|
||||||
getTariff: !!opt.tickets
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(({res, common}) => {
|
.then(({res, common}) => {
|
||||||
if (!Array.isArray(res.outConL) || !res.outConL[0]) {
|
if (!Array.isArray(res.outConL) || !res.outConL[0]) {
|
||||||
throw new Error('invalid response')
|
throw new Error('invalid response')
|
||||||
|
|
|
@ -9,6 +9,7 @@ const formatNearbyReq = require('../format/nearby-req')
|
||||||
const formatTripReq = require('../format/trip-req')
|
const formatTripReq = require('../format/trip-req')
|
||||||
const formatRadarReq = require('../format/radar-req')
|
const formatRadarReq = require('../format/radar-req')
|
||||||
const formatReachableFromReq = require('../format/reachable-from-req')
|
const formatReachableFromReq = require('../format/reachable-from-req')
|
||||||
|
const formatRefreshJourneyReq = require('../format/refresh-journey-req')
|
||||||
|
|
||||||
const parseDateTime = require('../parse/date-time')
|
const parseDateTime = require('../parse/date-time')
|
||||||
const parsePlatform = require('../parse/platform')
|
const parsePlatform = require('../parse/platform')
|
||||||
|
@ -59,6 +60,7 @@ const defaultProfile = {
|
||||||
formatTripReq,
|
formatTripReq,
|
||||||
formatRadarReq,
|
formatRadarReq,
|
||||||
formatReachableFromReq,
|
formatReachableFromReq,
|
||||||
|
formatRefreshJourneyReq,
|
||||||
transformJourneysQuery: id,
|
transformJourneysQuery: id,
|
||||||
|
|
||||||
parseDateTime,
|
parseDateTime,
|
||||||
|
|
|
@ -15,6 +15,7 @@ const types = {
|
||||||
formatTripReq: 'function',
|
formatTripReq: 'function',
|
||||||
formatRadarReq: 'function',
|
formatRadarReq: 'function',
|
||||||
formatReachableFromReq: 'function',
|
formatReachableFromReq: 'function',
|
||||||
|
formatRefreshJourneyReq: 'function',
|
||||||
transformJourneysQuery: 'function',
|
transformJourneysQuery: 'function',
|
||||||
|
|
||||||
products: 'array',
|
products: 'array',
|
||||||
|
|
|
@ -11,6 +11,21 @@ const transformReqBody = (ctx, body) => {
|
||||||
return 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 = {
|
const vsnProfile = {
|
||||||
locale: 'de-DE',
|
locale: 'de-DE',
|
||||||
timezone: 'Europe/Berlin',
|
timezone: 'Europe/Berlin',
|
||||||
|
@ -22,6 +37,7 @@ const vsnProfile = {
|
||||||
addMicMac: true,
|
addMicMac: true,
|
||||||
|
|
||||||
transformReqBody,
|
transformReqBody,
|
||||||
|
formatRefreshJourneyReq,
|
||||||
|
|
||||||
products: products,
|
products: products,
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue