Skip to content

Commit d13c603

Browse files
authored
Merge pull request #197 from topcoder-platform/issue-4536
Issue4536 - Challenge Details - Get submissions and merge with challenge return
2 parents a4f81b3 + e2a4188 commit d13c603

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',
@@ -197,6 +198,7 @@ class ChallengesService {
197198
tokenV2,
198199
tokenV3,
199200
memberService: getMembersService(),
201+
submissionsService: getSubmissionsService(tokenV3),
200202
};
201203
}
202204

@@ -321,8 +323,11 @@ class ChallengesService {
321323
async getChallengeDetails(challengeId) {
322324
const memberId = this.private.tokenV3 ? decodeToken(this.private.tokenV3).userId : null;
323325
let challenge = {};
326+
let registrants = [];
327+
let submissions = [];
324328
let isLegacyChallenge = false;
325329
let isRegistered = false;
330+
326331
// condition based on ROUTE used for Review Opportunities, change if needed
327332
if (/^[\d]{5,8}$/.test(challengeId)) {
328333
isLegacyChallenge = true;
@@ -333,28 +338,59 @@ class ChallengesService {
333338
.then(res => res.challenges);
334339
}
335340

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

343-
if (memberId) {
344-
isRegistered = _.some(registrants, r => r.memberId === memberId);
379+
challenge = {
380+
...challenge,
381+
isLegacyChallenge,
382+
isRegistered,
383+
registrants,
384+
submissions,
385+
events: _.map(challenge.events, e => ({
386+
eventName: e.key,
387+
eventId: e.id,
388+
description: e.name,
389+
})),
390+
fetchedWithAuth: Boolean(this.private.apiV5.private.token),
391+
};
345392
}
346393

347-
challenge.isLegacyChallenge = isLegacyChallenge;
348-
challenge.isRegistered = isRegistered;
349-
350-
challenge.events = _.map(challenge.events, e => ({
351-
eventName: e.key,
352-
eventId: e.id,
353-
description: e.name,
354-
}));
355-
356-
challenge.fetchedWithAuth = Boolean(this.private.apiV5.private.token);
357-
358394
return challenge;
359395
}
360396

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)