Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/services/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/* global XMLHttpRequest */
import _ from 'lodash';
import qs from 'qs';
import { decodeToken } from 'tc-accounts';
import logger from '../utils/logger';
import { getApiResponsePayload } from '../utils/tc';
import { getApi } from './api';
Expand Down Expand Up @@ -329,7 +330,8 @@ class MembersService {
* @param {Array} challengeId the challenge id
*/
async getChallengeResources(challengeId) {
const url = `/resources?challengeId=${challengeId}`;
const user = decodeToken(this.private.tokenV3);
const url = `/resources?challengeId=${challengeId}&memberId=${user.userId}`;
let res = null;

try {
Expand All @@ -346,14 +348,14 @@ class MembersService {
* @param {Array} memberId the member id
*/
async getUserResources(memberId) {
const url = `/resources/${memberId}/challenges`;
const url = `/challenges?status=Active&memberId=${memberId}`;
const res = await this.private.apiV5.get(url);
const challenges = await res.json();
const roles = await this.getResourceRoles();
const calls = [];

challenges.forEach(async (ch) => {
calls.push(this.getChallengeResources(ch));
calls.push(this.getChallengeResources(ch.id));
});

return Promise.all(calls).then((resources) => {
Expand Down
18 changes: 13 additions & 5 deletions src/utils/challenge/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ import { COMPETITION_TRACKS, REVIEW_OPPORTUNITY_TYPES } from '../tc';
*/

function filterByGroupIds(challenge, state) {
if (!state.groupIds) return true;
return state.groupIds.some(id => challenge.groups[id]);
if (_.isEmpty(state.groupIds)) return true;
if (_.isEmpty(challenge.groups)) return false;
return state.groupIds.some(id => challenge.groups.find(gId => gId === id));
}

function filterByRegistrationOpen(challenge, state) {
Expand Down Expand Up @@ -144,12 +145,18 @@ function filterByStatus(challenge, state) {
}

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

function filterByEvents(challenge, state) {
if (_.isEmpty(state.events)) return true;
if (_.isEmpty(challenge.events)) return false;
return state.events.some(key => challenge.events.find(e => e.key === key));
}

function filterByText(challenge, state) {
if (!state.text) return true;
const str = `${challenge.name} ${challenge.tags} ${challenge.platforms} ${challenge.tags}`
Expand Down Expand Up @@ -217,6 +224,7 @@ export function getFilterFunction(state) {
&& filterByGroupIds(challenge, state)
&& filterByText(challenge, state)
&& filterByTags(challenge, state)
&& filterByEvents(challenge, state)
&& filterByTypes(challenge, state)
&& filterByUsers(challenge, state)
&& filterByEndDate(challenge, state)
Expand Down Expand Up @@ -346,7 +354,7 @@ export function combine(...filters) {
const res = {};
filters.forEach((filter) => {
combineEndDate(res, filter);
combineArrayRules(res, filter, 'groups');
combineArrayRules(res, filter, 'groupIds');
/* TODO: The registrationOpen rule is just ignored for now. */
combineStartDate(res, filter);
combineArrayRules(res, filter, 'or', true);
Expand Down Expand Up @@ -383,7 +391,7 @@ export function combine(...filters) {
*/
export function mapToBackend(filter) {
const res = {};
if (filter.groups) res.groups = filter.groups;
if (filter.groupIds) res.groups = filter.groupIds;
return res;
}

Expand Down