Skip to content

Commit 303277a

Browse files
author
Vikas Agarwal
committed
Implementing the review suggestions:
- Moved field pick logic back to the service instead of repeating at every calling code (reverted all changes from TeamService because of this) - Renamed getM2MToken back to getM2MUbahnToken to keep the changes minimal
1 parent 47edf69 commit 303277a

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/common/helper.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,7 @@ async function getUserById (userId, enrich) {
11001100
const user = _.pick(res.body, ['id', 'handle', 'firstName', 'lastName'])
11011101

11021102
if (enrich) {
1103-
user.skills = await Promise.all((res.body.skills || []).map(async (userSkill) => {
1104-
const skill = await getSkillById(userSkill.skillId)
1105-
return _.pick(skill, ['id', 'name'])
1106-
}))
1103+
user.skills = await Promise.all((res.body.skills || []).map(async (userSkill) => getSkillById(userSkill.skillId)))
11071104
const attributes = _.get(res, 'body.attributes', [])
11081105
user.attributes = _.map(attributes, (attr) =>
11091106
_.pick(attr, ['id', 'value', 'attribute.id', 'attribute.name'])
@@ -1226,7 +1223,7 @@ async function getProjectById (currentUser, id) {
12261223
* @returns the request result
12271224
*/
12281225
async function getTopcoderSkills (criteria) {
1229-
const token = await getM2MToken()
1226+
const token = await getM2MUbahnToken()
12301227
try {
12311228
const res = await request
12321229
.get(`${config.TC_API}/skills`)
@@ -1279,7 +1276,7 @@ async function getAllTopcoderSkills (criteria) {
12791276
* @returns the request result
12801277
*/
12811278
async function getSkillById (skillId) {
1282-
const token = await getM2MToken()
1279+
const token = await getM2MUbahnToken()
12831280
const res = await request
12841281
.get(`${config.TC_API}/skills/${skillId}`)
12851282
.set('Authorization', `Bearer ${token}`)
@@ -1289,7 +1286,7 @@ async function getSkillById (skillId) {
12891286
context: 'getSkillById',
12901287
message: `response body: ${JSON.stringify(res.body)}`
12911288
})
1292-
return res.body
1289+
return _.pick(res.body, ['id', 'name'])
12931290
}
12941291

12951292
/**

src/services/TeamService.js

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

330330
// add job skills for result
331+
let jobSkills = []
331332
if (teamDetail && teamDetail.jobs) {
332333
for (const job of teamDetail.jobs) {
333334
if (job.skills) {
334-
job.skills = await Promise.all(job.skills.map(async (skillId) => {
335-
const skill = await helper.getSkillById(skillId)
336-
return _.pick(skill, ['id', 'name'])
337-
}))
335+
const usersPromises = []
336+
_.map(job.skills, (skillId) => {
337+
usersPromises.push(helper.getSkillById(skillId))
338+
})
339+
jobSkills = await Promise.all(usersPromises)
340+
job.skills = jobSkills
338341
}
339342
}
340343
}
@@ -373,10 +376,7 @@ async function getTeamJob (currentUser, id, jobId) {
373376

374377
if (job.skills) {
375378
result.skills = await Promise.all(
376-
_.map(job.skills, async (skillId) => {
377-
const skill = await helper.getSkillById(skillId)
378-
return _.pick(skill, ['id', 'name'])
379-
})
379+
_.map(job.skills, (skillId) => helper.getSkillById(skillId))
380380
)
381381
}
382382

0 commit comments

Comments
 (0)