Skip to content

Commit 8023ef8

Browse files
committed
fix: added back mml route
1 parent 07f0bce commit 8023ef8

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/server/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { toJson as xmlToJson } from 'utils/xml2json';
2626
import cdnRouter from './routes/cdn';
2727
import mockDocuSignFactory from './__mocks__/docu-sign-mock';
2828
import recruitCRMRouter from './routes/recruitCRM';
29+
import mmLeaderboardRouter from './routes/mmLeaderboard';
2930

3031
/* Dome API for topcoder communities */
3132
import tcCommunitiesDemoApi from './tc-communities';
@@ -239,6 +240,7 @@ async function onExpressJsSetup(server) {
239240

240241
server.use('/api/cdn', cdnRouter);
241242
server.use('/api/recruit', recruitCRMRouter);
243+
server.use('/api/mml', mmLeaderboardRouter);
242244

243245
// serve demo api
244246
server.use(

src/server/routes/mmLeaderboard.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The routes related to MMLeaderboard integration
3+
*/
4+
5+
import express from 'express';
6+
import MMLService from '../services/mmLeaderboard';
7+
8+
const cors = require('cors');
9+
10+
const routes = express.Router();
11+
12+
// Enables CORS on those routes according config above
13+
// ToDo configure CORS for set of our trusted domains
14+
routes.use(cors());
15+
routes.options('*', cors());
16+
17+
routes.get('/:id', (req, res, next) => new MMLService().getLeaderboard(req, res, next));
18+
19+
export default routes;

src/server/services/mmLeaderboard.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable class-methods-use-this */
2+
/**
3+
* Server-side functions necessary for effective integration with MMLeaderboard
4+
*/
5+
import { services } from 'topcoder-react-lib';
6+
import xss from 'xss';
7+
8+
const { api, submissions } = services;
9+
10+
/**
11+
* Auxiliary class that handles communication with MMLeaderboard
12+
*/
13+
export default class MMLService {
14+
/**
15+
* getLeaderboard endpoint.
16+
* @return {Promise}
17+
* @param {Object} the request.
18+
*/
19+
async getLeaderboard(req, res, next) {
20+
try {
21+
const sanitizedId = xss(req.params.id);
22+
const m2mToken = await api.getTcM2mToken();
23+
const subSrv = submissions.getService(m2mToken);
24+
const reviewIds = await subSrv.getScanReviewIds();
25+
const v5api = api.getApiV5(m2mToken);
26+
const subs = await v5api.get(`/submissions?challengeId=${sanitizedId}&page=1&perPage=500`);
27+
return res.send({
28+
id: sanitizedId,
29+
subs: await subs.json(),
30+
reviewIds,
31+
});
32+
} catch (err) {
33+
return next(err);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)