From 42c2ac35c2cee34369179a925ef1d51961e3b6a6 Mon Sep 17 00:00:00 2001 From: yoution Date: Tue, 1 Jun 2021 15:28:15 +0800 Subject: [PATCH] Role & Skills Intake - Job Description Module --- ...coder-bookings-api.postman_collection.json | 42 +++++++++++- docs/swagger.yaml | 65 +++++++++++++++++++ src/common/helper.js | 24 +++++++ src/controllers/TeamController.js | 11 ++++ src/routes/TeamRoutes.js | 8 +++ src/services/TeamService.js | 24 +++++++ 6 files changed, 172 insertions(+), 2 deletions(-) diff --git a/docs/Topcoder-bookings-api.postman_collection.json b/docs/Topcoder-bookings-api.postman_collection.json index 74155753..0059a126 100644 --- a/docs/Topcoder-bookings-api.postman_collection.json +++ b/docs/Topcoder-bookings-api.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "58b277bb-0d1d-4bbf-919f-c5951ba0e1c0", + "_postman_id": "b25dc4fc-ac96-49a5-b8b0-7700c625d4d0", "name": "Topcoder-bookings-api", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, @@ -17647,6 +17647,44 @@ }, "response": [] }, + { + "name": "POST /taas-teams/getSkillsByJobDescription", + "request": { + "method": "POST", + "header": [ + { + "key": "Authorization", + "type": "text", + "value": "Bearer {{token_member}}" + }, + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": \"nodejs react c++ hello\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{URL}}/taas-teams/getSkillsByJobDescription", + "host": [ + "{{URL}}" + ], + "path": [ + "taas-teams", + "getSkillsByJobDescription" + ] + } + }, + "response": [] + }, { "name": "POST /taas-teams/email - member-issue-report", "request": { @@ -27007,4 +27045,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 1584f5cf..4359781a 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -3170,6 +3170,54 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" + + /taas-teams/getSkillsByJobDescription: + post: + tags: + - Teams + description: | + Get skill list by Job Description + security: + - bearerAuth: [] + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/TeamJobDescriptionRequestBody" + responses: + "200": + description: OK + content: + application/json: + schema: + type : array + items : { + $ref: "#/components/schemas/SkillItem" + } + "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" /taas-teams/email: post: tags: @@ -3282,6 +3330,15 @@ components: scheme: bearer bearerFormat: JWT schemas: + SkillItem: + properties: + tag: + type: string + type: + type: string + source: + type: string + Job: required: - id @@ -4666,6 +4723,14 @@ components: type: array items: $ref: "#/components/schemas/Skill" + TeamJobDescriptionRequestBody: + type: object + properties: + description: + type: string + description: "job description" + example: "nodejs and java" + TeamEmailRequestBody: type: object properties: diff --git a/src/common/helper.js b/src/common/helper.js index e68e5c58..64226267 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -1691,6 +1691,29 @@ async function substituteStringByObject(string, object) { return string; } + +/** + * Get tags from tagging service + * @param {String} description The challenge description + * @returns {Array} array of tags + */ +async function getTags (description) { + const data = { text: description, extract_confidence: false} + const type = "emsi/internal_no_refresh" + const url = `${config.TC_API}/contest-tagging/${type}`; + const res = await request + .post(url) + .set('Accept', 'application/json') + .send(querystring.stringify(data)) + + localLogger.debug({ + context: 'getTags', + message: `response body: ${JSON.stringify(res.body)}`, + }); + return _.get(res, 'body'); +} + + /** * @param {Object} currentUser the user performing the action * @param {Object} data title of project and any other info @@ -1752,6 +1775,7 @@ module.exports = { getMemberDetailsByHandles, getMemberDetailsByHandle, getMemberDetailsByEmails, + getTags, createProjectMember, listProjectMembers, listProjectMemberInvites, diff --git a/src/controllers/TeamController.js b/src/controllers/TeamController.js index ca4f1bca..94b831c5 100644 --- a/src/controllers/TeamController.js +++ b/src/controllers/TeamController.js @@ -108,6 +108,16 @@ async function getMe(req, res) { res.send(await service.getMe(req.authUser)); } + +/** + * Return skills by job description. + * @param req the request + * @param res the response + */ +async function getSkillsByJobDescription(req, res) { + res.send(await service.getSkillsByJobDescription(req.authUser, req.body)); +} + /** * * @param req the request @@ -127,5 +137,6 @@ module.exports = { searchInvites, deleteMember, getMe, + getSkillsByJobDescription, createProj, }; diff --git a/src/routes/TeamRoutes.js b/src/routes/TeamRoutes.js index 9bbe25c6..35292b01 100644 --- a/src/routes/TeamRoutes.js +++ b/src/routes/TeamRoutes.js @@ -36,6 +36,14 @@ module.exports = { scopes: [constants.Scopes.READ_TAAS_TEAM], }, }, + '/taas-teams/getSkillsByJobDescription': { + post: { + controller: 'TeamController', + method: 'getSkillsByJobDescription', + auth: 'jwt', + scopes: [constants.Scopes.READ_TAAS_TEAM], + }, + }, '/taas-teams/:id': { get: { controller: 'TeamController', diff --git a/src/services/TeamService.js b/src/services/TeamService.js index 3f6dbfd3..2ead4d74 100644 --- a/src/services/TeamService.js +++ b/src/services/TeamService.js @@ -669,6 +669,29 @@ getMe.schema = Joi.object() }) .required(); +/** + * Return skills by job description. + * + * @param {Object} currentUser the user who perform this operation. + * @params {Object} criteria the search criteria + * @returns {Object} the user data for current user + */ +async function getSkillsByJobDescription(currentUser,data) { + return helper.getTags(data.description) +} + +getSkillsByJobDescription.schema = Joi.object() + .keys({ + currentUser: Joi.object().required(), + data: Joi.object() + .keys({ + description: Joi.string().required(), + }) + .required(), + }) + .required(); + + /** * @param {Object} currentUser the user performing the operation. * @param {Object} data project data @@ -695,5 +718,6 @@ module.exports = { searchInvites, deleteMember, getMe, + getSkillsByJobDescription, createProj, };