Skip to content

Commit

Permalink
Defect/athlete details (#80)
Browse files Browse the repository at this point in the history
* api breaking change. do not call athlete details endpoint anymore

* fix api breaking change issue

* export filter club members function to club services.
  • Loading branch information
totorototo authored Feb 10, 2018
1 parent e986896 commit f187b50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
34 changes: 18 additions & 16 deletions app/store/sagas/clubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { SET_CURRENT_USER_ID } from "../constants/actionTypes";
import { updateEntity, setEntity } from "../actions/entities";
import { setCurrentClubID } from "../actions/data";
import { token, getCurrentUserID } from "../state/appState/selectors";
import { listClubMembers, listClubActivities } from "../services/clubs";
import { getStats } from "./athlete";
import {
listClubMembers,
listClubActivities,
filterClubAthletes
} from "../services/clubs";
import { getRankings } from "../services/activities";

function* listActivities(clubID, membersIDs) {
Expand All @@ -29,22 +32,21 @@ function* listMembers() {
// TODO: this should not be done this way! (current club ID)
const clubID = 288750;
yield put(setCurrentClubID("loading"));
const { ids, error } = yield call(listClubMembers, accessToken, clubID);
const { ids, error, entities } = yield call(
listClubMembers,
accessToken,
clubID
);
if (!error) {
yield put(updateEntity(clubID, "clubs", { members: ids }));
const filteredIds = ids.filter(id => id !== currentUserID);
let mergedEntities = {};
for (let index = 0; index < filteredIds.length; index += 1) {
const { entities } = yield getStats(filteredIds[index]);
mergedEntities = {
...mergedEntities,
athletes: {
...mergedEntities.athletes,
...entities.athletes
}
};
}
yield put(setEntity("athletes", mergedEntities.athletes));

const athletes = yield call(
filterClubAthletes,
entities.members,
currentUserID
);

yield put(setEntity("athletes", athletes));
yield put(setCurrentClubID(clubID));
yield listActivities(clubID, ids);
}
Expand Down
9 changes: 8 additions & 1 deletion app/store/services/clubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const listClubMembers = (token, id) => {
{},
{
idAttribute: "id",
processStrategy: entity => pick(entity, ["username"])
processStrategy: entity =>
pick(entity, ["firstname", "lastname", "profile", "id", "country"])
}
);
const membersSchema = [memberSchema];
Expand Down Expand Up @@ -108,3 +109,9 @@ export const listClubActivities = (token, id) => {
error => ({ error })
);
};

export const filterClubAthletes = (athletes = {}, filteredAthleteID = 0) =>
Object.keys(athletes)
.filter(member => parseInt(member, 0) !== filteredAthleteID)
.map(key => ({ [key]: athletes[key] }))
.reduce((accumulator, current) => ({ ...accumulator, ...current }), {});

0 comments on commit f187b50

Please sign in to comment.