Skip to content

Commit e2a4188

Browse files
Challenge Details - Get submissions and merge with challenge return
1 parent dc5c430 commit e2a4188

File tree

2 files changed

+76
-19
lines changed

2 files changed

+76
-19
lines changed

src/services/challenges.js

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
1313
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
1414
import { getApi } from './api';
1515
import { getService as getMembersService } from './members';
16+
import { getService as getSubmissionsService } from './submissions';
1617

1718
export const ORDER_BY = {
1819
SUBMISSION_END_DATE: 'submissionEndDate',
@@ -203,6 +204,7 @@ class ChallengesService {
203204
tokenV2,
204205
tokenV3,
205206
memberService: getMembersService(),
207+
submissionsService: getSubmissionsService(tokenV3),
206208
};
207209
}
208210

@@ -327,8 +329,11 @@ class ChallengesService {
327329
async getChallengeDetails(challengeId) {
328330
const memberId = this.private.tokenV3 ? decodeToken(this.private.tokenV3).userId : null;
329331
let challenge = {};
332+
let registrants = [];
333+
let submissions = [];
330334
let isLegacyChallenge = false;
331335
let isRegistered = false;
336+
332337
// condition based on ROUTE used for Review Opportunities, change if needed
333338
if (/^[\d]{5,8}$/.test(challengeId)) {
334339
isLegacyChallenge = true;
@@ -339,28 +344,59 @@ class ChallengesService {
339344
.then(res => res.challenges);
340345
}
341346

342-
let registrants = await this.getChallengeRegistrants(challenge.id);
343-
// This TEMP fix to colorStyle, this will be fixed with issue #4530
344-
registrants = _.map(registrants, r => ({
345-
...r, colorStyle: 'color: #151516',
346-
}));
347-
challenge.registrants = registrants;
347+
if (challenge) {
348+
registrants = await this.getChallengeRegistrants(challenge.id);
349+
350+
// This TEMP fix to colorStyle, this will be fixed with issue #4530
351+
registrants = _.map(registrants, r => ({
352+
...r, colorStyle: 'color: #151516',
353+
}));
354+
355+
/* Prepare data to logged user */
356+
if (memberId) {
357+
isRegistered = _.some(registrants, r => r.memberId === memberId);
358+
359+
/**
360+
* TODO: Currenlty using legacyId until submissions_api fix issue with UUID
361+
*/
362+
const subParams = {
363+
challengeId: challenge.legacyId,
364+
perPage: 100,
365+
};
366+
submissions = await this.private.submissionsService.getSubmissions(subParams);
367+
368+
if (submissions) {
369+
// Remove AV Scan, SonarQube Review and Virus Scan review types
370+
const reviewScans = await this.private.submissionsService.getScanReviewIds();
371+
submissions.forEach((s, i) => {
372+
submissions[i].review = _.reject(s.review, r => _.includes(reviewScans, r.typeId));
373+
});
374+
375+
// Add submission date to registrants
376+
registrants.forEach((r, i) => {
377+
const submission = submissions.find(s => s.memberId === Number(r.memberId));
378+
if (submission) {
379+
registrants[i].submissionDate = submission.created;
380+
}
381+
});
382+
}
383+
}
348384

349-
if (memberId) {
350-
isRegistered = _.some(registrants, r => r.memberId === memberId);
385+
challenge = {
386+
...challenge,
387+
isLegacyChallenge,
388+
isRegistered,
389+
registrants,
390+
submissions,
391+
events: _.map(challenge.events, e => ({
392+
eventName: e.key,
393+
eventId: e.id,
394+
description: e.name,
395+
})),
396+
fetchedWithAuth: Boolean(this.private.apiV5.private.token),
397+
};
351398
}
352399

353-
challenge.isLegacyChallenge = isLegacyChallenge;
354-
challenge.isRegistered = isRegistered;
355-
356-
challenge.events = _.map(challenge.events, e => ({
357-
eventName: e.key,
358-
eventId: e.id,
359-
description: e.name,
360-
}));
361-
362-
challenge.fetchedWithAuth = Boolean(this.private.apiV5.private.token);
363-
364400
return challenge;
365401
}
366402

src/services/submissions.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @desc This module provides a service for convenient manipulation with
44
* Topcoder submissions via TC API. Currently only used for MM challenges
55
*/
6+
import _ from 'lodash';
67
import qs from 'qs';
78
import { getApi } from './api';
89

@@ -39,6 +40,26 @@ class SubmissionsService {
3940
.then(res => res);
4041
}
4142

43+
/**
44+
* Get scan reviews types
45+
* @returns {Promise} Resolves to the api response.
46+
*/
47+
async getScanReviewIds() {
48+
const reviews = await Promise.all([
49+
this.private.apiV5.get('/reviewTypes?name=AV Scan')
50+
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
51+
.then(res => res),
52+
this.private.apiV5.get('/reviewTypes?name=SonarQube Review')
53+
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
54+
.then(res => res),
55+
this.private.apiV5.get('/reviewTypes?name=Virus Scan')
56+
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
57+
.then(res => res),
58+
]).then(([av, sonar, virus]) => (_.concat(av, sonar, virus)));
59+
60+
return reviews.map(r => r.id);
61+
}
62+
4263
/**
4364
* Get submission information by submission id
4465
* @param submissionId The submission id

0 commit comments

Comments
 (0)