Skip to content

Commit

Permalink
Copy v2 into a new v3 (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanna-zhou authored Oct 11, 2020
1 parent 37c8b10 commit 133e2dd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class API extends ApplicationAPI {
...sharedRouters,
Routers.RouteV2Router,
],
v3: [
...sharedRouters,
Routers.RouteV3Router,
],
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/routers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PlaceIDCoordinatesRouter from './v1/PlaceIDCoordinatesRouter';
import RouteRouter from './v1/RouteRouter';
import RouteSelectedRouter from './v1/RouteSelectedRouter';
import RouteV2Router from './v2/RouteRouter';
import RouteV3Router from './v3/RouteRouter';
import SearchRouter from './v1/SearchRouter';
import TrackingRouter from './v1/TrackingRouter';

Expand All @@ -30,6 +31,7 @@ export default {
RouteRouter,
RouteSelectedRouter,
RouteV2Router,
RouteV3Router,
SearchRouter,
TrackingRouter,
};
61 changes: 61 additions & 0 deletions src/routers/v3/RouteRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// @flow
import type Request from 'express';
import AnalyticsUtils from '../../utils/AnalyticsUtils';
import ApplicationRouter from '../../appdev/ApplicationRouter';
import LogUtils from '../../utils/LogUtils';
import RouteUtils from '../../utils/RouteUtils';

class RouteRouter extends ApplicationRouter<Object> {
constructor() {
super(['POST']);
}

getPath(): string {
return '/route/';
}

async content(req: Request): Promise<Object> {
const {
destinationName,
end,
arriveBy,
originName,
start,
time,
uid,
} = req.body;

const isArriveBy = (arriveBy === '1' || arriveBy === true || arriveBy === 'true' || arriveBy === 'True');

const isOriginBusStop = await RouteUtils.isBusStop(originName);
const originBusStopName = isOriginBusStop ? originName : null;
const sectionedRoutes = await RouteUtils.getSectionedRoutes(
originName,
destinationName,
end,
start,
time,
isArriveBy,
originBusStopName,
);
const routes = RouteUtils.flatten(Object.values(sectionedRoutes));
if (routes.length > 0) {
const request = {
isArriveBy,
destinationName,
end: routes[0].endCoords,
originName,
routeId: routes[0].routeId,
start: routes[0].startCoords,
time,
uid,
};
LogUtils.log({ category: 'routeRequest', request });
}
AnalyticsUtils.assignRouteIdsAndCache(routes);

return sectionedRoutes;
}
}

export default new RouteRouter().router;

0 comments on commit 133e2dd

Please sign in to comment.