Skip to content

Commit 3eb060a

Browse files
Added apiProxy to get registrants from challenge
1 parent 6b60d2a commit 3eb060a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/server/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Application from 'shared';
99
import config from 'config';
1010
import express from 'express';
1111
import fetch from 'isomorphic-fetch';
12-
import { logger } from 'topcoder-react-lib';
12+
import { logger, services } from 'topcoder-react-lib';
1313
import fs from 'fs';
1414
import moment from 'moment';
1515
import path from 'path';
@@ -145,6 +145,28 @@ async function onExpressJsSetup(server) {
145145
tcCommunitiesDemoApi,
146146
);
147147

148+
// Get registrants from challenge
149+
server.use(
150+
'/community-app-assets/api/registrants/:challengeId',
151+
async (req, res, next) => {
152+
const tokenM2M = await services.api.getTcM2mToken();
153+
const params = {
154+
challengeId: req.params.challengeId,
155+
roleId: req.query.roleId,
156+
};
157+
const url = `${config.API.V5}/resources?${qs.stringify(params)}`;
158+
try {
159+
let data = await fetch(url, {
160+
headers: { Authorization: `Bearer ${tokenM2M}` },
161+
});
162+
data = await data.text();
163+
res.send(data);
164+
} catch (err) {
165+
next(err);
166+
}
167+
},
168+
);
169+
148170
server.use(
149171
'/community-app-assets/api/edit-contentful-entry/:id',
150172
(req, res) => res.redirect(`${CMS_BASE_URL}/entries/${req.params.id}`),

0 commit comments

Comments
 (0)