Skip to content

fix for challenge 30122528 #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 64 additions & 64 deletions dist/dev/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/services.challenges.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ This module provides a service for convenient manipulation with
* [.close(challengeId, winnerId)](#module_services.challenges..ChallengesService+close) ⇒ <code>Promise</code>
* [.createTask(projectId, accountId, title, description, assignee, payment)](#module_services.challenges..ChallengesService+createTask) ⇒ <code>Promise</code>
* [.getChallengeDetails(challengeId)](#module_services.challenges..ChallengesService+getChallengeDetails) ⇒ <code>Promise</code>
* [.getChallengeSubtracks()](#module_services.challenges..ChallengesService+getChallengeSubtracks) ⇒ <code>Promise</code>
* [.getChallengeTypes()](#module_services.challenges..ChallengesService+getChallengeTypes) ⇒ <code>Promise</code>
* [.getChallengeTags()](#module_services.challenges..ChallengesService+getChallengeTags) ⇒ <code>Promise</code>
* [.getChallenges(filters, params)](#module_services.challenges..ChallengesService+getChallenges) ⇒ <code>Promise</code>
* [.getMarathonMatches(filters, params)](#module_services.challenges..ChallengesService+getMarathonMatches) ⇒ <code>Promise</code>
@@ -119,7 +119,7 @@ Challenge service.
* [.close(challengeId, winnerId)](#module_services.challenges..ChallengesService+close) ⇒ <code>Promise</code>
* [.createTask(projectId, accountId, title, description, assignee, payment)](#module_services.challenges..ChallengesService+createTask) ⇒ <code>Promise</code>
* [.getChallengeDetails(challengeId)](#module_services.challenges..ChallengesService+getChallengeDetails) ⇒ <code>Promise</code>
* [.getChallengeSubtracks()](#module_services.challenges..ChallengesService+getChallengeSubtracks) ⇒ <code>Promise</code>
* [.getChallengeTypes()](#module_services.challenges..ChallengesService+getChallengeTypes) ⇒ <code>Promise</code>
* [.getChallengeTags()](#module_services.challenges..ChallengesService+getChallengeTags) ⇒ <code>Promise</code>
* [.getChallenges(filters, params)](#module_services.challenges..ChallengesService+getChallenges) ⇒ <code>Promise</code>
* [.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.
| --- | --- |
| challengeId | <code>Number</code> \| <code>String</code> |

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

#### challengesService.getChallengeSubtracks() ⇒ <code>Promise</code>
#### challengesService.getChallengeTypes() ⇒ <code>Promise</code>
Gets possible challenge subtracks.

**Kind**: instance method of [<code>ChallengesService</code>](#module_services.challenges..ChallengesService)
10 changes: 5 additions & 5 deletions src/services/__mocks__/challenges.js
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username)
// Fill some derived data
const registrationOpen = _.some(
challenge.allPhases,
phase => phase.name === 'Registration' && phase.isActive,
phase => phase.name === 'Registration' && phase.isOpen,
) ? 'Yes' : 'No';
_.defaults(challenge, {
communities: new Set([COMPETITION_TRACKS[challenge.track]]),
@@ -163,7 +163,7 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username)
* @return {Object} Normalized challenge.
*/
export function normalizeChallenge(challenge, username) {
const registrationOpen = challenge.allPhases.filter(d => d.name === 'Registration')[0].isActive ? 'Yes' : 'No';
const registrationOpen = challenge.allPhases.filter(d => d.name === 'Registration')[0].isOpen ? 'Yes' : 'No';
const groups = {};
if (challenge.groupIds) {
challenge.groupIds.forEach((id) => {
@@ -250,10 +250,10 @@ class ChallengesService {
}

/**
* Gets possible challenge subtracks.
* @return {Promise} Resolves to the array of subtrack names.
* Gets possible challenge types.
* @return {Promise} Resolves to the array of challenge type names.
*/
getChallengeSubtracks() {
getChallengeTypes() {
return Promise.all([
this.private.apiV2.get('/design/challengetypes')
.then(res => (res.ok ? res.json() : new Error(res.statusText))),
73 changes: 37 additions & 36 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
@@ -57,7 +57,6 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
numberOfCheckpointsPrizes: challenge.numberOfCheckpointsPrizes,
topCheckPointPrize: challenge.topCheckPointPrize,
submissionsViewable: challenge.submissionsViewable || 'false',
reviewType: challenge.reviewType,
allowStockArt: challenge.allowStockArt === 'true',
fileTypes: challenge.filetypes || [],
environment: challenge.environment,
@@ -66,12 +65,7 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
submissionLimit: Number(challenge.submissionLimit) || 0,
drPoints: challenge.digitalRunPoints,
directUrl: challenge.directUrl,
tags: _.union(
challenge.technologies || [],
challenge.technology || [],
challenge.platforms || [],
challenge.tags || [],
),
tags: challenge.tags || [],
prizes: challenge.prize || challenge.prizes || [],
events: _.map(challenge.event, e => ({
eventName: e.eventShortDesc,
@@ -80,7 +74,6 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
})),
terms: challenge.terms,
submissions: challenge.submissions,
track: _.toUpper(challenge.challengeCommunity),
subTrack: challenge.subTrack,
checkpoints: challenge.checkpoints,
documents: challenge.documents || [],
@@ -147,7 +140,7 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
// Fill some derived data
const registrationOpen = _.some(
allPhases,
phase => phase.name === 'Registration' && phase.isActive,
phase => phase.name === 'Registration' && phase.isOpen,
) ? 'Yes' : 'No';
_.defaults(finalChallenge, {
communities: new Set([COMPETITION_TRACKS[finalChallenge.track]]),
@@ -180,7 +173,7 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
* @param {String} username Optional.
*/
export function normalizeChallenge(challenge, username) {
const registrationOpen = (challenge.allPhases || challenge.phases || []).filter(d => (d.name === 'Registration' || !d.name))[0].isActive ? 'Yes' : 'No';
const registrationOpen = (challenge.allPhases || challenge.phases || []).filter(d => (d.name === 'Registration' || !d.name))[0].isOpen ? 'Yes' : 'No';
const groups = {};
if (challenge.groupIds) {
challenge.groupIds.forEach((id) => {
@@ -192,8 +185,7 @@ export function normalizeChallenge(challenge, username) {
if (!challenge.totalPrize) {
challenge.totalPrize = challenge.prizes.reduce((sum, x) => sum + x, 0);
}
if (!challenge.technologies) challenge.technologies = [];
if (!challenge.platforms) challenge.platforms = [];
if (!challenge.tags) challenge.tags = [];

if (challenge.subTrack === 'DEVELOP_MARATHON_MATCH') {
challenge.track = 'DATA_SCIENCE';
@@ -339,7 +331,12 @@ class ChallengesService {
* is rejected.
*/
async activate(challengeId) {
let res = await this.private.api.post(`/challenges/${challengeId}/activate`);
const params = {
status: 'Active',
};

let res = await this.private.apiV5.patch(`/challenge/${challengeId}`, params);

if (!res.ok) throw new Error(res.statusText);
res = (await res.json()).result;
if (res.status !== 200) throw new Error(res.content);
@@ -349,15 +346,14 @@ class ChallengesService {
/**
* Closes the specified challenge.
* @param {Number} challengeId
* @param {Number} winnerId Optional. ID of the assignee to declare the
* winner.
* @return {Promise} Resolves to null value in case of success; otherwise it
* is rejected.
*/
async close(challengeId, winnerId) {
let url = `/challenges/${challengeId}/close`;
if (winnerId) url = `${url}?winnerId=${winnerId}`;
let res = await this.private.api.post(url);
async close(challengeId) {
const params = {
status: 'Completed',
};
let res = await this.private.apiV5.patch(`/challenges/${challengeId}/close`, params);
if (!res.ok) throw new Error(res.statusText);
res = (await res.json()).result;
if (res.status !== 200) throw new Error(res.content);
@@ -375,7 +371,7 @@ class ChallengesService {
* @param {String} submissionGuidelines
* @param {Number} copilotId
* @param {Number} copilotFee
* @param {?} technologies
* @param {?} tags
* @return {Promise} Resolves to the created challenge object (payment task).
*/
async createTask(
@@ -388,7 +384,7 @@ class ChallengesService {
submissionGuidelines,
copilotId,
copilotFee,
technologies,
tags,
) {
const payload = {
param: {
@@ -399,7 +395,7 @@ class ChallengesService {
submissionGuidelines,
milestoneId: 1,
name: title,
technologies,
tags,
prizes: payment ? [payment] : [],
projectId,
registrationStartsAt: moment().toISOString(),
@@ -467,11 +463,11 @@ class ChallengesService {
}

/**
* Gets possible challenge subtracks.
* Gets possible challenge types.
* @return {Promise} Resolves to the array of subtrack names.
*/
getChallengeSubtracks() {
return this.private.apiV5.get('/challengetypes')
getChallengeTypes() {
return this.private.apiV5.get('/challenge-types')
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
.then(res => (
res.message
@@ -511,18 +507,15 @@ class ChallengesService {
/**
* Gets SRM matches.
* @param {Object} params
* @param {string} typeId Challenge SRM TypeId
* @return {Promise}
*/
async getSrms(params) {
const res = await this.private.api.get(`/srms/?${qs.stringify(params)}`);
const res = await this.private.apiV5.get(`/challenges/?${qs.stringify(params)}`);
return getApiResponsePayload(res);
}

static updateFiltersParamsForGettingMemberChallenges(filters, params) {
if (filters && filters.status === 'Active') {
// eslint-disable-next-line no-param-reassign
filters.status = 'ACTIVE';
}
if (params && params.perPage) {
// eslint-disable-next-line no-param-reassign
params.offset = (params.page - 1) * params.perPage;
@@ -577,23 +570,31 @@ class ChallengesService {
/**
* Registers user to the specified challenge.
* @param {String} challengeId
* @param {String} memberHandle
* @param {String} roleId
* @return {Promise}
*/
async register(challengeId) {
const endpoint = `/challenges/${challengeId}/register`;
const res = await this.private.api.postJson(endpoint);
async register(challengeId, memberHandle, roleId) {
const params = {
challengeId, memberHandle, roleId,
};
const res = await this.private.apiV5.post('/resources', params);
if (!res.ok) throw new Error(res.statusText);
return res.json();
}

/**
* Unregisters user from the specified challenge.
* @param {String} challengeId
* @param {String} memberHandle
* @param {String} roleId
* @return {Promise}
*/
async unregister(challengeId) {
const endpoint = `/challenges/${challengeId}/unregister`;
const res = await this.private.api.post(endpoint);
async unregister(challengeId, memberHandle, roleId) {
const params = {
challengeId, memberHandle, roleId,
};
const res = await this.private.apiV5.post('/resources', params);
if (!res.ok) throw new Error(res.statusText);
return res.json();
}
12 changes: 6 additions & 6 deletions src/utils/challenge/filter.js
Original file line number Diff line number Diff line change
@@ -90,12 +90,12 @@ function filterByRegistrationOpen(challenge, state) {
return challenge.status !== 'Past';
}
const registrationPhase = (challenge.allPhases || challenge.phases || []).find(item => item.name === 'Registration');
if (!registrationPhase || !registrationPhase.isActive) {
if (!registrationPhase || !registrationPhase.isOpen) {
return false;
}
if (challenge.track === 'DESIGN') {
const checkpointPhase = (challenge.allPhases || challenge.phases || []).find(item => item.name === 'Checkpoint Submission');
return !checkpointPhase || !checkpointPhase.isActive;
return !checkpointPhase || !checkpointPhase.isOpen;
}
return true;
};
@@ -123,7 +123,7 @@ function filterByStarted(challenge, state) {
if (!challenge.phases) {
return true;
}
return _.some(challenge.phases, { isActive: true, name: 'Registration' });
return _.some(challenge.phases, { isOpen: true, name: 'Registration' });
}

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

function filterByTags(challenge, state) {
if (!state.tags) return true;
const { platforms, technologies } = challenge;
const str = `${platforms} ${technologies}`.toLowerCase();
const { platforms, tags } = challenge;
const str = `${platforms} ${tags}`.toLowerCase();
return state.tags.some(tag => str.includes(tag.toLowerCase()));
}

function filterByText(challenge, state) {
if (!state.text) return true;
const str = `${challenge.name} ${challenge.tags} ${challenge.platforms} ${challenge.technologies}`
const str = `${challenge.name} ${challenge.tags} ${challenge.platforms} ${challenge.tags}`
.toLowerCase();
return str.includes(state.text.toLowerCase());
}