Skip to content

Commit 7e89f22

Browse files
Merge pull request #159 from nursoltan-s/feature-challenge-v5
fix for challenge 30122528
2 parents b524069 + 0d9c3ed commit 7e89f22

File tree

5 files changed

+116
-115
lines changed

5 files changed

+116
-115
lines changed

dist/dev/index.js

Lines changed: 64 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/services.challenges.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This module provides a service for convenient manipulation with
1818
* [.close(challengeId, winnerId)](#module_services.challenges..ChallengesService+close) ⇒ <code>Promise</code>
1919
* [.createTask(projectId, accountId, title, description, assignee, payment)](#module_services.challenges..ChallengesService+createTask) ⇒ <code>Promise</code>
2020
* [.getChallengeDetails(challengeId)](#module_services.challenges..ChallengesService+getChallengeDetails) ⇒ <code>Promise</code>
21-
* [.getChallengeSubtracks()](#module_services.challenges..ChallengesService+getChallengeSubtracks) ⇒ <code>Promise</code>
21+
* [.getChallengeTypes()](#module_services.challenges..ChallengesService+getChallengeTypes) ⇒ <code>Promise</code>
2222
* [.getChallengeTags()](#module_services.challenges..ChallengesService+getChallengeTags) ⇒ <code>Promise</code>
2323
* [.getChallenges(filters, params)](#module_services.challenges..ChallengesService+getChallenges) ⇒ <code>Promise</code>
2424
* [.getMarathonMatches(filters, params)](#module_services.challenges..ChallengesService+getMarathonMatches) ⇒ <code>Promise</code>
@@ -119,7 +119,7 @@ Challenge service.
119119
* [.close(challengeId, winnerId)](#module_services.challenges..ChallengesService+close) ⇒ <code>Promise</code>
120120
* [.createTask(projectId, accountId, title, description, assignee, payment)](#module_services.challenges..ChallengesService+createTask) ⇒ <code>Promise</code>
121121
* [.getChallengeDetails(challengeId)](#module_services.challenges..ChallengesService+getChallengeDetails) ⇒ <code>Promise</code>
122-
* [.getChallengeSubtracks()](#module_services.challenges..ChallengesService+getChallengeSubtracks) ⇒ <code>Promise</code>
122+
* [.getChallengeTypes()](#module_services.challenges..ChallengesService+getChallengeTypes) ⇒ <code>Promise</code>
123123
* [.getChallengeTags()](#module_services.challenges..ChallengesService+getChallengeTags) ⇒ <code>Promise</code>
124124
* [.getChallenges(filters, params)](#module_services.challenges..ChallengesService+getChallenges) ⇒ <code>Promise</code>
125125
* [.getMarathonMatches(filters, params)](#module_services.challenges..ChallengesService+getMarathonMatches) ⇒ <code>Promise</code>
@@ -203,9 +203,9 @@ incorrect in the main v3 endpoint. This may change in the future.
203203
| --- | --- |
204204
| challengeId | <code>Number</code> \| <code>String</code> |
205205

206-
<a name="module_services.challenges..ChallengesService+getChallengeSubtracks"></a>
206+
<a name="module_services.challenges..ChallengesService+getChallengeTypes"></a>
207207

208-
#### challengesService.getChallengeSubtracks() ⇒ <code>Promise</code>
208+
#### challengesService.getChallengeTypes() ⇒ <code>Promise</code>
209209
Gets possible challenge subtracks.
210210

211211
**Kind**: instance method of [<code>ChallengesService</code>](#module_services.challenges..ChallengesService)

src/services/__mocks__/challenges.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username)
134134
// Fill some derived data
135135
const registrationOpen = _.some(
136136
challenge.allPhases,
137-
phase => phase.name === 'Registration' && phase.isActive,
137+
phase => phase.name === 'Registration' && phase.isOpen,
138138
) ? 'Yes' : 'No';
139139
_.defaults(challenge, {
140140
communities: new Set([COMPETITION_TRACKS[challenge.track]]),
@@ -163,7 +163,7 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username)
163163
* @return {Object} Normalized challenge.
164164
*/
165165
export function normalizeChallenge(challenge, username) {
166-
const registrationOpen = challenge.allPhases.filter(d => d.name === 'Registration')[0].isActive ? 'Yes' : 'No';
166+
const registrationOpen = challenge.allPhases.filter(d => d.name === 'Registration')[0].isOpen ? 'Yes' : 'No';
167167
const groups = {};
168168
if (challenge.groupIds) {
169169
challenge.groupIds.forEach((id) => {
@@ -250,10 +250,10 @@ class ChallengesService {
250250
}
251251

252252
/**
253-
* Gets possible challenge subtracks.
254-
* @return {Promise} Resolves to the array of subtrack names.
253+
* Gets possible challenge types.
254+
* @return {Promise} Resolves to the array of challenge type names.
255255
*/
256-
getChallengeSubtracks() {
256+
getChallengeTypes() {
257257
return Promise.all([
258258
this.private.apiV2.get('/design/challengetypes')
259259
.then(res => (res.ok ? res.json() : new Error(res.statusText))),

src/services/challenges.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
5757
numberOfCheckpointsPrizes: challenge.numberOfCheckpointsPrizes,
5858
topCheckPointPrize: challenge.topCheckPointPrize,
5959
submissionsViewable: challenge.submissionsViewable || 'false',
60-
reviewType: challenge.reviewType,
6160
allowStockArt: challenge.allowStockArt === 'true',
6261
fileTypes: challenge.filetypes || [],
6362
environment: challenge.environment,
@@ -66,12 +65,7 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
6665
submissionLimit: Number(challenge.submissionLimit) || 0,
6766
drPoints: challenge.digitalRunPoints,
6867
directUrl: challenge.directUrl,
69-
tags: _.union(
70-
challenge.technologies || [],
71-
challenge.technology || [],
72-
challenge.platforms || [],
73-
challenge.tags || [],
74-
),
68+
tags: challenge.tags || [],
7569
prizes: challenge.prize || challenge.prizes || [],
7670
events: _.map(challenge.event, e => ({
7771
eventName: e.eventShortDesc,
@@ -80,7 +74,6 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
8074
})),
8175
terms: challenge.terms,
8276
submissions: challenge.submissions,
83-
track: _.toUpper(challenge.challengeCommunity),
8477
subTrack: challenge.subTrack,
8578
checkpoints: challenge.checkpoints,
8679
documents: challenge.documents || [],
@@ -147,7 +140,7 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
147140
// Fill some derived data
148141
const registrationOpen = _.some(
149142
allPhases,
150-
phase => phase.name === 'Registration' && phase.isActive,
143+
phase => phase.name === 'Registration' && phase.isOpen,
151144
) ? 'Yes' : 'No';
152145
_.defaults(finalChallenge, {
153146
communities: new Set([COMPETITION_TRACKS[finalChallenge.track]]),
@@ -180,7 +173,7 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
180173
* @param {String} username Optional.
181174
*/
182175
export function normalizeChallenge(challenge, username) {
183-
const registrationOpen = (challenge.allPhases || challenge.phases || []).filter(d => (d.name === 'Registration' || !d.name))[0].isActive ? 'Yes' : 'No';
176+
const registrationOpen = (challenge.allPhases || challenge.phases || []).filter(d => (d.name === 'Registration' || !d.name))[0].isOpen ? 'Yes' : 'No';
184177
const groups = {};
185178
if (challenge.groupIds) {
186179
challenge.groupIds.forEach((id) => {
@@ -192,8 +185,7 @@ export function normalizeChallenge(challenge, username) {
192185
if (!challenge.totalPrize) {
193186
challenge.totalPrize = challenge.prizes.reduce((sum, x) => sum + x, 0);
194187
}
195-
if (!challenge.technologies) challenge.technologies = [];
196-
if (!challenge.platforms) challenge.platforms = [];
188+
if (!challenge.tags) challenge.tags = [];
197189

198190
if (challenge.subTrack === 'DEVELOP_MARATHON_MATCH') {
199191
challenge.track = 'DATA_SCIENCE';
@@ -339,7 +331,12 @@ class ChallengesService {
339331
* is rejected.
340332
*/
341333
async activate(challengeId) {
342-
let res = await this.private.api.post(`/challenges/${challengeId}/activate`);
334+
const params = {
335+
status: 'Active',
336+
};
337+
338+
let res = await this.private.apiV5.patch(`/challenge/${challengeId}`, params);
339+
343340
if (!res.ok) throw new Error(res.statusText);
344341
res = (await res.json()).result;
345342
if (res.status !== 200) throw new Error(res.content);
@@ -349,15 +346,14 @@ class ChallengesService {
349346
/**
350347
* Closes the specified challenge.
351348
* @param {Number} challengeId
352-
* @param {Number} winnerId Optional. ID of the assignee to declare the
353-
* winner.
354349
* @return {Promise} Resolves to null value in case of success; otherwise it
355350
* is rejected.
356351
*/
357-
async close(challengeId, winnerId) {
358-
let url = `/challenges/${challengeId}/close`;
359-
if (winnerId) url = `${url}?winnerId=${winnerId}`;
360-
let res = await this.private.api.post(url);
352+
async close(challengeId) {
353+
const params = {
354+
status: 'Completed',
355+
};
356+
let res = await this.private.apiV5.patch(`/challenges/${challengeId}/close`, params);
361357
if (!res.ok) throw new Error(res.statusText);
362358
res = (await res.json()).result;
363359
if (res.status !== 200) throw new Error(res.content);
@@ -375,7 +371,7 @@ class ChallengesService {
375371
* @param {String} submissionGuidelines
376372
* @param {Number} copilotId
377373
* @param {Number} copilotFee
378-
* @param {?} technologies
374+
* @param {?} tags
379375
* @return {Promise} Resolves to the created challenge object (payment task).
380376
*/
381377
async createTask(
@@ -388,7 +384,7 @@ class ChallengesService {
388384
submissionGuidelines,
389385
copilotId,
390386
copilotFee,
391-
technologies,
387+
tags,
392388
) {
393389
const payload = {
394390
param: {
@@ -399,7 +395,7 @@ class ChallengesService {
399395
submissionGuidelines,
400396
milestoneId: 1,
401397
name: title,
402-
technologies,
398+
tags,
403399
prizes: payment ? [payment] : [],
404400
projectId,
405401
registrationStartsAt: moment().toISOString(),
@@ -467,11 +463,11 @@ class ChallengesService {
467463
}
468464

469465
/**
470-
* Gets possible challenge subtracks.
466+
* Gets possible challenge types.
471467
* @return {Promise} Resolves to the array of subtrack names.
472468
*/
473-
getChallengeSubtracks() {
474-
return this.private.apiV5.get('/challengetypes')
469+
getChallengeTypes() {
470+
return this.private.apiV5.get('/challenge-types')
475471
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
476472
.then(res => (
477473
res.message
@@ -511,18 +507,15 @@ class ChallengesService {
511507
/**
512508
* Gets SRM matches.
513509
* @param {Object} params
510+
* @param {string} typeId Challenge SRM TypeId
514511
* @return {Promise}
515512
*/
516513
async getSrms(params) {
517-
const res = await this.private.api.get(`/srms/?${qs.stringify(params)}`);
514+
const res = await this.private.apiV5.get(`/challenges/?${qs.stringify(params)}`);
518515
return getApiResponsePayload(res);
519516
}
520517

521518
static updateFiltersParamsForGettingMemberChallenges(filters, params) {
522-
if (filters && filters.status === 'Active') {
523-
// eslint-disable-next-line no-param-reassign
524-
filters.status = 'ACTIVE';
525-
}
526519
if (params && params.perPage) {
527520
// eslint-disable-next-line no-param-reassign
528521
params.offset = (params.page - 1) * params.perPage;
@@ -577,23 +570,31 @@ class ChallengesService {
577570
/**
578571
* Registers user to the specified challenge.
579572
* @param {String} challengeId
573+
* @param {String} memberHandle
574+
* @param {String} roleId
580575
* @return {Promise}
581576
*/
582-
async register(challengeId) {
583-
const endpoint = `/challenges/${challengeId}/register`;
584-
const res = await this.private.api.postJson(endpoint);
577+
async register(challengeId, memberHandle, roleId) {
578+
const params = {
579+
challengeId, memberHandle, roleId,
580+
};
581+
const res = await this.private.apiV5.post('/resources', params);
585582
if (!res.ok) throw new Error(res.statusText);
586583
return res.json();
587584
}
588585

589586
/**
590587
* Unregisters user from the specified challenge.
591588
* @param {String} challengeId
589+
* @param {String} memberHandle
590+
* @param {String} roleId
592591
* @return {Promise}
593592
*/
594-
async unregister(challengeId) {
595-
const endpoint = `/challenges/${challengeId}/unregister`;
596-
const res = await this.private.api.post(endpoint);
593+
async unregister(challengeId, memberHandle, roleId) {
594+
const params = {
595+
challengeId, memberHandle, roleId,
596+
};
597+
const res = await this.private.apiV5.post('/resources', params);
597598
if (!res.ok) throw new Error(res.statusText);
598599
return res.json();
599600
}

src/utils/challenge/filter.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ function filterByRegistrationOpen(challenge, state) {
9090
return challenge.status !== 'Past';
9191
}
9292
const registrationPhase = (challenge.allPhases || challenge.phases || []).find(item => item.name === 'Registration');
93-
if (!registrationPhase || !registrationPhase.isActive) {
93+
if (!registrationPhase || !registrationPhase.isOpen) {
9494
return false;
9595
}
9696
if (challenge.track === 'DESIGN') {
9797
const checkpointPhase = (challenge.allPhases || challenge.phases || []).find(item => item.name === 'Checkpoint Submission');
98-
return !checkpointPhase || !checkpointPhase.isActive;
98+
return !checkpointPhase || !checkpointPhase.isOpen;
9999
}
100100
return true;
101101
};
@@ -123,7 +123,7 @@ function filterByStarted(challenge, state) {
123123
if (!challenge.phases) {
124124
return true;
125125
}
126-
return _.some(challenge.phases, { isActive: true, name: 'Registration' });
126+
return _.some(challenge.phases, { isOpen: true, name: 'Registration' });
127127
}
128128

129129
function filterByStatus(challenge, state) {
@@ -143,14 +143,14 @@ function filterBySubtracks(challenge, state) {
143143

144144
function filterByTags(challenge, state) {
145145
if (!state.tags) return true;
146-
const { platforms, technologies } = challenge;
147-
const str = `${platforms} ${technologies}`.toLowerCase();
146+
const { platforms, tags } = challenge;
147+
const str = `${platforms} ${tags}`.toLowerCase();
148148
return state.tags.some(tag => str.includes(tag.toLowerCase()));
149149
}
150150

151151
function filterByText(challenge, state) {
152152
if (!state.text) return true;
153-
const str = `${challenge.name} ${challenge.tags} ${challenge.platforms} ${challenge.technologies}`
153+
const str = `${challenge.name} ${challenge.tags} ${challenge.platforms} ${challenge.tags}`
154154
.toLowerCase();
155155
return str.includes(state.text.toLowerCase());
156156
}

0 commit comments

Comments
 (0)