File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class API extends ApplicationAPI {
2323 Routers . MultiRouteRouter ,
2424 Routers . PlacesAutocompleteRouter ,
2525 Routers . PlaceIDCoordinatesRouter ,
26+ Routers . RouteSelectedRouter ,
2627 Routers . SearchRouter ,
2728 ] ;
2829 return {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import MultiRouteRouter from './v1/MultiRouteRouter';
1111import PlacesAutocompleteRouter from './v1/PlacesAutocompleteRouter' ;
1212import PlaceIDCoordinatesRouter from './v1/PlaceIDCoordinatesRouter' ;
1313import RouteRouter from './v1/RouteRouter' ;
14+ import RouteSelectedRouter from './v1/RouteSelectedRouter' ;
1415import RouteV2Router from './v2/RouteRouter' ;
1516import RouteV3Router from './v3/RouteRouter' ;
1617import SearchRouter from './v1/SearchRouter' ;
@@ -31,6 +32,7 @@ export default {
3132 PlacesAutocompleteRouter,
3233 PlaceIDCoordinatesRouter,
3334 RouteRouter,
35+ RouteSelectedRouter,
3436 RouteV2Router,
3537 RouteV3Router,
3638 SearchRouter,
Original file line number Diff line number Diff line change 11// @flow
22import type Request from 'express' ;
3+ import AnalyticsUtils from '../../utils/AnalyticsUtils' ;
34import ApplicationRouter from '../../appdev/ApplicationRouter' ;
45import LogUtils from '../../utils/LogUtils' ;
56import RouteUtils from '../../utils/RouteUtils' ;
@@ -42,6 +43,8 @@ class RouteRouter extends ApplicationRouter<Array<Object>> {
4243 } ;
4344 LogUtils . log ( { category : 'routeRequestWithTransfer' , request } ) ;
4445 }
46+ AnalyticsUtils . assignRouteIdsAndCache ( routes ) ;
47+
4548 return routes ;
4649 }
4750}
Original file line number Diff line number Diff line change 1+ // @flow
2+ import type Request from 'express' ;
3+ import ApplicationRouter from '../../appdev/ApplicationRouter' ;
4+
5+ class RouteSelectedRouter extends ApplicationRouter < Array < Object >> {
6+ constructor ( ) {
7+ super ( [ 'POST' ] ) ;
8+ }
9+
10+ getPath ( ) : string {
11+ return '/routeSelected/' ;
12+ }
13+
14+ // eslint-disable-next-line require-await
15+ async content ( req : Request ) : Promise < any > {
16+ return null ;
17+ }
18+ }
19+
20+ export default new RouteSelectedRouter ( ) . router ;
Original file line number Diff line number Diff line change 11// @flow
22import type Request from 'express' ;
3+ import AnalyticsUtils from '../../utils/AnalyticsUtils' ;
34import ApplicationRouter from '../../appdev/ApplicationRouter' ;
45import LogUtils from '../../utils/LogUtils' ;
56import RouteUtils from '../../utils/RouteUtils' ;
@@ -44,13 +45,14 @@ class RouteRouter extends ApplicationRouter<Object> {
4445 destinationName,
4546 end : routes [ 0 ] . endCoords ,
4647 originName,
47- routeId : routes [ 0 ] . routeId ,
48+ routeId : null ,
4849 start : routes [ 0 ] . startCoords ,
4950 time,
5051 uid,
5152 } ;
5253 LogUtils . log ( { category : 'routeRequest' , request } ) ;
5354 }
55+ AnalyticsUtils . assignRouteIdsAndCache ( routes ) ;
5456 return sectionedRoutes ;
5557 }
5658}
Original file line number Diff line number Diff line change 1+ // @flow
2+ import crypto from 'crypto' ;
3+
4+ function getUniqueId ( numBytes : ?number = 10 ) {
5+ return crypto . randomBytes ( numBytes ) . toString ( 'hex' ) ;
6+ }
7+
8+ function assignRouteIdsAndCache ( routeRes : Object [ ] ) {
9+ routeRes . forEach ( ( route ) => {
10+ route . routeId = getUniqueId ( ) ;
11+ } ) ;
12+ }
13+
14+ export default {
15+ getUniqueId,
16+ assignRouteIdsAndCache,
17+ } ;
Original file line number Diff line number Diff line change @@ -23,17 +23,14 @@ async function fetchVehicles(): Object {
2323}
2424
2525/**
26- * Given an array of { routeID, tripID },
26+ * Given an array of { routeId, tripId },
2727 * Return bus information
2828 * Input:[
2929 * {
30- * routeID : String,
31- * tripID : String
30+ * routeId : String,
31+ * tripId : String
3232 * },... ]
33- * NOTE: Because we need to provide backwards compatibility with old iOS clients
34- * we have to follow their janky way of routeID input is String but routeID
35- * output is Number. This "routeID" is also named jankily, which is supposed to
36- * be routeNumber from v2/route/. We cast this to Number in getVehicleInformation.
33+ * Corresponds to GTFS RouteId and TripId.
3734 *
3835 *
3936 */
@@ -116,6 +113,7 @@ function getVehicleInformation(
116113 return null ;
117114 }
118115 const vehicleData = Object . values ( vehicles ) . find (
116+ // Naming here is routeID and tripID due to how the microservice names fields
119117 v => ( v . routeID === routeId ) && ( v . tripID === tripId ) ,
120118 ) ;
121119 if ( ! vehicleData ) {
You can’t perform that action at this time.
0 commit comments