Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

update profile and skills to v5#328

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rakibansary merged 1 commit intotopcoder-platform:feat/traits-v5-upgradefromCDharmateja:update-profile-and-skills-to-v5
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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
2 changes: 2 additions & 0 deletions__tests__/__snapshots__/index.js.snap
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,7 +174,9 @@ Object {
"updatePasswordDone": [Function],
"updatePasswordInit": [Function],
"updateProfileDone": [Function],
"updateProfileDoneV5": [Function],
"updateProfileInit": [Function],
"updateProfileInitV5": [Function],
"uploadPhotoDone": [Function],
"uploadPhotoInit": [Function],
"verifyMemberNewEmailDone": [Function],
Expand Down
2 changes: 2 additions & 0 deletions__tests__/actions/__snapshots__/profile.js.snap
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,7 +44,9 @@ Object {
"updatePasswordDone": [Function],
"updatePasswordInit": [Function],
"updateProfileDone": [Function],
"updateProfileDoneV5": [Function],
"updateProfileInit": [Function],
"updateProfileInitV5": [Function],
"uploadPhotoDone": [Function],
"uploadPhotoInit": [Function],
"verifyMemberNewEmailDone": [Function],
Expand Down
4 changes: 2 additions & 2 deletions__tests__/actions/auth.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
const MOCK_GROUPS_REQ_URL = 'https://api.topcoder-dev.com/v5/groups?memberId=12345&membershipType=user';
const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v3/members/username12345';
const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v5/members/username12345';

jest.mock('isomorphic-fetch', () => jest.fn(url => Promise.resolve({
ok: true,
Expand All@@ -10,7 +10,7 @@ jest.mock('isomorphic-fetch', () => jest.fn(url => Promise.resolve({
content = ['Group1', 'Group2'];
break;
case MOCK_PROFILE_REQ_URL:
content ={ result: { content: {userId: 12345 }, status: 200 } };
content =Promise.resolve({userId: 12345 });
break;
default: throw new Error('Unexpected URL!');
}
Expand Down
8 changes: 4 additions & 4 deletionssrc/actions/auth.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,10 @@

import { createActions } from 'redux-actions';
import { decodeToken } from '@topcoder-platform/tc-auth-lib';
import {getApiV3,getApiV5 } from '../services/api';
import { getApiV5 } from '../services/api';
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
import { getService } from '../services/groups';
import { handleApiResponse } from '../utils/tc';

/**
* Helper method that checks for HTTP error response v5 and throws Error in this case.
Expand DownExpand Up@@ -41,11 +42,10 @@ async function checkErrorV5(res) {
function loadProfileDone(userTokenV3) {
if (!userTokenV3) return Promise.resolve(null);
const user = decodeToken(userTokenV3);
const apiV3 = getApiV3(userTokenV3);
const apiV5 = getApiV5(userTokenV3);
return Promise.all([
apiV3.get(`/members/${user.handle}`)
.then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : {})),
apiV5.get(`/members/${user.handle}`)
.then(handleApiResponse),
apiV5.get(`/groups?memberId=${user.userId}&membershipType=user`)
.then(checkErrorV5).then(res => res.result || []),
]).then(([profile, groups]) => ({ ...profile, groups }));
Expand Down
21 changes: 21 additions & 0 deletionssrc/actions/profile.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -246,6 +246,25 @@ function updateProfileDone(profile, tokenV3) {
return service.updateMemberProfile(profile);
}

/**
* @static
* @desc Creates an action that signals beginning of updating user's profile.
* @return {Action}
*/
function updateProfileInitV5() {}

/**
* @static
* @desc Creates an action that updates user's profile.
* @param {String} profile Topcoder user profile.
* @param {String} tokenV5 Topcoder auth token v5.
* @return {Action}
*/
function updateProfileDoneV5(profile, handle, tokenV3) {
const service = getMembersService(tokenV3);
return service.updateMemberProfileV5(profile, handle);
}

/**
* @static
* @desc Creates an action that signals beginning of adding user's skill.
Expand DownExpand Up@@ -483,6 +502,8 @@ export default createActions({
DELETE_PHOTO_DONE: updateProfileDone,
UPDATE_PROFILE_INIT: updateProfileInit,
UPDATE_PROFILE_DONE: updateProfileDone,
UPDATE_PROFILE_INIT_V5: updateProfileInitV5,
UPDATE_PROFILE_DONE_V5: updateProfileDoneV5,
ADD_SKILL_INIT: addSkillInit,
ADD_SKILL_DONE: addSkillDone,
HIDE_SKILL_INIT: hideSkillInit,
Expand Down
15 changes: 15 additions & 0 deletionssrc/reducers/auth.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,6 +106,21 @@ function create(initialState) {
},
};
},
[profileActions.profile.updateProfileDoneV5]: (state, { payload, error }) => {
if (error) {
return state;
}
if (!state.profile || state.profile.handle !== payload.handle) {
return state;
}
return {
...state,
profile: {
...state.profile,
...payload,
},
};
},
}, _.defaults(initialState, {
authenticating: true,
profile: null,
Expand Down
45 changes: 45 additions & 0 deletionssrc/reducers/profile.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -266,6 +266,49 @@ function onUpdateProfileDone(state, { payload, error }) {
};
}

/**
* Handles PROFILE/UPDATE_PROFILE_DONE_V5 action.
* @param {Object} state
* @param {Object} action Payload will be JSON from api call
* @return {Object} New state
*/
function onUpdateProfileDoneV5(state, { payload, error }) {
const newState = { ...state, updatingProfile: false };

if (payload.isEmailConflict) {
return {
...newState,
isEmailConflict: true,
updateProfileSuccess: false,
};
}

if (error) {
logger.error('Failed to update user profile', payload);
fireErrorMessage('ERROR: Failed to update user profile!');
return {
...newState,
updateProfileSuccess: false,
};
}

if (!newState.info || newState.info.handle !== payload.handle) {
return {
...newState,
updateProfileSuccess: true,
};
}

return {
...newState,
info: {
...newState.info,
...payload,
},
updateProfileSuccess: true,
};
}

/**
* Handles PROFILE/ADD_SKILL_DONE action.
* @param {Object} state
Expand DownExpand Up@@ -530,6 +573,8 @@ function create(initialState) {
[a.deletePhotoDone]: onDeletePhotoDone,
[a.updateProfileInit]: state => ({ ...state, updatingProfile: true }),
[a.updateProfileDone]: onUpdateProfileDone,
[a.updateProfileInitV5]: state => ({ ...state, updatingProfile: true }),
[a.updateProfileDoneV5]: onUpdateProfileDoneV5,
[a.addSkillInit]: state => ({ ...state, addingSkill: true }),
[a.addSkillDone]: onAddSkillDone,
[a.hideSkillInit]: state => ({ ...state, hidingSkill: true }),
Expand Down
46 changes: 26 additions & 20 deletionssrc/services/members.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,8 +45,8 @@ class MembersService {
* @return {Promise} Resolves to the data object.
*/
async getMemberInfo(handle) {
const res = await this.private.api.get(`/members/${handle}`);
returngetApiResponsePayload(res);
const res = await this.private.apiV5.get(`/members/${handle}`);
returnhandleApiResponse(res);
}

/**
Expand DownExpand Up@@ -75,8 +75,8 @@ class MembersService {
* @return {Promise} Resolves to the stats object.
*/
async getSkills(handle) {
const res = await this.private.api.get(`/members/${handle}/skills`);
returngetApiResponsePayload(res);
const res = await this.private.apiV5.get(`/members/${handle}/skills`);
returnhandleApiResponse(res);
}

/**
Expand DownExpand Up@@ -188,16 +188,12 @@ class MembersService {
*/
async addSkill(handle, skillTagId) {
const body = {
param: {
skills: {
[skillTagId]: {
hidden: false,
},
},
[skillTagId]: {
hidden: false,
},
};
const res = await this.private.api.patchJson(`/members/${handle}/skills`, body);
returngetApiResponsePayload(res);
const res = await this.private.apiV5.patchJson(`/members/${handle}/skills`, body);
returnhandleApiResponse(res);
}

/**
Expand All@@ -208,19 +204,15 @@ class MembersService {
*/
async hideSkill(handle, skillTagId) {
const body = {
param: {
skills: {
[skillTagId]: {
hidden: true,
},
},
[skillTagId]: {
hidden: true,
},
};
const res = await this.private.api.fetch(`/members/${handle}/skills`, {
const res = await this.private.apiV5.fetch(`/members/${handle}/skills`, {
body: JSON.stringify(body),
method: 'PATCH',
});
returngetApiResponsePayload(res);
returnhandleApiResponse(res);
}

/**
Expand All@@ -237,6 +229,20 @@ class MembersService {
return getApiResponsePayload(res);
}

/**
* Updates member profile.
* @param {Object} profile The profile to update.
* @return {Promise} Resolves to the api response content
*/
async updateMemberProfileV5(profile, handle) {
const url = profile.verifyUrl ? `/members/${handle}?verifyUrl=${profile.verifyUrl}` : `/members/${handle}`;
const res = await this.private.apiV5.putJson(url, profile.verifyUrl ? _.omit(profile, ['verifyUrl']) : profile);
if (profile.verifyUrl && res.status === 409) {
return Promise.resolve(Object.assign({}, profile, { isEmailConflict: true }));
}
return handleApiResponse(res);
}

/**
* Updates member photo.
* @param {String} userHandle The user handle
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp