From 1ab03a369cda01622012b6049e46c5c4b6c8b838 Mon Sep 17 00:00:00 2001 From: maxceem Date: Mon, 16 Aug 2021 16:18:01 +0300 Subject: [PATCH 1/2] Revert "Revert "Handling missing skill data enrichment via API call"" --- config/default.js | 6 ++++-- docs/swagger.yaml | 48 +++++++++++++++++++++++++------------------- src/common/helper.js | 24 +++++++++++++--------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/config/default.js b/config/default.js index 1a012a6d..b4ff40d7 100644 --- a/config/default.js +++ b/config/default.js @@ -33,10 +33,12 @@ module.exports = { // the Topcoder v5 url TC_API: process.env.TC_API || 'https://api.topcoder-dev.com/v5', + // the Topcoder Beta API url currently v5.1 + TC_BETA_API: process.env.TC_BETA_API || 'https://api.topcoder-dev.com/v5.1', // the organization id ORG_ID: process.env.ORG_ID || '36ed815b-3da1-49f1-a043-aaed0a4e81ad', - // the referenced skill provider id - TOPCODER_SKILL_PROVIDER_ID: process.env.TOPCODER_SKILL_PROVIDER_ID || '9cc0795a-6e12-4c84-9744-15858dba1861', + // the referenced taxonomy id + TOPCODER_TAXONOMY_ID: process.env.TOPCODER_TAXONOMY_ID || '7637ae1a-3b7c-44eb-a5ed-10ea02f1885d', TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users', // the api to find topcoder members diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 245f6abc..40fcd2eb 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -3157,7 +3157,7 @@ paths: schema: type: array items: - $ref: "#/components/schemas/UbahnSkill" + $ref: "#/components/schemas/SkillInSkillsAPI" headers: X-Next-Page: schema: @@ -5516,17 +5516,25 @@ components: type: string example: "React" description: The skill name. - UbahnSkill: - type: object + SkillInSkillsAPI: + required: + - "id" + - "name" + - "taxonomyId" + - "taxonomyName" + - "metadata" properties: id: type: "string" format: "UUID" description: "The skill id" - skillProviderId: + taxonomyId: type: "string" format: "UUID" - description: "The referenced skill provider id" + description: "The referenced taxonomy id" + taxonomyName: + type: "string" + description: "The referenced taxonomy name" name: type: "string" description: "The name of the skill" @@ -5536,22 +5544,20 @@ components: uri: type: "string" description: "The uri for the skill" - created: - type: "string" - format: "date-time" - description: "When the entity was created." - updated: - type: "string" - format: "date-time" - description: "When the entity was updated." - createdBy: - type: "string" - format: "UUID" - description: "Creator of the entity." - updatedBy: - type: "string" - format: "UUID" - description: "User that last updated the entity." + metadata: + type: "object" + description: "The metadata for the skill" + properties: + updated: + type: "string" + format: "date-time" + description: "The last updated timestamp of the skill" + challengeProminence: + type: "string" + description: "The challenge prominence ranging from [0, 1]" + memberProminence: + type: "string" + description: "The member prominence ranging from [0, 1]" JobForTeam: properties: id: diff --git a/src/common/helper.js b/src/common/helper.js index 1fd28f60..05785428 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -950,7 +950,15 @@ async function listUsersByExternalId (externalId) { context: 'listUserByExternalId', message: `response body: ${JSON.stringify(res.body)}` }) - return res.body + + const users = res.body + // populate skill data for each user skill + await Promise.all(users.map(user => Promise.all(user.skills.map(async userSkill => { + const skill = await getSkillById(userSkill.skillId) + userSkill.skill = skill + })))) + + return users } /** @@ -1092,9 +1100,7 @@ async function getUserById (userId, enrich) { const user = _.pick(res.body, ['id', 'handle', 'firstName', 'lastName']) if (enrich) { - user.skills = (res.body.skills || []).map((skillObj) => - _.pick(skillObj.skill, ['id', 'name']) - ) + user.skills = await Promise.all((res.body.skills || []).map(async (userSkill) => getSkillById(userSkill.skillId))) const attributes = _.get(res, 'body.attributes', []) user.attributes = _.map(attributes, (attr) => _.pick(attr, ['id', 'value', 'attribute.id', 'attribute.name']) @@ -1211,7 +1217,7 @@ async function getProjectById (currentUser, id) { /** * Function to search skills from v5/skills - * - only returns skills from Topcoder Skills Provider defined by `TOPCODER_SKILL_PROVIDER_ID` + * - only returns skills from Topcoder Skills API defined by `TOPCODER_TAXONOMY_ID` * * @param {Object} criteria the search criteria * @returns the request result @@ -1220,9 +1226,9 @@ async function getTopcoderSkills (criteria) { const token = await getM2MUbahnToken() try { const res = await request - .get(`${config.TC_API}/skills`) + .get(`${config.TC_BETA_API}/skills`) .query({ - skillProviderId: config.TOPCODER_SKILL_PROVIDER_ID, + taxonomyId: config.TOPCODER_TAXONOMY_ID, ...criteria }) .set('Authorization', `Bearer ${token}`) @@ -1248,7 +1254,7 @@ async function getTopcoderSkills (criteria) { /** * Function to search and retrive all skills from v5/skills - * - only returns skills from Topcoder Skills Provider defined by `TOPCODER_SKILL_PROVIDER_ID` + * - only returns skills from Topcoder Skills API defined by `TOPCODER_TAXONOMY_ID` * * @param {Object} criteria the search criteria * @returns the request result @@ -1272,7 +1278,7 @@ async function getAllTopcoderSkills (criteria) { async function getSkillById (skillId) { const token = await getM2MUbahnToken() const res = await request - .get(`${config.TC_API}/skills/${skillId}`) + .get(`${config.TC_BETA_API}/skills/${skillId}`) .set('Authorization', `Bearer ${token}`) .set('Content-Type', 'application/json') .set('Accept', 'application/json') From 1ee0442f7ee566a5b3153994d174c65a96aea2b0 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Mon, 16 Aug 2021 19:30:43 +0530 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20issue=20with=20`/me`=20endpoint,=20w?= =?UTF-8?q?e=20don=E2=80=99t=20need=20any=20change=20in=20the=20listUsersB?= =?UTF-8?q?yExternalId=20method=20as=20we=20don=E2=80=99t=20need=20skills?= =?UTF-8?q?=20back=20there.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/helper.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/common/helper.js b/src/common/helper.js index 05785428..bbc0654e 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -951,14 +951,7 @@ async function listUsersByExternalId (externalId) { message: `response body: ${JSON.stringify(res.body)}` }) - const users = res.body - // populate skill data for each user skill - await Promise.all(users.map(user => Promise.all(user.skills.map(async userSkill => { - const skill = await getSkillById(userSkill.skillId) - userSkill.skill = skill - })))) - - return users + return res.body } /**