Skip to content

Commit

Permalink
move parseSparseTrip to lib/util.js
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Apr 15, 2020
1 parent 75f0eed commit 18718c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
parseOperator,
parseStopover,
normalizeEmpty,
parseSparseTrip,
} = require('./util')
const fetch = require('./fetch')

Expand All @@ -21,18 +22,13 @@ const trip = async (tripId, opt = {}) => {
const [trip] = t.trips

return {
id: t.uid,
...parseSparseTrip(t.uid, trip),
tripType: t.type, // don't conflict with FPTF's `type`
direction: trip.line_direction,
lineName: trip.line_code,
operator: trip.operated_by ? parseOperator(trip.operated_by) : null,
cancelled: trip.is_cancelled === true,
realtimeDataUpdatedAt: (
t.real_time_info && t.real_time_info.status !== 'too_soon'
? parseDateTime(t.real_time_info.updated_at)
: null
),
stopovers: trip.stops.map(st => parseStopover(st)),
hasTracker: normalizeEmpty(trip.has_tracker),
// @todo trip.messages
}
Expand Down
13 changes: 13 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ const parseStopover = (st) => {
}
}

const parseSparseTrip = (id, trip) => {
return {
id,
direction: trip.line_direction,
// @todo fall back to parsing trip.line_direction?
lineName: normalizeEmpty(trip.line_code),
operator: trip.operated_by ? parseOperator(trip.operated_by) : null,
cancelled: normalizeEmpty(trip.is_cancelled),
stopovers: trip.stops ? trip.stops.map(st => parseStopover(st)) : null,
}
}

module.exports = {
formatDateTime,
parseDateTime,
Expand All @@ -113,4 +125,5 @@ module.exports = {
parseOperator,
parseWhen,
parseStopover,
parseSparseTrip,
}

0 comments on commit 18718c5

Please sign in to comment.