Skip to content

implement taas-teams skills endpoint #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The following parameters can be set in config files or in env variables:
- `PROJECT_API_URL`: the project service url
- `TC_API`: the Topcoder v5 url
- `ORG_ID`: the organization id
- `TOPCODER_SKILL_PROVIDER_ID`: the referenced skill provider id

- `esConfig.HOST`: the elasticsearch host
- `esConfig.ES_INDEX_JOB`: the job index
Expand Down
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {

TC_API: process.env.TC_API || 'https://api.topcoder-dev.com/v5',
ORG_ID: process.env.ORG_ID || '36ed815b-3da1-49f1-a043-aaed0a4e81ad',
TOPCODER_SKILL_PROVIDER_ID: process.env.TOPCODER_SKILL_PROVIDER_ID,

TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users',

Expand Down
39 changes: 39 additions & 0 deletions docs/Topcoder-bookings-api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -4366,6 +4366,45 @@
}
},
"response": []
},
{
"name": "GET /taas-teams/skills",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{token_member}}",
"type": "text"
}
],
"url": {
"raw": "{{URL}}/taas-teams/skills?perPage=10&page=1&orderBy=name",
"host": [
"{{URL}}"
],
"path": [
"taas-teams",
"skills"
],
"query": [
{
"key": "perPage",
"value": "10"
},
{
"key": "page",
"value": "1"
},
{
"key": "orderBy",
"value": "name",
"description": "possible values are defined by /v5/skills"
}
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
Expand Down
126 changes: 126 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,96 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/taas-teams/skills:
get:
tags:
- Teams
description: |
Serves as a proxy endpoint for /v5/skills, allowing to be accessed by any topcoder user.
parameters:
- in: query
name: page
required: false
schema:
type: integer
default: 1
description: The page number.
- in: query
name: perPage
required: false
schema:
type: integer
default: 20
description: The number of items to list per page.
- name: orderBy
in: query
schema:
type: string
description: "Specify by which field to sort by. Sorts in ascending order only"
security:
- bearerAuth: []
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UbahnSkill'
headers:
X-Next-Page:
schema:
type: integer
description: The index of the next page
X-Page:
schema:
type: integer
description: The index of the current page (starting at 1)
X-Per-Page:
schema:
type: integer
description: The number of items to list per page
X-Prev-Page:
schema:
type: integer
description: The index of the previous page
X-Total:
schema:
type: integer
description: The total number of items
X-Total-Pages:
schema:
type: integer
description: The total number of pages
Link:
schema:
type: string
description: Pagination link header.
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: Not authenticated
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/health:
get:
tags:
Expand Down Expand Up @@ -2056,6 +2146,42 @@ components:
type: string
example: 'React'
description: The skill name.
UbahnSkill:
type: object
properties:
id:
type: "string"
format: "UUID"
description: "The skill id"
skillProviderId:
type: "string"
format: "UUID"
description: "The referenced skill provider id"
name:
type: "string"
description: "The name of the skill"
externalId:
type: "string"
description: "The external id for the skill"
uri:
type: "string"
description: "The uri for the skill"
created:
type: "string"
format: "date-time"
description: "When the entity was created."
updated:
type: "string"
format: "date-time"
description: "When the entity was updated."
createdBy:
type: "string"
format: "UUID"
description: "Creator of the entity."
updatedBy:
type: "string"
format: "UUID"
description: "User that last updated the entity."
JobForTeam:
properties:
id:
Expand Down
33 changes: 33 additions & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,38 @@ async function getProjectById (currentUser, id) {
}
}

/**
* Function to search skills from v5/skills
* @param {Object} criteria the search criteria
* @returns the request result
*/
async function getSkills (criteria) {
const token = await getM2Mtoken()
try {
const res = await request
.get(`${config.TC_API}/skills`)
.query({
skillProviderId: config.TOPCODER_SKILL_PROVIDER_ID,
...criteria
})
.set('Authorization', `Bearer ${token}`)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
localLogger.debug({ context: 'getSkills', message: `response body: ${JSON.stringify(res.body)}` })
return {
total: Number(_.get(res.headers, 'x-total')),
page: Number(_.get(res.headers, 'x-page')),
perPage: Number(_.get(res.headers, 'x-per-page')),
result: res.body
}
} catch (err) {
if (err.status === HttpStatus.BAD_REQUEST) {
throw new errors.BadRequestError(err.response.body.message)
}
throw err
}
}

/**
* Function to get skill by id
* @param {String} skillId the skill Id
Expand Down Expand Up @@ -612,6 +644,7 @@ module.exports = {
getUserById,
getMembers,
getProjectById,
getSkills,
getSkillById,
getUserSkill,
ensureJobById,
Expand Down
20 changes: 20 additions & 0 deletions src/controllers/SkillController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Controller for skills endpoints
*/
const service = require('../services/SkillService')
const helper = require('../common/helper')

/**
* Search skills
* @param req the request
* @param res the response
*/
async function searchSkills (req, res) {
const result = await service.searchSkills(req.query)
helper.setResHeaders(req, res, result)
res.send(result.result)
}

module.exports = {
searchSkills
}
8 changes: 8 additions & 0 deletions src/routes/TeamRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module.exports = {
scopes: [constants.Scopes.READ_TAAS_TEAM]
}
},
'/taas-teams/skills': {
get: {
controller: 'SkillController',
method: 'searchSkills',
auth: 'jwt',
scopes: [constants.Scopes.READ_TAAS_TEAM]
}
},
'/taas-teams/:id': {
get: {
controller: 'TeamController',
Expand Down
26 changes: 26 additions & 0 deletions src/services/SkillService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* This service provides operations of Skill.
*/
const Joi = require('joi')
const helper = require('../common/helper')

/**
* Search skills
* @param {Object} criteria the search criteria
* @returns {Object} the search result, contain total/page/perPage and result array
*/
async function searchSkills (criteria) {
return helper.getSkills(criteria)
}

searchSkills.schema = Joi.object().keys({
criteria: Joi.object().keys({
page: Joi.page(),
perPage: Joi.perPage(),
orderBy: Joi.string()
}).required()
}).required()

module.exports = {
searchSkills
}