Skip to content

Commit 9396cf3

Browse files
committed
feat: use count api
1 parent 9e6563e commit 9396cf3

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

app-routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ module.exports = (app) => {
108108
}
109109
});
110110
}
111+
actions.push(method);
111112
actions.push((req, res, next) => {
112113
logger.info(`Done request handling, ${req.signature}`);
113114
next();
114115
});
115-
actions.push(method);
116116
app[verb](`/${config.API_VERSION}${path}`, helper.autoWrapExpress(actions));
117117
});
118118
});

src/common/helper.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,22 @@ async function getChallengeResources(challengeId, roleId = null) {
253253
return result;
254254
}
255255

256+
/**
257+
* Get challenge resources count
258+
* @param {String} challengeId the challenge id
259+
* @returns {Promise<Object>} the challenge resources count
260+
*/
261+
async function getChallengeResourcesCount(challengeId, roleId = null) {
262+
const token = await m2mHelper.getM2MToken();
263+
const url = `${config.RESOURCES_API_URL}/count?challengeId=${challengeId}${
264+
roleId ? `&roleId=${roleId}` : ""
265+
}`;
266+
const res = await axios.get(url, {
267+
headers: { Authorization: `Bearer ${token}` },
268+
});
269+
return res.data;
270+
}
271+
256272
/**
257273
* Create challenge resources
258274
* @param {String} challengeId the challenge id
@@ -1053,6 +1069,19 @@ async function getChallengeSubmissions(challengeId) {
10531069
return allSubmissions;
10541070
}
10551071

1072+
/**
1073+
* Get challenge submissions count
1074+
* @param {String} challengeId the challenge id
1075+
* @returns {Promise<Object>} the submission counts
1076+
*/
1077+
async function getChallengeSubmissionsCount(challengeId) {
1078+
const token = await m2mHelper.getM2MToken();
1079+
const res = await axios.get(`${config.SUBMISSIONS_API_URL}/${challengeId}/count`, {
1080+
headers: { Authorization: `Bearer ${token}` },
1081+
});
1082+
return res.data;
1083+
}
1084+
10561085
/**
10571086
* Get member by ID
10581087
* @param {String} userId the user ID
@@ -1183,6 +1212,7 @@ module.exports = {
11831212
downloadFromS3,
11841213
deleteFromS3,
11851214
getChallengeResources,
1215+
getChallengeResourcesCount,
11861216
createResource,
11871217
getUserGroups,
11881218
ensureNoDuplicateOrNullElements,
@@ -1206,6 +1236,7 @@ module.exports = {
12061236
getProjectIdByRoundId,
12071237
getGroupById,
12081238
getChallengeSubmissions,
1239+
getChallengeSubmissionsCount,
12091240
getMemberById,
12101241
createSelfServiceProject,
12111242
activateProject,

src/phase-management/PhaseAdvancer.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,18 @@ class PhaseAdvancer {
274274
async #getRegistrantCount(challengeId) {
275275
console.log(`Getting registrant count for challenge ${challengeId}`);
276276
// TODO: getChallengeResources loops through all pages, which is not necessary here, we can just get the first page and total count from header[X-Total]
277-
const submitters = await helper.getChallengeResources(challengeId, config.SUBMITTER_ROLE_ID);
278-
return submitters.length;
277+
const submitters = await helper.getChallengeResourcesCount(
278+
challengeId,
279+
config.SUBMITTER_ROLE_ID
280+
);
281+
return submitters[config.SUBMITTER_ROLE_ID] || 0;
279282
}
280283

281284
async #getSubmissionCount(challengeId) {
282285
console.log(`Getting submission count for challenge ${challengeId}`);
283286
// TODO: getChallengeSubmissions loops through all pages, which is not necessary here, we can just get the first page and total count from header[X-Total]
284-
const submissions = await helper.getChallengeSubmissions(challengeId);
285-
return submissions.length;
287+
const submissions = await helper.getChallengeSubmissionsCount(challengeId);
288+
return submissions["Contest Submission"] || 0;
286289
}
287290

288291
async #areAllSubmissionsReviewed(challengeId) {

0 commit comments

Comments
 (0)