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

feat: use v5 member api to save traits and skills#332

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
luizrrodrigues merged 12 commits intomasterfromdevelop
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
16cbb35
Revert "Merge pull request #325 from topcoder-platform/revert-322-fea…
luizrrodriguesDec 13, 2021
2a01da8
ci: added tag test-release
luizrrodriguesDec 13, 2021
e04f229
update profile and skills to v5
Dec 21, 2021
39265c8
Merge pull request #328 from CDharmateja/update-profile-and-skills-to-v5
rakibansaryDec 22, 2021
d49c623
Merge pull request #327 from topcoder-platform/feat/traits-v5-upgrade
rakibansaryDec 22, 2021
e02ab99
ci: test release
rakibansaryDec 22, 2021
473daea
Merge pull request #329 from topcoder-platform/feat/traits-v5-upgrade
rakibansaryDec 22, 2021
972a8d8
fix issue 5953
Jan 8, 2022
5f2c5c0
Merge pull request #330 from nursoltan-s/issue-5953
rakibansaryJan 10, 2022
3879270
ci: test release
rakibansaryJan 10, 2022
12b6c42
ci: removed tag test-release
luizrrodriguesJan 10, 2022
2f8dc7d
fix; for topcoder-platform/community-app#5918
luizrrodriguesJan 10, 2022
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
4 changes: 0 additions & 4 deletions__tests__/actions/profile.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,8 +18,6 @@ const linkedAccounts = [{

// Mock services
const mockMembersService = {
getPresignedUrl: jest.fn().mockReturnValue(Promise.resolve()),
uploadFileToS3: jest.fn().mockReturnValue(Promise.resolve()),
updateMemberPhoto: jest.fn().mockReturnValue(Promise.resolve('url-of-photo')),
updateMemberProfile: jest.fn().mockReturnValue(Promise.resolve(profile)),
addSkill: jest.fn().mockReturnValue(Promise.resolve({ skills: [skill] })),
Expand DownExpand Up@@ -47,8 +45,6 @@ test('Module exports', () => expect(actions).toMatchSnapshot());
test('profile.uploadPhotoDone', async () => {
const actionResult = await redux.resolveAction(actions.profile.uploadPhotoDone(handle, tokenV3));
expect(actionResult).toMatchSnapshot();
expect(mockMembersService.getPresignedUrl).toBeCalled();
expect(mockMembersService.uploadFileToS3).toBeCalled();
expect(mockMembersService.updateMemberPhoto).toBeCalled();
});

Expand Down
40 changes: 6 additions & 34 deletionsdocs/services.members.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,9 +25,7 @@ members via API V3.
* [.addSkill(handle, skillTagId)](#module_services.members..MembersService+addSkill) ⇒ <code>Promise</code>
* [.hideSkill(handle, skillTagId)](#module_services.members..MembersService+hideSkill) ⇒ <code>Promise</code>
* [.updateMemberProfile(profile)](#module_services.members..MembersService+updateMemberProfile) ⇒ <code>Promise</code>
* [.getPresignedUrl(userHandle, file)](#module_services.members..MembersService+getPresignedUrl) ⇒ <code>Promise</code>
* [.updateMemberPhoto(S3Response)](#module_services.members..MembersService+updateMemberPhoto) ⇒ <code>Promise</code>
* [.uploadFileToS3(presignedUrlResponse)](#module_services.members..MembersService+uploadFileToS3) ⇒ <code>Promise</code>
* [.updateMemberPhoto(userHandle, file)](#module_services.members..MembersService+updateMemberPhoto) ⇒ <code>Promise</code>
* [.verifyMemberNewEmail(handle, emailVerifyToken)](#module_services.members..MembersService+verifyMemberNewEmail) ⇒ <code>Promise</code>

<a name="module_services.members.getService"></a>
Expand DownExpand Up@@ -65,9 +63,7 @@ Service class.
* [.addSkill(handle, skillTagId)](#module_services.members..MembersService+addSkill) ⇒ <code>Promise</code>
* [.hideSkill(handle, skillTagId)](#module_services.members..MembersService+hideSkill) ⇒ <code>Promise</code>
* [.updateMemberProfile(profile)](#module_services.members..MembersService+updateMemberProfile) ⇒ <code>Promise</code>
* [.getPresignedUrl(userHandle, file)](#module_services.members..MembersService+getPresignedUrl) ⇒ <code>Promise</code>
* [.updateMemberPhoto(S3Response)](#module_services.members..MembersService+updateMemberPhoto) ⇒ <code>Promise</code>
* [.uploadFileToS3(presignedUrlResponse)](#module_services.members..MembersService+uploadFileToS3) ⇒ <code>Promise</code>
* [.updateMemberPhoto(userHandle, file)](#module_services.members..MembersService+updateMemberPhoto) ⇒ <code>Promise</code>
* [.verifyMemberNewEmail(handle, emailVerifyToken)](#module_services.members..MembersService+verifyMemberNewEmail) ⇒ <code>Promise</code>

<a name="new_module_services.members..MembersService_new"></a>
Expand DownExpand Up@@ -256,42 +252,18 @@ Updates member profile.
| --- | --- | --- |
| profile | <code>Object</code> | The profile to update. |

<a name="module_services.members..MembersService+getPresignedUrl"></a>

#### membersService.getPresignedUrl(userHandle, file) ⇒ <code>Promise</code>
Gets presigned url for member photo file.

**Kind**: instance method of [<code>MembersService</code>](#module_services.members..MembersService)
**Returns**: <code>Promise</code> - Resolves to the api response content

| Param | Type | Description |
| --- | --- | --- |
| userHandle | <code>String</code> | The user handle |
| file | <code>File</code> | The file to get its presigned url |

<a name="module_services.members..MembersService+updateMemberPhoto"></a>

#### membersService.updateMemberPhoto(S3Response) ⇒ <code>Promise</code>
Updates member photo.
#### membersService.updateMemberPhoto(userHandle, file) ⇒ <code>Promise</code>
Uploads and updates member photo.

**Kind**: instance method of [<code>MembersService</code>](#module_services.members..MembersService)
**Returns**: <code>Promise</code> - Resolves to the api response content

| Param | Type | Description |
| --- | --- | --- |
| S3Response | <code>Object</code> | The response from uploadFileToS3() function. |

<a name="module_services.members..MembersService+uploadFileToS3"></a>

#### membersService.uploadFileToS3(presignedUrlResponse) ⇒ <code>Promise</code>
Uploads file to S3.

**Kind**: instance method of [<code>MembersService</code>](#module_services.members..MembersService)
**Returns**: <code>Promise</code> - Resolves to the api response content

| Param | Type | Description |
| --- | --- | --- |
| presignedUrlResponse | <code>Object</code> | The presigned url response from getPresignedUrl() function. |
| userHandle | <code>String</code> | The user handle |
| file | <code>File</code> | The file to be uploaded |

<a name="module_services.members..MembersService+verifyMemberNewEmail"></a>

Expand Down
2 changes: 1 addition & 1 deletionpackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1.2.4",
"version": "1.2.5",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
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
25 changes: 22 additions & 3 deletionssrc/actions/profile.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -216,9 +216,7 @@ function uploadPhotoInit() {}
*/
function uploadPhotoDone(handle, tokenV3, file) {
const service = getMembersService(tokenV3);
return service.getPresignedUrl(handle, file)
.then(res => service.uploadFileToS3(res))
.then(res => service.updateMemberPhoto(res))
return service.updateMemberPhoto(handle, file)
.then(photoURL => ({ handle, photoURL }));
}

Expand DownExpand Up@@ -248,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@@ -485,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
Loading

[8]ページ先頭

©2009-2025 Movatter.jp