Skip to content

Commit e4d4848

Browse files
author
David Emory
committed
feat(api): Consider modes when constructing profile API requests
1 parent 821a3f4 commit e4d4848

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/actions/api.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if (typeof (fetch) === 'undefined') {
99
}
1010

1111
import { queryIsValid } from '../util/state'
12+
import { isTransit, isAccessMode, isCar } from '../util/itinerary'
1213

1314
// Itinerary Query
1415

@@ -113,6 +114,22 @@ export function profileTrip (customOtpQueryBuilder) {
113114
function constructProfileQuery (api, query) {
114115
const planEndpoint = `${api.host}${api.port ? ':' + api.port : ''}${api.path}/plan`
115116
const { mode, startTime, endTime, date } = query
117+
118+
const accessModes = []
119+
const directModes = []
120+
const transitModes = []
121+
122+
if (mode && mode.length > 0) {
123+
mode.split(',').forEach(m => {
124+
if (isTransit(m)) transitModes.push(m)
125+
if (isAccessMode(m)) {
126+
accessModes.push(m)
127+
// make configurable whether direct-driving is considered
128+
if (!isCar(m)) directModes.push(m)
129+
}
130+
})
131+
}
132+
116133
const params = {
117134
date,
118135
startTime,
@@ -125,9 +142,9 @@ function constructProfileQuery (api, query) {
125142
lat: query.to.lat,
126143
lon: query.to.lon
127144
},
128-
accessModes: 'WALK,BICYCLE',
129-
directModes: 'WALK,BICYCLE,BICYCLE_RENT',
130-
transitModes: 'BUS,TRAM'
145+
accessModes: accessModes.join(','),
146+
directModes: directModes.join(','),
147+
transitModes: transitModes.join(',')
131148
}
132149
const stringParams = qs.stringify(params)
133150
// TODO: set url hash based on params

lib/util/itinerary.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ export function isBicycle (mode) {
2121
return mode === 'BICYCLE'
2222
}
2323

24+
export function isBicycleRent (mode) {
25+
mode = mode || this.get('mode')
26+
return mode === 'BICYCLE_RENT'
27+
}
28+
2429
export function isCar (mode) {
2530
mode = mode || this.get('mode')
2631
return mode === 'CAR'
2732
}
2833

34+
export function isAccessMode (mode) {
35+
return isWalk(mode) || isBicycle(mode) || isBicycleRent(mode) || isCar(mode)
36+
}
37+
2938
export function getMapColor (mode) {
3039
mode = mode || this.get('mode')
3140
if (mode === 'WALK') return '#444'

0 commit comments

Comments
 (0)