Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin v3/route by copying v2 into a new v3 #308

Merged
merged 1 commit into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are there so many possible inputs for arriveBy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good question :) it's because people send in all types of random stuff to us so this is a precaution


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;