From b5cd87536bf8d848d3c767cd30414c1b6a7c6bf5 Mon Sep 17 00:00:00 2001 From: vikasrohit Date: Wed, 18 Aug 2021 09:03:09 +0530 Subject: [PATCH 1/8] Adapting for new V5 skills api --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index b0fbb8e..41d9ba7 100644 --- a/index.js +++ b/index.js @@ -11,13 +11,13 @@ const helper = require('./src/common/helper') * @param {String} userId the userId * @param {String} tagId the tag id * @param {Number} score the skill score - * @param {String} skillProviderId the skillProvider id + * @param {String} taxonomyId the taxonomy id * @param {boolean} isDelete if delete the skill * @returns {Promise} */ -async function syncUserSkill(userId, tagId, score, skillProviderId, isDelete) { +async function syncUserSkill(userId, tagId, score, taxonomyId, isDelete) { const name = await helper.getTagName(tagId) - const skill = await helper.getUbahnResource('skills', { skillProviderId, name }) + const skill = await helper.getUbahnResource('skills', { taxonomyId, name }) const skillExist = await helper.checkUserSkillExist(userId, skill.id) if (isDelete && skillExist) { helper.deleteUserSkill(userId, skill.id) @@ -35,7 +35,7 @@ async function syncUserSkill(userId, tagId, score, skillProviderId, isDelete) { module.exports.handle = async (event) => { try { console.log(`Received event: `, JSON.stringify(event)) - const skillProvider = await helper.getUbahnResource('skillsProviders', { name: config.SKILL_PROVIDER_NAME }) + const taxonomy = await helper.getUbahnResource('taxonomies', { name: config.TAXONOMY_NAME }) for (const record of event.Records) { try { const handle = _.get(record, 'dynamodb.NewImage.userHandle.S') @@ -53,15 +53,15 @@ module.exports.handle = async (event) => { console.log('Skills to delete:', JSON.stringify(deleteSkills)) const user = await helper.getUser(handle) for (const key of _.keys(createSkills)) { - await syncUserSkill(user.id, key, _.get(createSkills,`${key}.score`, 0), skillProvider.id) + await syncUserSkill(user.id, key, _.get(createSkills,`${key}.score`, 0), taxonomy.id) await helper.sleep() } for (const key of _.keys(updateSkills)) { - await syncUserSkill(user.id, key, _.get(createSkills,`${key}.score`, 0), skillProvider.id) + await syncUserSkill(user.id, key, _.get(createSkills,`${key}.score`, 0), taxonomy.id) await helper.sleep() } for (const key of _.keys(deleteSkills)) { - await syncUserSkill(user.id, key, 0, skillProvider.id, true) + await syncUserSkill(user.id, key, 0, taxonomy.id, true) await helper.sleep() } } catch (e) { From 82ab154087b4c4185e82d32e7000450e6476a292 Mon Sep 17 00:00:00 2001 From: vikasrohit Date: Wed, 18 Aug 2021 09:05:57 +0530 Subject: [PATCH 2/8] Renamed configuration parameter for taxonomy name --- config/default.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/default.js b/config/default.js index 632ce30..b0a4452 100644 --- a/config/default.js +++ b/config/default.js @@ -15,8 +15,8 @@ module.exports = { UBAHN_API_URL: process.env.UBAHN_API_URL || 'https://api.topcoder-dev.com/v5', // The topcoder api url TC_API_URL: process.env.TC_API_URL || 'https://api.topcoder-dev.com', - // The skill provider name - SKILL_PROVIDER_NAME: process.env.SKILL_PROVIDER_NAME || 'Topcoder', + // The taxonomy name + TAXONOMY_NAME: process.env.TAXONOMY_NAME || 'Topcoder', // The pause time between two create operations, default value: 1000 ms SLEEP_TIME: parseInt(process.env.SLEEP_TIME || 1000) } From 55e975b6edad9b29072c5ebefb79a51427e05bb6 Mon Sep 17 00:00:00 2001 From: vikasrohit Date: Wed, 18 Aug 2021 09:10:08 +0530 Subject: [PATCH 3/8] Updated method and env names to reflect non ubahn api --- src/common/helper.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/helper.js b/src/common/helper.js index c6e0b70..ab6d9d0 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -42,14 +42,14 @@ const getM2MUbahnToken = async () => { } /** - * Get the u-bahn record + * Get the V5 Skill/Taxonomy record * @param {String} path the resource path * @param {String} params the query params * @returns {Object} the u-bahn user */ -async function getUbahnResource (path, params) { +async function getV5SkillResource (path, params) { const token = await getM2MUbahnToken() - const res = await axios.get(`${config.UBAHN_API_URL}/${path}`, { + const res = await axios.get(`${config.TC_BETA_API}/${path}`, { params, headers: { Authorization: `Bearer ${token}` } }) @@ -131,7 +131,7 @@ module.exports = { sleep, getM2MToken, getM2MUbahnToken, - getUbahnResource, + getV5SkillResource, deleteUserSkill, updateUserSkill, createUserSkill, From 85305a41f6c61750e5f8b539384f1457fd90e9c5 Mon Sep 17 00:00:00 2001 From: vikasrohit Date: Wed, 18 Aug 2021 09:10:53 +0530 Subject: [PATCH 4/8] Using updated getV5SkillResource method --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 41d9ba7..ae801ab 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ const helper = require('./src/common/helper') */ async function syncUserSkill(userId, tagId, score, taxonomyId, isDelete) { const name = await helper.getTagName(tagId) - const skill = await helper.getUbahnResource('skills', { taxonomyId, name }) + const skill = await helper.getV5SkillResource('skills', { taxonomyId, name }) const skillExist = await helper.checkUserSkillExist(userId, skill.id) if (isDelete && skillExist) { helper.deleteUserSkill(userId, skill.id) @@ -35,7 +35,7 @@ async function syncUserSkill(userId, tagId, score, taxonomyId, isDelete) { module.exports.handle = async (event) => { try { console.log(`Received event: `, JSON.stringify(event)) - const taxonomy = await helper.getUbahnResource('taxonomies', { name: config.TAXONOMY_NAME }) + const taxonomy = await helper.getV5SkillResource('taxonomies', { name: config.TAXONOMY_NAME }) for (const record of event.Records) { try { const handle = _.get(record, 'dynamodb.NewImage.userHandle.S') From ccf7d04380b689ff3fa374a30b2345d5375d492c Mon Sep 17 00:00:00 2001 From: vikasrohit Date: Wed, 18 Aug 2021 09:11:48 +0530 Subject: [PATCH 5/8] Introducing TC_BETA_API_URL --- config/default.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/default.js b/config/default.js index b0a4452..054b30e 100644 --- a/config/default.js +++ b/config/default.js @@ -13,6 +13,8 @@ module.exports = { AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET, // The ubahn api url UBAHN_API_URL: process.env.UBAHN_API_URL || 'https://api.topcoder-dev.com/v5', + // TC BETA API url + TC_BETA_API_URL: process.env.TC_BETA_API_URL || 'https://api.topcoder-dev.com/v5.1', // The topcoder api url TC_API_URL: process.env.TC_API_URL || 'https://api.topcoder-dev.com', // The taxonomy name From dc893fafe2813008d6728db9e8d2d0ea48a288e9 Mon Sep 17 00:00:00 2001 From: vikasrohit Date: Wed, 18 Aug 2021 09:12:15 +0530 Subject: [PATCH 6/8] Using updated TC_BETA_API_URL env variable --- src/common/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/helper.js b/src/common/helper.js index ab6d9d0..bc63b8e 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -49,7 +49,7 @@ const getM2MUbahnToken = async () => { */ async function getV5SkillResource (path, params) { const token = await getM2MUbahnToken() - const res = await axios.get(`${config.TC_BETA_API}/${path}`, { + const res = await axios.get(`${config.TC_BETA_API_URL}/${path}`, { params, headers: { Authorization: `Bearer ${token}` } }) From 57d98ab7f31d96254aada0c6795df4ae7d4e0d9e Mon Sep 17 00:00:00 2001 From: vikasrohit Date: Wed, 18 Aug 2021 09:48:13 +0530 Subject: [PATCH 7/8] deployable feature branch --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 69a0800..9e93d47 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -82,6 +82,7 @@ workflows: branches: only: - develop + - feature/skills-api-shapeup # production builds are executed on "master" branch only. - "build-prod": context : org-global From b917f0a1cb1c3c9d32ed9632823ade69c45e58ad Mon Sep 17 00:00:00 2001 From: vikasrohit Date: Wed, 18 Aug 2021 10:27:55 +0530 Subject: [PATCH 8/8] Readded getUbahnResource helper It was called by getUser method as well --- src/common/helper.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/common/helper.js b/src/common/helper.js index bc63b8e..86ac1a5 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -60,6 +60,25 @@ async function getV5SkillResource (path, params) { return result } +/** + * Get the ubahn record + * @param {String} path the resource path + * @param {String} params the query params + * @returns {Object} the u-bahn user + */ +async function getUbahnResource (path, params) { + const token = await getM2MUbahnToken() + const res = await axios.get(`${config.UBAHN_API_URL}/${path}`, { + params, + headers: { Authorization: `Bearer ${token}` } + }) + const result = _.head(_.get(res, 'data')) + if (!result) { + throw Error(`Cannot find u-bahn resource ${path} with params ${JSON.stringify(params)}`) + } + return result +} + /** * Create user skill * @param {String} userId the user id