Skip to content

Commit e31d6c1

Browse files
authored
Merge pull request #393 from eisbilir/members-suggest
proxy endpoint for member suggestion
2 parents 8e8541f + 57e5fd2 commit e31d6c1

File tree

7 files changed

+368
-5
lines changed

7 files changed

+368
-5
lines changed

config/default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ module.exports = {
4141
TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users',
4242
// the api to find topcoder members
4343
TOPCODER_MEMBERS_API: process.env.TOPCODER_MEMBERS_API || 'https://api.topcoder-dev.com/v5/members',
44+
// the v3 api to find topcoder members
45+
TOPCODER_MEMBERS_API_V3: process.env.TOPCODER_MEMBERS_API_V3 || 'https://api.topcoder-dev.com/v3/members',
4446
// rate limit of requests to user api
4547
MAX_PARALLEL_REQUEST_TOPCODER_USERS_API: process.env.MAX_PARALLEL_REQUEST_TOPCODER_USERS_API || 100,
4648

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 242 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "15f10b58-dda5-4aaf-96e5-061a5c901717",
3+
"_postman_id": "87477d86-2d08-40b6-93c6-99a394193e28",
44
"name": "Topcoder-bookings-api",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},
@@ -19312,6 +19312,247 @@
1931219312
}
1931319313
]
1931419314
},
19315+
{
19316+
"name": "Member Suggestion",
19317+
"item": [
19318+
{
19319+
"name": "get member suggestion successfully with administrator",
19320+
"event": [
19321+
{
19322+
"listen": "test",
19323+
"script": {
19324+
"exec": [
19325+
"pm.test('Status code is 200', function () {\r",
19326+
" pm.response.to.have.status(200);\r",
19327+
"});"
19328+
],
19329+
"type": "text/javascript"
19330+
}
19331+
}
19332+
],
19333+
"request": {
19334+
"method": "GET",
19335+
"header": [
19336+
{
19337+
"key": "Authorization",
19338+
"type": "text",
19339+
"value": "Bearer {{token_administrator}}"
19340+
}
19341+
],
19342+
"url": {
19343+
"raw": "{{URL}}/taas-teams/members-suggest/maxceem",
19344+
"host": [
19345+
"{{URL}}"
19346+
],
19347+
"path": [
19348+
"taas-teams",
19349+
"members-suggest",
19350+
"maxceem"
19351+
]
19352+
}
19353+
},
19354+
"response": []
19355+
},
19356+
{
19357+
"name": "get member suggestion successfully with booking manager",
19358+
"event": [
19359+
{
19360+
"listen": "test",
19361+
"script": {
19362+
"exec": [
19363+
"pm.test('Status code is 200', function () {\r",
19364+
" pm.response.to.have.status(200);\r",
19365+
"});"
19366+
],
19367+
"type": "text/javascript"
19368+
}
19369+
}
19370+
],
19371+
"request": {
19372+
"method": "GET",
19373+
"header": [
19374+
{
19375+
"key": "Authorization",
19376+
"type": "text",
19377+
"value": "Bearer {{token_bookingManager}}"
19378+
}
19379+
],
19380+
"url": {
19381+
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
19382+
"host": [
19383+
"{{URL}}"
19384+
],
19385+
"path": [
19386+
"taas-teams",
19387+
"members-suggest",
19388+
"isbilir"
19389+
]
19390+
}
19391+
},
19392+
"response": []
19393+
},
19394+
{
19395+
"name": "get member suggestion with connect manager",
19396+
"event": [
19397+
{
19398+
"listen": "test",
19399+
"script": {
19400+
"exec": [
19401+
"pm.test('Status code is 403', function () {\r",
19402+
" pm.response.to.have.status(403);\r",
19403+
" const response = pm.response.json()\r",
19404+
" pm.expect(response.message).to.eq(\"You are not allowed to perform this action!\")\r",
19405+
"});"
19406+
],
19407+
"type": "text/javascript"
19408+
}
19409+
}
19410+
],
19411+
"request": {
19412+
"method": "GET",
19413+
"header": [
19414+
{
19415+
"key": "Authorization",
19416+
"type": "text",
19417+
"value": "Bearer {{token_connect_manager_pshahcopmanag2}}"
19418+
}
19419+
],
19420+
"url": {
19421+
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
19422+
"host": [
19423+
"{{URL}}"
19424+
],
19425+
"path": [
19426+
"taas-teams",
19427+
"members-suggest",
19428+
"isbilir"
19429+
]
19430+
}
19431+
},
19432+
"response": []
19433+
},
19434+
{
19435+
"name": "get member suggestion with member",
19436+
"event": [
19437+
{
19438+
"listen": "test",
19439+
"script": {
19440+
"exec": [
19441+
"pm.test('Status code is 403', function () {\r",
19442+
" pm.response.to.have.status(403);\r",
19443+
" const response = pm.response.json()\r",
19444+
" pm.expect(response.message).to.eq(\"You are not allowed to perform this action!\")\r",
19445+
"});"
19446+
],
19447+
"type": "text/javascript"
19448+
}
19449+
}
19450+
],
19451+
"request": {
19452+
"method": "GET",
19453+
"header": [
19454+
{
19455+
"key": "Authorization",
19456+
"type": "text",
19457+
"value": "Bearer {{token_member}}"
19458+
}
19459+
],
19460+
"url": {
19461+
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
19462+
"host": [
19463+
"{{URL}}"
19464+
],
19465+
"path": [
19466+
"taas-teams",
19467+
"members-suggest",
19468+
"isbilir"
19469+
]
19470+
}
19471+
},
19472+
"response": []
19473+
},
19474+
{
19475+
"name": "get member suggestion with m2m",
19476+
"event": [
19477+
{
19478+
"listen": "test",
19479+
"script": {
19480+
"exec": [
19481+
"pm.test('Status code is 403', function () {\r",
19482+
" pm.response.to.have.status(403);\r",
19483+
" const response = pm.response.json()\r",
19484+
" pm.expect(response.message).to.eq(\"You are not allowed to perform this action!\")\r",
19485+
"});"
19486+
],
19487+
"type": "text/javascript"
19488+
}
19489+
}
19490+
],
19491+
"request": {
19492+
"method": "GET",
19493+
"header": [
19494+
{
19495+
"key": "Authorization",
19496+
"type": "text",
19497+
"value": "Bearer {{token_m2m_all_job}}"
19498+
}
19499+
],
19500+
"url": {
19501+
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
19502+
"host": [
19503+
"{{URL}}"
19504+
],
19505+
"path": [
19506+
"taas-teams",
19507+
"members-suggest",
19508+
"isbilir"
19509+
]
19510+
}
19511+
},
19512+
"response": []
19513+
},
19514+
{
19515+
"name": "get member suggestion with invalid token",
19516+
"event": [
19517+
{
19518+
"listen": "test",
19519+
"script": {
19520+
"exec": [
19521+
"pm.test('Status code is 401', function () {\r",
19522+
" pm.response.to.have.status(401);\r",
19523+
" const response = pm.response.json()\r",
19524+
" pm.expect(response.message).to.eq(\"Invalid Token.\")\r",
19525+
"});"
19526+
],
19527+
"type": "text/javascript"
19528+
}
19529+
}
19530+
],
19531+
"request": {
19532+
"method": "GET",
19533+
"header": [
19534+
{
19535+
"key": "Authorization",
19536+
"type": "text",
19537+
"value": "Bearer invalid"
19538+
}
19539+
],
19540+
"url": {
19541+
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
19542+
"host": [
19543+
"{{URL}}"
19544+
],
19545+
"path": [
19546+
"taas-teams",
19547+
"members-suggest",
19548+
"isbilir"
19549+
]
19550+
}
19551+
},
19552+
"response": []
19553+
}
19554+
]
19555+
},
1931519556
{
1931619557
"name": "GET /taas-teams",
1931719558
"request": {

docs/swagger.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,6 +3296,41 @@ paths:
32963296
application/json:
32973297
schema:
32983298
$ref: "#/components/schemas/Error"
3299+
/taas-teams/members-suggest/{fragment}:
3300+
get:
3301+
tags:
3302+
- Teams
3303+
description: |
3304+
Returns suggested members for the given handle fragment
3305+
security:
3306+
- bearerAuth: []
3307+
responses:
3308+
"200":
3309+
description: OK
3310+
content:
3311+
application/json:
3312+
schema:
3313+
type: array
3314+
items:
3315+
$ref: "#/components/schemas/SuggestedMember"
3316+
"401":
3317+
description: Not authenticated
3318+
content:
3319+
application/json:
3320+
schema:
3321+
$ref: "#/components/schemas/Error"
3322+
"403":
3323+
description: Forbidden
3324+
content:
3325+
application/json:
3326+
schema:
3327+
$ref: "#/components/schemas/Error"
3328+
"500":
3329+
description: Internal Server Error
3330+
content:
3331+
application/json:
3332+
schema:
3333+
$ref: "#/components/schemas/Error"
32993334
/taas-roles:
33003335
post:
33013336
tags:
@@ -5404,6 +5439,32 @@ components:
54045439
type: string
54055440
format: uuid
54065441
description: "The user Id who updated the role last time.(Will get the user info from the token)"
5442+
SuggestedMember:
5443+
properties:
5444+
userId:
5445+
type: number
5446+
example: 40157055
5447+
description: the user id
5448+
handle:
5449+
type: string
5450+
example: maxceemdev
5451+
description: the user handle
5452+
photoURL:
5453+
type: string
5454+
example: https://topcoder-dev-media.s3.amazonaws.com/member/profile/maxceem13-1587184611143.jpeg
5455+
description: the photo url
5456+
firstName:
5457+
type: string
5458+
example: Max
5459+
description: the firstname of the user
5460+
lastName:
5461+
type: string
5462+
example: Max
5463+
description: the lastname of the user
5464+
maxRating:
5465+
type: number
5466+
example: 1200
5467+
description: the maximum rating of the user
54075468
RoleRequestBody:
54085469
required:
54095470
- name

src/common/helper.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,26 @@ function removeTextFormatting (text) {
19881988
return text
19891989
}
19901990

1991+
/**
1992+
* Function to get member suggestions
1993+
* @param {string} fragment the handle fragment
1994+
* @return the request result
1995+
*/
1996+
async function getMembersSuggest (fragment) {
1997+
const token = await getM2MToken()
1998+
const url = `${config.TOPCODER_MEMBERS_API_V3}/_suggest/${encodeURIComponent(fragment)}`
1999+
const res = await request
2000+
.get(url)
2001+
.set('Authorization', `Bearer ${token}`)
2002+
.set('Content-Type', 'application/json')
2003+
.set('Accept', 'application/json')
2004+
localLogger.debug({
2005+
context: 'getMembersSuggest',
2006+
message: `response body: ${JSON.stringify(res.body)}`
2007+
})
2008+
return res.body
2009+
}
2010+
19912011
module.exports = {
19922012
getParamFromCliArgs,
19932013
promptUser,
@@ -2048,5 +2068,6 @@ module.exports = {
20482068
substituteStringByObject,
20492069
createProject,
20502070
getMemberGroups,
2051-
removeTextFormatting
2071+
removeTextFormatting,
2072+
getMembersSuggest
20522073
}

src/controllers/TeamController.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ async function searchSkills (req, res) {
146146
res.send(result.result)
147147
}
148148

149+
/**
150+
* Suggest members
151+
* @param req the request
152+
* @param res the response
153+
*/
154+
async function suggestMembers (req, res) {
155+
res.send(await service.suggestMembers(req.authUser, req.params.fragment))
156+
}
157+
149158
module.exports = {
150159
searchTeams,
151160
getTeam,
@@ -159,5 +168,6 @@ module.exports = {
159168
getSkillsByJobDescription,
160169
roleSearchRequest,
161170
createTeam,
162-
searchSkills
171+
searchSkills,
172+
suggestMembers
163173
}

0 commit comments

Comments
 (0)