Skip to content

Commit 2b7a591

Browse files
committed
feat: endpoint to get V5 user by handle
1 parent be2f50f commit 2b7a591

File tree

5 files changed

+94
-4
lines changed

5 files changed

+94
-4
lines changed

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "b1144d77-699c-47be-864e-fbe99e7f5c14",
3+
"_postman_id": "0c096a43-08c8-4152-83ca-1d544f92cad4",
44
"name": "Topcoder-bookings-api",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},
@@ -4431,6 +4431,37 @@
44314431
}
44324432
},
44334433
"response": []
4434+
},
4435+
{
4436+
"name": "GET /taas-teams/users/:handle",
4437+
"request": {
4438+
"method": "GET",
4439+
"header": [
4440+
{
4441+
"key": "Authorization",
4442+
"type": "text",
4443+
"value": "Bearer {{token_member}}"
4444+
}
4445+
],
4446+
"url": {
4447+
"raw": "{{URL}}/taas-teams/users/:handle",
4448+
"host": [
4449+
"{{URL}}"
4450+
],
4451+
"path": [
4452+
"taas-teams",
4453+
"users",
4454+
":handle"
4455+
],
4456+
"variable": [
4457+
{
4458+
"key": "handle",
4459+
"value": "pshah_customer"
4460+
}
4461+
]
4462+
}
4463+
},
4464+
"response": []
44344465
}
44354466
]
44364467
},

src/common/helper.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,26 @@ async function getMembers (handles) {
440440
return res.body
441441
}
442442

443+
/**
444+
* Get Topcoder Member by handle
445+
*
446+
* @param {String} handle user handle
447+
*
448+
* @returns the request result
449+
*/
450+
async function getMemberByHandle (handle) {
451+
const token = await getM2MToken()
452+
const url = `${config.TC_API}/members/${handle}`
453+
454+
const res = await request
455+
.get(url)
456+
.set('Authorization', `Bearer ${token}`)
457+
.set('Content-Type', 'application/json')
458+
.set('Accept', 'application/json')
459+
localLogger.debug({ context: 'getMemberByHandle', message: `handle: "${handle}", response body: ${JSON.stringify(res.body)}` })
460+
return res.body
461+
}
462+
443463
/**
444464
* Function to get project by id
445465
* @param {Object} currentUser the user who perform this operation
@@ -641,5 +661,6 @@ module.exports = {
641661
ensureJobById,
642662
ensureUserById,
643663
getAuditM2Muser,
644-
checkIsMemberOfProject
664+
checkIsMemberOfProject,
665+
getMemberByHandle
645666
}

src/controllers/SkillController.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ async function searchSkills (req, res) {
1515
res.send(result.result)
1616
}
1717

18+
/**
19+
* Get V5 U-bahn user by handle
20+
* If user doesn't exists in V5 it creates it
21+
*
22+
* @param req the request
23+
* @param res the response
24+
*/
25+
async function getUserByHandle (req, res) {
26+
res.send(await service.getUserByHandle(req.params.handle))
27+
}
28+
1829
module.exports = {
19-
searchSkills
30+
searchSkills,
31+
getUserByHandle
2032
}

src/routes/TeamRoutes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ module.exports = {
2020
scopes: [constants.Scopes.READ_TAAS_TEAM]
2121
}
2222
},
23+
'/taas-teams/users/:handle': {
24+
get: {
25+
controller: 'SkillController',
26+
method: 'getUserByHandle',
27+
auth: 'jwt',
28+
scopes: [constants.Scopes.READ_TAAS_TEAM]
29+
}
30+
},
2331
'/taas-teams/:id': {
2432
get: {
2533
controller: 'TeamController',

src/services/SkillService.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ searchSkills.schema = Joi.object().keys({
2121
}).required()
2222
}).required()
2323

24+
/**
25+
* Get V5 U-bahn user by handle
26+
* If user doesn't exists in V5 it creates it
27+
*
28+
* @param {Object} handle user handle
29+
*
30+
* @returns {Object} V5 user
31+
*/
32+
async function getUserByHandle(handle) {
33+
const v3User = await helper.getMemberByHandle(handle);
34+
const v5userId = await helper.getUserId(v3User.userId);
35+
36+
return {
37+
userId: v5userId
38+
};
39+
}
40+
2441
module.exports = {
25-
searchSkills
42+
searchSkills,
43+
getUserByHandle,
2644
}

0 commit comments

Comments
 (0)