From 2b7a591c8fb0b84d39d7ebd3c103edc64cd66394 Mon Sep 17 00:00:00 2001 From: maxceem Date: Wed, 13 Jan 2021 11:32:37 +0200 Subject: [PATCH 1/3] feat: endpoint to get V5 user by handle --- ...coder-bookings-api.postman_collection.json | 33 ++++++++++++++++++- src/common/helper.js | 23 ++++++++++++- src/controllers/SkillController.js | 14 +++++++- src/routes/TeamRoutes.js | 8 +++++ src/services/SkillService.js | 20 ++++++++++- 5 files changed, 94 insertions(+), 4 deletions(-) diff --git a/docs/Topcoder-bookings-api.postman_collection.json b/docs/Topcoder-bookings-api.postman_collection.json index 6eb03c1f..f8c7fb70 100644 --- a/docs/Topcoder-bookings-api.postman_collection.json +++ b/docs/Topcoder-bookings-api.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "b1144d77-699c-47be-864e-fbe99e7f5c14", + "_postman_id": "0c096a43-08c8-4152-83ca-1d544f92cad4", "name": "Topcoder-bookings-api", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, @@ -4431,6 +4431,37 @@ } }, "response": [] + }, + { + "name": "GET /taas-teams/users/:handle", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "type": "text", + "value": "Bearer {{token_member}}" + } + ], + "url": { + "raw": "{{URL}}/taas-teams/users/:handle", + "host": [ + "{{URL}}" + ], + "path": [ + "taas-teams", + "users", + ":handle" + ], + "variable": [ + { + "key": "handle", + "value": "pshah_customer" + } + ] + } + }, + "response": [] } ] }, diff --git a/src/common/helper.js b/src/common/helper.js index a6a33d7c..c8d67ef0 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -440,6 +440,26 @@ async function getMembers (handles) { return res.body } +/** + * Get Topcoder Member by handle + * + * @param {String} handle user handle + * + * @returns the request result + */ +async function getMemberByHandle (handle) { + const token = await getM2MToken() + const url = `${config.TC_API}/members/${handle}` + + const res = await request + .get(url) + .set('Authorization', `Bearer ${token}`) + .set('Content-Type', 'application/json') + .set('Accept', 'application/json') + localLogger.debug({ context: 'getMemberByHandle', message: `handle: "${handle}", response body: ${JSON.stringify(res.body)}` }) + return res.body +} + /** * Function to get project by id * @param {Object} currentUser the user who perform this operation @@ -641,5 +661,6 @@ module.exports = { ensureJobById, ensureUserById, getAuditM2Muser, - checkIsMemberOfProject + checkIsMemberOfProject, + getMemberByHandle } diff --git a/src/controllers/SkillController.js b/src/controllers/SkillController.js index 0dd13ea7..d97e4584 100644 --- a/src/controllers/SkillController.js +++ b/src/controllers/SkillController.js @@ -15,6 +15,18 @@ async function searchSkills (req, res) { res.send(result.result) } +/** + * Get V5 U-bahn user by handle + * If user doesn't exists in V5 it creates it + * + * @param req the request + * @param res the response + */ +async function getUserByHandle (req, res) { + res.send(await service.getUserByHandle(req.params.handle)) +} + module.exports = { - searchSkills + searchSkills, + getUserByHandle } diff --git a/src/routes/TeamRoutes.js b/src/routes/TeamRoutes.js index 7cfff792..b15e0bb1 100644 --- a/src/routes/TeamRoutes.js +++ b/src/routes/TeamRoutes.js @@ -20,6 +20,14 @@ module.exports = { scopes: [constants.Scopes.READ_TAAS_TEAM] } }, + '/taas-teams/users/:handle': { + get: { + controller: 'SkillController', + method: 'getUserByHandle', + auth: 'jwt', + scopes: [constants.Scopes.READ_TAAS_TEAM] + } + }, '/taas-teams/:id': { get: { controller: 'TeamController', diff --git a/src/services/SkillService.js b/src/services/SkillService.js index b3d33025..469b1446 100644 --- a/src/services/SkillService.js +++ b/src/services/SkillService.js @@ -21,6 +21,24 @@ searchSkills.schema = Joi.object().keys({ }).required() }).required() +/** + * Get V5 U-bahn user by handle + * If user doesn't exists in V5 it creates it + * + * @param {Object} handle user handle + * + * @returns {Object} V5 user + */ +async function getUserByHandle(handle) { + const v3User = await helper.getMemberByHandle(handle); + const v5userId = await helper.getUserId(v3User.userId); + + return { + userId: v5userId + }; +} + module.exports = { - searchSkills + searchSkills, + getUserByHandle, } From 7d740150aadbceab05eae5068c89e15353a4ad48 Mon Sep 17 00:00:00 2001 From: maxceem Date: Wed, 13 Jan 2021 18:27:41 +0200 Subject: [PATCH 2/3] feat: make some Job fields longer ref issue #109 --- .../2021-01-13-make-some-job-fields-longer.js | 20 +++++++++++++++++++ src/bootstrap.js | 2 +- src/models/Job.js | 14 ++++++------- src/models/JobCandidate.js | 6 +++--- src/models/ResourceBooking.js | 4 ++-- 5 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 migrations/2021-01-13-make-some-job-fields-longer.js diff --git a/migrations/2021-01-13-make-some-job-fields-longer.js b/migrations/2021-01-13-make-some-job-fields-longer.js new file mode 100644 index 00000000..286fd888 --- /dev/null +++ b/migrations/2021-01-13-make-some-job-fields-longer.js @@ -0,0 +1,20 @@ +/* + * Make some Job fields longer + * title: 64 -> 128 + * description: change type to TEXT (unlimited length) + */ + +module.exports = { + up: queryInterface => { + return Promise.all([ + queryInterface.sequelize.query(`ALTER TABLE bookings.jobs ALTER COLUMN title TYPE VARCHAR(128)`), + queryInterface.sequelize.query(`ALTER TABLE bookings.jobs ALTER COLUMN description TYPE TEXT`) + ]) + }, + down: queryInterface => { + return Promise.all([ + queryInterface.sequelize.query(`ALTER TABLE bookings.jobs ALTER COLUMN title TYPE VARCHAR(64)`), + queryInterface.sequelize.query(`ALTER TABLE bookings.jobs ALTER COLUMN description TYPE VARCHAR(255)`) + ]) + } +} diff --git a/src/bootstrap.js b/src/bootstrap.js index 8e14bba3..eaaf88ec 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -9,7 +9,7 @@ Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly') Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled') Joi.workload = () => Joi.string().valid('full-time', 'fractional') Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled') -Joi.title = () => Joi.string().max(64) +Joi.title = () => Joi.string().max(128) function buildServices (dir) { const files = fs.readdirSync(dir) diff --git a/src/models/Job.js b/src/models/Job.js index 3e278a15..14cec753 100644 --- a/src/models/Job.js +++ b/src/models/Job.js @@ -66,13 +66,13 @@ module.exports = (sequelize) => { }, externalId: { field: 'external_id', - type: Sequelize.STRING + type: Sequelize.STRING(255) }, description: { - type: Sequelize.STRING + type: Sequelize.TEXT, // technically unlimited length }, title: { - type: Sequelize.STRING, + type: Sequelize.STRING(128), allowNull: false }, startDate: { @@ -90,22 +90,22 @@ module.exports = (sequelize) => { }, resourceType: { field: 'resource_type', - type: Sequelize.STRING + type: Sequelize.STRING(255) }, rateType: { field: 'rate_type', - type: Sequelize.STRING + type: Sequelize.STRING(255) }, workload: { field: 'workload', - type: Sequelize.STRING + type: Sequelize.STRING(45) }, skills: { type: Sequelize.JSONB, allowNull: false }, status: { - type: Sequelize.STRING, + type: Sequelize.STRING(255), allowNull: false }, createdAt: { diff --git a/src/models/JobCandidate.js b/src/models/JobCandidate.js index 20d0831c..70632b66 100644 --- a/src/models/JobCandidate.js +++ b/src/models/JobCandidate.js @@ -53,15 +53,15 @@ module.exports = (sequelize) => { allowNull: false }, status: { - type: Sequelize.STRING, + type: Sequelize.STRING(255), allowNull: false }, externalId: { field: 'external_id', - type: Sequelize.STRING + type: Sequelize.STRING(255) }, resume: { - type: Sequelize.STRING + type: Sequelize.STRING(2048) }, createdAt: { field: 'created_at', diff --git a/src/models/ResourceBooking.js b/src/models/ResourceBooking.js index 93a62210..63557904 100644 --- a/src/models/ResourceBooking.js +++ b/src/models/ResourceBooking.js @@ -56,7 +56,7 @@ module.exports = (sequelize) => { type: Sequelize.UUID }, status: { - type: Sequelize.STRING, + type: Sequelize.STRING(255), allowNull: false }, startDate: { @@ -77,7 +77,7 @@ module.exports = (sequelize) => { }, rateType: { field: 'rate_type', - type: Sequelize.STRING, + type: Sequelize.STRING(255), allowNull: false }, createdAt: { From 2b6ccdb944985e6fafae4cea5771b77809eb33bd Mon Sep 17 00:00:00 2001 From: maxceem Date: Tue, 19 Jan 2021 17:42:47 +0200 Subject: [PATCH 3/3] Revert "feat: endpoint to get V5 user by handle" This reverts commit 2b7a591c8fb0b84d39d7ebd3c103edc64cd66394. --- ...coder-bookings-api.postman_collection.json | 33 +------------------ src/common/helper.js | 23 +------------ src/controllers/SkillController.js | 14 +------- src/routes/TeamRoutes.js | 8 ----- src/services/SkillService.js | 20 +---------- 5 files changed, 4 insertions(+), 94 deletions(-) diff --git a/docs/Topcoder-bookings-api.postman_collection.json b/docs/Topcoder-bookings-api.postman_collection.json index f8c7fb70..6eb03c1f 100644 --- a/docs/Topcoder-bookings-api.postman_collection.json +++ b/docs/Topcoder-bookings-api.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "0c096a43-08c8-4152-83ca-1d544f92cad4", + "_postman_id": "b1144d77-699c-47be-864e-fbe99e7f5c14", "name": "Topcoder-bookings-api", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, @@ -4431,37 +4431,6 @@ } }, "response": [] - }, - { - "name": "GET /taas-teams/users/:handle", - "request": { - "method": "GET", - "header": [ - { - "key": "Authorization", - "type": "text", - "value": "Bearer {{token_member}}" - } - ], - "url": { - "raw": "{{URL}}/taas-teams/users/:handle", - "host": [ - "{{URL}}" - ], - "path": [ - "taas-teams", - "users", - ":handle" - ], - "variable": [ - { - "key": "handle", - "value": "pshah_customer" - } - ] - } - }, - "response": [] } ] }, diff --git a/src/common/helper.js b/src/common/helper.js index c8d67ef0..a6a33d7c 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -440,26 +440,6 @@ async function getMembers (handles) { return res.body } -/** - * Get Topcoder Member by handle - * - * @param {String} handle user handle - * - * @returns the request result - */ -async function getMemberByHandle (handle) { - const token = await getM2MToken() - const url = `${config.TC_API}/members/${handle}` - - const res = await request - .get(url) - .set('Authorization', `Bearer ${token}`) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json') - localLogger.debug({ context: 'getMemberByHandle', message: `handle: "${handle}", response body: ${JSON.stringify(res.body)}` }) - return res.body -} - /** * Function to get project by id * @param {Object} currentUser the user who perform this operation @@ -661,6 +641,5 @@ module.exports = { ensureJobById, ensureUserById, getAuditM2Muser, - checkIsMemberOfProject, - getMemberByHandle + checkIsMemberOfProject } diff --git a/src/controllers/SkillController.js b/src/controllers/SkillController.js index d97e4584..0dd13ea7 100644 --- a/src/controllers/SkillController.js +++ b/src/controllers/SkillController.js @@ -15,18 +15,6 @@ async function searchSkills (req, res) { res.send(result.result) } -/** - * Get V5 U-bahn user by handle - * If user doesn't exists in V5 it creates it - * - * @param req the request - * @param res the response - */ -async function getUserByHandle (req, res) { - res.send(await service.getUserByHandle(req.params.handle)) -} - module.exports = { - searchSkills, - getUserByHandle + searchSkills } diff --git a/src/routes/TeamRoutes.js b/src/routes/TeamRoutes.js index b15e0bb1..7cfff792 100644 --- a/src/routes/TeamRoutes.js +++ b/src/routes/TeamRoutes.js @@ -20,14 +20,6 @@ module.exports = { scopes: [constants.Scopes.READ_TAAS_TEAM] } }, - '/taas-teams/users/:handle': { - get: { - controller: 'SkillController', - method: 'getUserByHandle', - auth: 'jwt', - scopes: [constants.Scopes.READ_TAAS_TEAM] - } - }, '/taas-teams/:id': { get: { controller: 'TeamController', diff --git a/src/services/SkillService.js b/src/services/SkillService.js index 469b1446..b3d33025 100644 --- a/src/services/SkillService.js +++ b/src/services/SkillService.js @@ -21,24 +21,6 @@ searchSkills.schema = Joi.object().keys({ }).required() }).required() -/** - * Get V5 U-bahn user by handle - * If user doesn't exists in V5 it creates it - * - * @param {Object} handle user handle - * - * @returns {Object} V5 user - */ -async function getUserByHandle(handle) { - const v3User = await helper.getMemberByHandle(handle); - const v5userId = await helper.getUserId(v3User.userId); - - return { - userId: v5userId - }; -} - module.exports = { - searchSkills, - getUserByHandle, + searchSkills }