Skip to content

Commit

Permalink
fix(modules): use objectPath when accessing MTC props to avoid undefi…
Browse files Browse the repository at this point in the history
…ned erros
  • Loading branch information
landonreed committed Jul 10, 2017
1 parent f2cfe84 commit 729a05c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/common/util/modules.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import objectPath from 'object-path'

import { getConfigProperty } from './config'

export const getFeed = (feeds, id) => {
// console.log(feeds, id)
// TODO: move use_extension to extension enabled??
const useMtc = getConfigProperty('modules.gtfsapi.use_extension') === 'mtc'
const feed = feeds ? feeds.find(f => useMtc ? f.externalProperties.MTC.AgencyId === id : f.id === id) : null
const feed = feeds
? feeds.find(f => useMtc ? objectPath.get(f, 'externalProperties.MTC.AgencyId') === id : f.id === id)
: null
return feed
}

export const getFeedId = (feed) => {
const useMtc = getConfigProperty('modules.gtfsapi.use_extension') === 'mtc'
return !feed ? null : useMtc ? feed.externalProperties.MTC.AgencyId : feed.id
return !feed
? null
: useMtc
? objectPath.get(feed, 'externalProperties.MTC.AgencyId')
: feed.id
}

export const getAlertsUrl = () => {
Expand Down

0 comments on commit 729a05c

Please # to comment.