diff --git a/.gitignore b/.gitignore index 27fb5f91..62753454 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules _auto_doc_ .vscode topcoder-react-lib-*.*.*.tgz +.idea diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap index 02658e98..1b73c5a3 100644 --- a/__tests__/__snapshots__/index.js.snap +++ b/__tests__/__snapshots__/index.js.snap @@ -72,6 +72,8 @@ Object { "getReviewTypesInit": [Function], "getSkillTagsDone": [Function], "getSkillTagsInit": [Function], + "getTechnologiesDone": [Function], + "getTechnologiesInit": [Function], "getTypesDone": [Function], "getTypesInit": [Function], }, diff --git a/__tests__/actions/__snapshots__/lookup.js.snap b/__tests__/actions/__snapshots__/lookup.js.snap index 5061adee..261bac2c 100644 --- a/__tests__/actions/__snapshots__/lookup.js.snap +++ b/__tests__/actions/__snapshots__/lookup.js.snap @@ -17,6 +17,8 @@ Object { "getReviewTypesInit": [Function], "getSkillTagsDone": [Function], "getSkillTagsInit": [Function], + "getTechnologiesDone": [Function], + "getTechnologiesInit": [Function], "getTypesDone": [Function], "getTypesInit": [Function], }, diff --git a/__tests__/reducers/__snapshots__/lookup.js.snap b/__tests__/reducers/__snapshots__/lookup.js.snap index 91055596..6b1a6d45 100644 --- a/__tests__/reducers/__snapshots__/lookup.js.snap +++ b/__tests__/reducers/__snapshots__/lookup.js.snap @@ -27,6 +27,7 @@ Object { "status": "APPROVED", }, ], + "technologies": Array [], "types": Array [], } `; @@ -58,6 +59,7 @@ Object { "status": "APPROVED", }, ], + "technologies": Array [], "types": Array [], } `; @@ -83,6 +85,7 @@ Object { "status": "APPROVED", }, ], + "technologies": Array [], "types": Array [], } `; @@ -108,6 +111,7 @@ Object { "status": "APPROVED", }, ], + "technologies": Array [], "types": Array [], } `; @@ -125,6 +129,7 @@ Object { "oses": Array [], "reviewTypes": Array [], "skillTags": Array [], + "technologies": Array [], "types": Array [], } `; @@ -156,6 +161,7 @@ Object { "status": "APPROVED", }, ], + "technologies": Array [], "types": Array [], } `; @@ -187,6 +193,7 @@ Object { "status": "APPROVED", }, ], + "technologies": Array [], "types": Array [], } `; @@ -212,6 +219,7 @@ Object { "status": "APPROVED", }, ], + "technologies": Array [], "types": Array [], } `; @@ -237,6 +245,7 @@ Object { "status": "APPROVED", }, ], + "technologies": Array [], "types": Array [], } `; @@ -254,6 +263,7 @@ Object { "oses": Array [], "reviewTypes": Array [], "skillTags": Array [], + "technologies": Array [], "types": Array [], } `; diff --git a/package-lock.json b/package-lock.json index 076542d3..86a4b827 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31730,4 +31730,4 @@ } } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 11f16853..fdd37223 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "1000.25.7", + "version": "1000.25.8", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0", diff --git a/src/actions/lookup.js b/src/actions/lookup.js index 753e2472..f4c191d1 100644 --- a/src/actions/lookup.js +++ b/src/actions/lookup.js @@ -173,6 +173,22 @@ function getAllCountriesDone(tokenV3) { return getService(tokenV3).getAllCountries(); } +/** + * @static + * @desc Creates an action that signals beginning of getting all technologies. + * @return {Action} + */ +function getTechnologiesInit() {} + +/** + * @static + * @desc Creates an action that gets all technologies. + * @return {Action} + */ +function getTechnologiesDone() { + return getService().getTechnologies(); +} + export default createActions({ LOOKUP: { GET_TYPES_INIT: getTypesInit, @@ -191,5 +207,7 @@ export default createActions({ GET_REVIEW_TYPES_DONE: getReviewTypesDone, GET_ALL_COUNTRIES_INIT: getAllCountriesInit, GET_ALL_COUNTRIES_DONE: getAllCountriesDone, + GET_TECHNOLOGIES_INIT: getTechnologiesInit, + GET_TECHNOLOGIES_DONE: getTechnologiesDone, }, }); diff --git a/src/reducers/lookup.js b/src/reducers/lookup.js index e887ad39..2e892d1f 100644 --- a/src/reducers/lookup.js +++ b/src/reducers/lookup.js @@ -236,6 +236,25 @@ function onGetAllCountriesDone(state, { payload, error }) { }); } +/** + * Handles LOOKUP/GET_TECHNOLOGIES_DONE action. + * @param {Object} state + * @param {Object} action Payload will be JSON from api call + * @return {Object} New state + */ +function onGetTechnologiesDone(state, { payload, error }) { + if (error) { + logger.error('Failed to get technologies', payload); + return { ...state, loadingTechnologiesError: true }; + } + + return ({ + ...state, + loadingTechnologiesError: false, + technologies: payload, + }); +} + /** * Creates a new Lookup reducer with the specified initial state. * @param {Object} initialState Optional. Initial state. @@ -260,6 +279,8 @@ function create(initialState = {}) { [a.getReviewTypesDone]: onGetReviewTypesDone, [a.getAllCountriesInit]: state => state, [a.getAllCountriesDone]: onGetAllCountriesDone, + [a.getTechnologiesInit]: state => state, + [a.getTechnologiesDone]: onGetTechnologiesDone, }, _.defaults(initialState, { skillTags: [], countries: [], @@ -273,6 +294,7 @@ function create(initialState = {}) { osPage: 1, hasMoreOses: false, reviewTypes: [], + technologies: [], })); } diff --git a/src/services/lookup.js b/src/services/lookup.js index cd2b99e7..93f0c005 100644 --- a/src/services/lookup.js +++ b/src/services/lookup.js @@ -15,6 +15,7 @@ class LookupService { constructor(tokenV3) { this.private = { api: getApi('V3', tokenV3), + apiV4: getApi('V4', tokenV3), apiV5: getApi('V5', tokenV3), tokenV3, }; @@ -119,6 +120,15 @@ class LookupService { } return []; } + + /** + * Gets all technologies. + * @return {Promise} Resolves to the review types. + */ + async getTechnologies() { + const res = await this.private.apiV4.get('/technologies'); + return getApiResponsePayload(res); + } } let lastInstance = null; diff --git a/src/services/user-traits.js b/src/services/user-traits.js index c1d71b71..d3a30415 100644 --- a/src/services/user-traits.js +++ b/src/services/user-traits.js @@ -4,9 +4,18 @@ * via API V3. */ import toCapitalCase from 'to-capital-case'; -import { getApiResponsePayload } from '../utils/tc'; import { getApi } from './api'; +/** + * Private. Handles given response from the member's traits API. + * @param {Object} response + * @return {Promise} On success resolves to the data fetched from the API. + */ +function handleApiResponse(response) { + if (!response.ok) throw new Error(response.statusText); + return response.json(); +} + /** * Service class. */ @@ -16,7 +25,7 @@ class UserTraitsService { */ constructor(tokenV3) { this.private = { - api: getApi('V3', tokenV3), + api: getApi('V5', tokenV3), tokenV3, }; } @@ -29,7 +38,7 @@ class UserTraitsService { async getAllUserTraits(handle) { // FIXME: Remove the .toLowerCase() when the API is fixed to ignore the case in the route params const res = await this.private.api.get(`/members/${handle.toLowerCase()}/traits`); - return getApiResponsePayload(res); + return handleApiResponse(res); } /** @@ -40,18 +49,17 @@ class UserTraitsService { * @return {Promise} Resolves to the member traits. */ async addUserTrait(handle, traitId, data) { - const body = { - param: [{ + const body = [{ + traitId, + categoryName: toCapitalCase(traitId), + traits: { traitId, - categoryName: toCapitalCase(traitId), - traits: { - data, - }, - }], - }; + data, + }, + }]; const res = await this.private.api.postJson(`/members/${handle}/traits`, body); - return getApiResponsePayload(res); + return handleApiResponse(res); } /** @@ -62,18 +70,16 @@ class UserTraitsService { * @return {Promise} Resolves to the member traits. */ async updateUserTrait(handle, traitId, data) { - const body = { - param: [{ - traitId, - categoryName: toCapitalCase(traitId), - traits: { - data, - }, - }], - }; + const body = [{ + traitId, + categoryName: toCapitalCase(traitId), + traits: { + data, + }, + }]; const res = await this.private.api.putJson(`/members/${handle}/traits`, body); - return getApiResponsePayload(res); + return handleApiResponse(res); } /** @@ -83,8 +89,7 @@ class UserTraitsService { * @return {Promise} Resolves to the member traits. */ async deleteUserTrait(handle, traitId) { - const res = await this.private.api.delete(`/members/${handle}/traits?traitIds=${traitId}`); - return getApiResponsePayload(res); + await this.private.api.delete(`/members/${handle}/traits?traitIds=${traitId}`); } }