Skip to content

Commit 974defe

Browse files
committed
enrich disintigration
1 parent e5d8118 commit 974defe

File tree

4 files changed

+56
-41
lines changed

4 files changed

+56
-41
lines changed

config/default.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ module.exports = {
3535
TC_API: process.env.TC_API || 'https://api.topcoder-dev.com/v5',
3636
// the organization id
3737
ORG_ID: process.env.ORG_ID || '36ed815b-3da1-49f1-a043-aaed0a4e81ad',
38-
// the referenced skill provider id
39-
TOPCODER_SKILL_PROVIDER_ID: process.env.TOPCODER_SKILL_PROVIDER_ID || '9cc0795a-6e12-4c84-9744-15858dba1861',
38+
// the referenced taxonomy id
39+
TOPCODER_TAXONOMY_ID: process.env.TOPCODER_TAXONOMY_ID || '7637ae1a-3b7c-44eb-a5ed-10ea02f1885d',
4040

4141
TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users',
4242
// the api to find topcoder members

docs/swagger.yaml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,7 +3157,7 @@ paths:
31573157
schema:
31583158
type: array
31593159
items:
3160-
$ref: "#/components/schemas/UbahnSkill"
3160+
$ref: "#/components/schemas/SkillInSkillsAPI"
31613161
headers:
31623162
X-Next-Page:
31633163
schema:
@@ -5319,17 +5319,25 @@ components:
53195319
type: string
53205320
example: "React"
53215321
description: The skill name.
5322-
UbahnSkill:
5323-
type: object
5322+
SkillInSkillsAPI:
5323+
required:
5324+
- "id"
5325+
- "name"
5326+
- "taxonomyId"
5327+
- "taxonomyName"
5328+
- "metadata"
53245329
properties:
53255330
id:
53265331
type: "string"
53275332
format: "UUID"
53285333
description: "The skill id"
5329-
skillProviderId:
5334+
taxonomyId:
53305335
type: "string"
53315336
format: "UUID"
5332-
description: "The referenced skill provider id"
5337+
description: "The referenced taxonomy id"
5338+
taxonomyName:
5339+
type: "string"
5340+
description: "The referenced taxonomy name"
53335341
name:
53345342
type: "string"
53355343
description: "The name of the skill"
@@ -5339,22 +5347,20 @@ components:
53395347
uri:
53405348
type: "string"
53415349
description: "The uri for the skill"
5342-
created:
5343-
type: "string"
5344-
format: "date-time"
5345-
description: "When the entity was created."
5346-
updated:
5347-
type: "string"
5348-
format: "date-time"
5349-
description: "When the entity was updated."
5350-
createdBy:
5351-
type: "string"
5352-
format: "UUID"
5353-
description: "Creator of the entity."
5354-
updatedBy:
5355-
type: "string"
5356-
format: "UUID"
5357-
description: "User that last updated the entity."
5350+
metadata:
5351+
type: "object"
5352+
description: "The metadata for the skill"
5353+
properties:
5354+
updated:
5355+
type: "string"
5356+
format: "date-time"
5357+
description: "The last updated timestamp of the skill"
5358+
challengeProminence:
5359+
type: "string"
5360+
description: "The challenge prominence ranging from [0, 1]"
5361+
memberProminence:
5362+
type: "string"
5363+
description: "The member prominence ranging from [0, 1]"
53585364
JobForTeam:
53595365
properties:
53605366
id:

src/common/helper.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,15 @@ async function listUsersByExternalId (externalId) {
940940
context: 'listUserByExternalId',
941941
message: `response body: ${JSON.stringify(res.body)}`
942942
})
943-
return res.body
943+
944+
const users = res.body
945+
// populate skill data for each user skill
946+
await Promise.all(users.map(user => Promise.all(user.skills.map(async userSkill => {
947+
const skill = await getSkillById(userSkill.skillId)
948+
userSkill.skill = skill
949+
}))))
950+
951+
return users
944952
}
945953

