Skip to content

Commit a753c27

Browse files
authored
Merge pull request #172 from imcaizheng/new-endpoint-taas-team-me-update
implement the `GET /taas-teams/me` endpoint without enrich parameter
2 parents f6abe98 + 26ba0c1 commit a753c27

File tree

6 files changed

+128
-20
lines changed

6 files changed

+128
-20
lines changed

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4694,6 +4694,30 @@
46944694
}
46954695
},
46964696
"response": []
4697+
},
4698+
{
4699+
"name": "GET /taas-teams/me",
4700+
"request": {
4701+
"method": "GET",
4702+
"header": [
4703+
{
4704+
"key": "Authorization",
4705+
"type": "text",
4706+
"value": "Bearer {{token_member}}"
4707+
}
4708+
],
4709+
"url": {
4710+
"raw": "{{URL}}/taas-teams/me",
4711+
"host": [
4712+
"{{URL}}"
4713+
],
4714+
"path": [
4715+
"taas-teams",
4716+
"me"
4717+
]
4718+
}
4719+
},
4720+
"response": []
46974721
}
46984722
]
46994723
},
@@ -9810,4 +9834,4 @@
98109834
]
98119835
}
98129836
]
9813-
}
9837+
}

docs/swagger.yaml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,52 @@ paths:
18941894
application/json:
18951895
schema:
18961896
$ref: '#/components/schemas/Error'
1897+
1898+
/taas-teams/me:
1899+
get:
1900+
tags:
1901+
- Teams
1902+
description: |
1903+
Return details about the current user.
1904+
security:
1905+
- bearerAuth: []
1906+
responses:
1907+
'200':
1908+
description: OK
1909+
content:
1910+
application/json:
1911+
schema:
1912+
$ref: '#/components/schemas/UbahnUser'
1913+
'400':
1914+
description: Bad request
1915+
content:
1916+
application/json:
1917+
schema:
1918+
$ref: '#/components/schemas/Error'
1919+
'401':
1920+
description: Not authenticated
1921+
content:
1922+
application/json:
1923+
schema:
1924+
$ref: '#/components/schemas/Error'
1925+
'403':
1926+
description: Forbidden
1927+
content:
1928+
application/json:
1929+
schema:
1930+
$ref: '#/components/schemas/Error'
1931+
'404':
1932+
description: Not Found
1933+
content:
1934+
application/json:
1935+
schema:
1936+
$ref: '#/components/schemas/Error'
1937+
'500':
1938+
description: Internal Server Error
1939+
content:
1940+
application/json:
1941+
schema:
1942+
$ref: '#/components/schemas/Error'
18971943
/health:
18981944
get:
18991945
tags:
@@ -2719,10 +2765,13 @@ components:
27192765
example: '[email protected]'
27202766
ProjectMember:
27212767
type: object
2722-
example: {"id": 14329, "userId": 40159097, "role": "customer", "createdAt": "2021-02-24T12:34:45.074Z", "updatedAt": "2021-02-24T12:34:45.075Z", "createdBy": -101, "updatedBy": -101, "handle": "tester1234", "photoURL": null, "workingHourStart": "9:00", "workingHourEnd": "17:00", "timeZone": "Asia/Kolkata", "email": "sathya.jayabal@gmail.com"}
2768+
example: {"id": 14329, "userId": 40159097, "role": "customer", "createdAt": "2021-02-24T12:34:45.074Z", "updatedAt": "2021-02-24T12:34:45.075Z", "createdBy": -101, "updatedBy": -101, "handle": "tester1234", "photoURL": null, "workingHourStart": "9:00", "workingHourEnd": "17:00", "timeZone": "Asia/Kolkata", "email": "xxx@xxx.com"}
27232769
ProjectMemberInvite:
27242770
type: object
27252771
example: {"createdAt": "2021-02-24T11:02:12.673Z", "deletedAt": null, "role": "customer", "updatedBy": -101, "createdBy": -101, "id": 3686, "projectId": 16705, "userId": 23008602, "email": null, "deletedBy": null, "updatedAt": "2021-02-24T11:02:12.674Z", "status": "pending"}
2772+
UbahnUser:
2773+
type: object
2774+
example: {"lastName": "DeLaurentis", "updatedBy": "tcAdmin", "achievements": [{"certifierId": "certifierId", "updatedBy": "tcAdmin", "createdBy": "tc-user", "certifiedDate": "2020-05-04T07:36:28.036Z", "created": "2020-05-13T08:44:27.244Z", "name": "Topcoder", "id": "a49e1013-fd42-4c08-bc12-492510cadb96", "achievementsProviderId": "ce05133f-129e-484d-9ef9-72bf51ff81f9", "uri": "http://www.google.com/xx", "updated": "2021-01-05T10:58:32.429Z", "userId": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699", "achievementprovider": {"updatedBy": "tcAdmin", "createdBy": "tc-user", "created": "2020-05-13T08:42:41.877Z", "name": "achievementsProviders_02", "id": "ce05133f-129e-484d-9ef9-72bf51ff81f9", "updated": "2021-01-05T10:58:32.341Z"}}], "created": "2020-05-05T10:18:03.882Z", "handle": "lazybaer", "skills": [{"certifierId": null, "skillId": "d67f35c3-fa42-4866-a0f9-0a4b84fcf4a9", "updatedBy": "tcAdmin", "createdBy": "lazybaer", "certifiedDate": null, "created": "2020-10-23T16:22:11.208Z", "skill": {"updatedBy": "tcAdmin", "skillprovider": {"updatedBy": "tcAdmin", "createdBy": "TonyJ", "created": "2020-08-31T12:30:00.543Z", "name": "Wipro Digital", "id": "26fb37b1-5f9f-4727-baa9-f3c87de84ab1", "updated": "2021-01-05T10:58:32.836Z"}, "createdBy": "0", "created": "2020-09-01T21:59:21.554Z", "skillProviderId": "26fb37b1-5f9f-4727-baa9-f3c87de84ab1", "name": "GitHub", "externalId": null, "id": "d67f35c3-fa42-4866-a0f9-0a4b84fcf4a9", "uri": null, "updated": "2021-01-05T10:58:33.332Z"}, "metricValue": null, "id": "8a84c1b4-1884-4a3c-90b2-eb86bf469bb6", "updated": "2021-01-05T10:58:34.080Z", "userId": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699"}], "firstName": "Christopher", "externalProfiles": [{"organizationId": "0d2320f9-be61-4ba4-973e-edc3bb682a69", "updatedBy": "tcAdmin", "createdBy": "TonyJ", "isInactive": false, "created": "2020-08-31T12:30:38.495Z", "organization": {"updatedBy": "tcAdmin", "createdBy": "TonyJ", "created": "2020-08-31T12:29:58.081Z", "name": "Wipro Digital", "skillProviders": [{"organizationId": "0d2320f9-be61-4ba4-973e-edc3bb682a69", "updatedBy": "tcAdmin", "createdBy": "TonyJ", "created": "2020-08-31T12:30:08.410Z", "skillProviderId": "26fb37b1-5f9f-4727-baa9-f3c87de84ab1", "id": "5b26cdd3-fe68-4b30-85c5-ceaf280bd688", "updated": "2021-01-05T10:58:32.919Z"}], "id": "0d2320f9-be61-4ba4-973e-edc3bb682a69", "updated": "2021-01-05T10:58:32.261Z"}, "externalId": "8547899", "id": "870af97b-8c3b-4659-92d6-cac126bbe9de", "uri": null, "updated": "2021-01-05T10:58:32.724Z", "userId": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699"}], "createdBy": "tc-Copilot", "attributes": [{"attributeId": "d709276a-80c3-491c-9b29-a4f065b2a56f", "updatedBy": "tcAdmin", "createdBy": "tc-Admin", "created": "2020-05-13T08:19:13.709Z", "id": "21de9324-900d-41ea-b127-f297dfb9a873", "attribute": {"updatedBy": "tcAdmin", "attributegroup": {"organizationId": "36ed815b-3da1-49f1-a043-aaed0a4e81ad", "updatedBy": "tc-Admin", "createdBy": "tc-Admin", "created": "2020-05-13T07:15:01.215Z", "name": "group 03", "id": "84634bbd-8191-40cf-a03e-9962d7e39fda", "updated": "2020-05-13T07:16:20.636Z"}, "createdBy": "tc-Admin", "created": "2020-05-13T07:32:03.128Z", "name": "Billing Account", "id": "d709276a-80c3-491c-9b29-a4f065b2a56f", "attributeGroupId": "84634bbd-8191-40cf-a03e-9962d7e39fda", "updated": "2021-01-05T10:58:32.604Z"}, "value": "74314457", "updated": "2021-01-05T10:58:33.739Z", "userId": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699"}], "id": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699", "updated": "2021-01-05T10:58:32.113Z"}
27262775
Error:
27272776
required:
27282777
- message

src/common/helper.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -598,17 +598,17 @@ function encodeQueryString (queryObj, nesting = '') {
598598
}
599599

600600
/**
601-
* Function to get user ids
602-
* @param {Integer} userId user id from jwt token
603-
* @returns {String} user id.
601+
* Function to list users by external id.
602+
* @param {Integer} externalId the legacy user id
603+
* @returns {Array} the users found
604604
*/
605-
async function getUserIds (userId) {
605+
async function listUsersByExternalId (externalId) {
606606
const token = await getM2MUbahnToken()
607607
const q = {
608608
enrich: true,
609609
externalProfile: {
610610
organizationId: config.ORG_ID,
611-
externalId: userId
611+
externalId
612612
}
613613
}
614614
const url = `${config.TC_API}/users?${encodeQueryString(q)}`
@@ -617,21 +617,21 @@ async function getUserIds (userId) {
617617
.set('Authorization', `Bearer ${token}`)
618618
.set('Content-Type', 'application/json')
619619
.set('Accept', 'application/json')
620-
localLogger.debug({ context: 'getUserIds', message: `response body: ${JSON.stringify(res.body)}` })
620+
localLogger.debug({ context: 'listUserByExternalId', message: `response body: ${JSON.stringify(res.body)}` })
621621
return res.body
622622
}
623623

624624
/**
625-
* Function to get user id
626-
* @param {Integer} userId user id from jwt token
627-
* @returns {String} user id.
625+
* Function to get user by external id.
626+
* @param {Integer} externalId the legacy user id
627+
* @returns {Object} the user
628628
*/
629-
async function getUserId (userId) {
630-
const ids = await getUserIds(userId)
631-
if (_.isEmpty(ids)) {
632-
throw new errors.NotFoundError(`userId: ${userId} "user" not found`)
629+
async function getUserByExternalId (externalId) {
630+
const users = await listUsersByExternalId(externalId)
631+
if (_.isEmpty(users)) {
632+
throw new errors.NotFoundError(`externalId: ${externalId} "user" not found`)
633633
}
634-
return ids[0].id
634+
return users[0]
635635
}
636636

637637
/**
@@ -883,7 +883,7 @@ async function getSkillById (skillId) {
883883
}
884884

885885
/**
886-
* Encapsulate the getUserId function.
886+
* Encapsulate the getUserByExternalId function.
887887
* Make sure a user exists in ubahn(/v5/users) and return the id of the user.
888888
*
889889
* In the case the user does not exist in /v5/users but can be found in /v3/users
@@ -894,7 +894,7 @@ async function getSkillById (skillId) {
894894
*/
895895
async function ensureUbahnUserId (currentUser) {
896896
try {
897-
return await getUserId(currentUser.userId)
897+
return (await getUserByExternalId(currentUser.userId)).id
898898
} catch (err) {
899899
if (!(err instanceof errors.NotFoundError)) {
900900
throw err
@@ -1138,6 +1138,7 @@ module.exports = {
11381138
}
11391139
return ensureUbahnUserId({ userId })
11401140
},
1141+
getUserByExternalId,
11411142
getM2MToken,
11421143
getM2MUbahnToken,
11431144
postEvent,

src/controllers/TeamController.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ async function deleteMember (req, res) {
8383
res.status(HttpStatus.NO_CONTENT).end()
8484
}
8585

86+
/**
87+
* Return details about the current user.
88+
* @param req the request
89+
* @param res the response
90+
*/
91+
async function getMe (req, res) {
92+
res.send(await service.getMe(req.authUser))
93+
}
94+
8695
module.exports = {
8796
searchTeams,
8897
getTeam,
@@ -91,5 +100,6 @@ module.exports = {
91100
addMembers,
92101
searchMembers,
93102
searchInvites,
94-
deleteMember
103+
deleteMember,
104+
getMe
95105
}

src/routes/TeamRoutes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ module.exports = {
2828
scopes: [constants.Scopes.READ_TAAS_TEAM]
2929
}
3030
},
31+
'/taas-teams/me': {
32+
get: {
33+
controller: 'TeamController',
34+
method: 'getMe',
35+
auth: 'jwt',
36+
scopes: [constants.Scopes.READ_TAAS_TEAM]
37+
}
38+
},
3139
'/taas-teams/:id': {
3240
get: {
3341
controller: 'TeamController',

src/services/TeamService.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,21 @@ deleteMember.schema = Joi.object().keys({
513513
projectMemberId: Joi.number().integer().required()
514514
}).required()
515515

516+
/**
517+
* Return details about the current user.
518+
*
519+
* @param {Object} currentUser the user who perform this operation.
520+
* @params {Object} criteria the search criteria
521+
* @returns {Object} the user data for current user
522+
*/
523+
async function getMe (currentUser) {
524+
return helper.getUserByExternalId(currentUser.userId)
525+
}
526+
527+
getMe.schema = Joi.object().keys({
528+
currentUser: Joi.object().required()
529+
}).required()
530+
516531
module.exports = {
517532
searchTeams,
518533
getTeam,
@@ -521,5 +536,6 @@ module.exports = {
521536
addMembers,
522537
searchMembers,
523538
searchInvites,
524-
deleteMember
539+
deleteMember,
540+
getMe
525541
}

0 commit comments

Comments
 (0)