946954
/**
@@ -1082,9 +1090,10 @@ async function getUserById (userId, enrich) {
10821090
const user = _.pick(res.body, ['id', 'handle', 'firstName', 'lastName'])
10831091

10841092
if (enrich) {
1085-
user.skills = (res.body.skills || []).map((skillObj) =>
1086-
_.pick(skillObj.skill, ['id', 'name'])
1087-
)
1093+
user.skills = await Promise.all((res.body.skills || []).map(async (userSkill) => {
1094+
const skill = await getSkillById(userSkill.skillId)
1095+
return _.pick(skill, ['id', 'name'])
1096+
}))
10881097
const attributes = _.get(res, 'body.attributes', [])
10891098
user.attributes = _.map(attributes, (attr) =>
10901099
_.pick(attr, ['id', 'value', 'attribute.id', 'attribute.name'])
@@ -1201,18 +1210,18 @@ async function getProjectById (currentUser, id) {
12011210

12021211
/**
12031212
* Function to search skills from v5/skills
1204-
* - only returns skills from Topcoder Skills Provider defined by `TOPCODER_SKILL_PROVIDER_ID`
1213+
* - only returns skills from Topcoder Skills API defined by `TOPCODER_TAXONOMY_ID`
12051214
*
12061215
* @param {Object} criteria the search criteria
12071216
* @returns the request result
12081217
*/
12091218
async function getTopcoderSkills (criteria) {
1210-
const token = await getM2MUbahnToken()
1219+
const token = await getM2MToken()
12111220
try {
12121221
const res = await request
12131222
.get(`${config.TC_API}/skills`)
12141223
.query({
1215-
skillProviderId: config.TOPCODER_SKILL_PROVIDER_ID,
1224+
taxonomyId: config.TOPCODER_TAXONOMY_ID,
12161225
...criteria
12171226
})
12181227
.set('Authorization', `Bearer ${token}`)
@@ -1238,7 +1247,7 @@ async function getTopcoderSkills (criteria) {
12381247

12391248
/**
12401249
* Function to search and retrive all skills from v5/skills
1241-
* - only returns skills from Topcoder Skills Provider defined by `TOPCODER_SKILL_PROVIDER_ID`
1250+
* - only returns skills from Topcoder Skills API defined by `TOPCODER_TAXONOMY_ID`
12421251
*
12431252
* @param {Object} criteria the search criteria
12441253
* @returns the request result
@@ -1260,7 +1269,7 @@ async function getAllTopcoderSkills (criteria) {
12601269
* @returns the request result
12611270
*/
12621271
async function getSkillById (skillId) {
1263-
const token = await getM2MUbahnToken()
1272+
const token = await getM2MToken()
12641273
const res = await request
12651274
.get(`${config.TC_API}/skills/${skillId}`)
12661275
.set('Authorization', `Bearer ${token}`)
@@ -1270,7 +1279,7 @@ async function getSkillById (skillId) {
12701279
context: 'getSkillById',
12711280
message: `response body: ${JSON.stringify(res.body)}`
12721281
})
1273-
return _.pick(res.body, ['id', 'name'])
1282+
return res.body
12741283
}
12751284

12761285
/**

src/services/TeamService.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,13 @@ async function getTeam (currentUser, id) {
337337
const teamDetail = result[0]
338338

339339
// add job skills for result
340-
let jobSkills = []
341340
if (teamDetail && teamDetail.jobs) {
342341
for (const job of teamDetail.jobs) {
343342
if (job.skills) {
344-
const usersPromises = []
345-
_.map(job.skills, (skillId) => {
346-
usersPromises.push(helper.getSkillById(skillId))
347-
})
348-
jobSkills = await Promise.all(usersPromises)
349-
job.skills = jobSkills
343+
job.skills = await Promise.all(job.skills.map(async (skillId) => {
344+
const skill = await helper.getSkillById(skillId)
345+
return _.pick(skill, ['id', 'name'])
346+
}))
350347
}
351348
}
352349
}
@@ -385,7 +382,10 @@ async function getTeamJob (currentUser, id, jobId) {
385382

386383
if (job.skills) {
387384
result.skills = await Promise.all(
388-
_.map(job.skills, (skillId) => helper.getSkillById(skillId))
385+
_.map(job.skills, async (skillId) => {
386+
const skill = await helper.getSkillById(skillId)
387+
return _.pick(skill, ['id', 'name'])
388+
})
389389
)
390390
}
391391

0 commit comments

Comments
 (0)