Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 9c1428b

Browse files
author
vikasrohit
authored
Merge pull request #7 from topcoder-platform/develop
Prod release - Calling new skills api
2 parents 5a9c1c4 + baeddc1 commit 9c1428b

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ workflows:
8282
branches:
8383
only:
8484
- develop
85+
- feature/skills-api-shapeup
8586
# production builds are executed on "master" branch only.
8687
- "build-prod":
8788
context : org-global

config/default.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ module.exports = {
1313
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
1414
// The ubahn api url
1515
UBAHN_API_URL: process.env.UBAHN_API_URL || 'https://api.topcoder-dev.com/v5',
16+
// TC BETA API url
17+
TC_BETA_API_URL: process.env.TC_BETA_API_URL || 'https://api.topcoder-dev.com/v5.1',
1618
// The topcoder api url
1719
TC_API_URL: process.env.TC_API_URL || 'https://api.topcoder-dev.com',
18-
// The skill provider name
19-
SKILL_PROVIDER_NAME: process.env.SKILL_PROVIDER_NAME || 'Topcoder',
20+
// The taxonomy name
21+
TAXONOMY_NAME: process.env.TAXONOMY_NAME || 'Topcoder',
2022
// The pause time between two create operations, default value: 1000 ms
2123
SLEEP_TIME: parseInt(process.env.SLEEP_TIME || 1000)
2224
}

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ const helper = require('./src/common/helper')
1111
* @param {String} userId the userId
1212
* @param {String} tagId the tag id
1313
* @param {Number} score the skill score
14-
* @param {String} skillProviderId the skillProvider id
14+
* @param {String} taxonomyId the taxonomy id
1515
* @param {boolean} isDelete if delete the skill
1616
* @returns {Promise}
1717
*/
18-
async function syncUserSkill(userId, tagId, score, skillProviderId, isDelete) {
18+
async function syncUserSkill(userId, tagId, score, taxonomyId, isDelete) {
1919
const name = await helper.getTagName(tagId)
20-
const skill = await helper.getUbahnResource('skills', { skillProviderId, name })
20+
const skill = await helper.getV5SkillResource('skills', { taxonomyId, name })
2121
const skillExist = await helper.checkUserSkillExist(userId, skill.id)
2222
if (isDelete && skillExist) {
2323
helper.deleteUserSkill(userId, skill.id)
@@ -35,7 +35,7 @@ async function syncUserSkill(userId, tagId, score, skillProviderId, isDelete) {
3535
module.exports.handle = async (event) => {
3636
try {
3737
console.log(`Received event: `, JSON.stringify(event))
38-
const skillProvider = await helper.getUbahnResource('skillsProviders', { name: config.SKILL_PROVIDER_NAME })
38+
const taxonomy = await helper.getV5SkillResource('taxonomies', { name: config.TAXONOMY_NAME })
3939
for (const record of event.Records) {
4040
try {
4141
const handle = _.get(record, 'dynamodb.NewImage.userHandle.S')
@@ -53,15 +53,15 @@ module.exports.handle = async (event) => {
5353
console.log('Skills to delete:', JSON.stringify(deleteSkills))
5454
const user = await helper.getUser(handle)
5555
for (const key of _.keys(createSkills)) {
56-
await syncUserSkill(user.id, key, _.get(createSkills,`${key}.score`, 0), skillProvider.id)
56+
await syncUserSkill(user.id, key, _.get(createSkills,`${key}.score`, 0), taxonomy.id)
5757
await helper.sleep()
5858
}
5959
for (const key of _.keys(updateSkills)) {
60-
await syncUserSkill(user.id, key, _.get(createSkills,`${key}.score`, 0), skillProvider.id)
60+
await syncUserSkill(user.id, key, _.get(createSkills,`${key}.score`, 0), taxonomy.id)
6161
await helper.sleep()
6262
}
6363
for (const key of _.keys(deleteSkills)) {
64-
await syncUserSkill(user.id, key, 0, skillProvider.id, true)
64+
await syncUserSkill(user.id, key, 0, taxonomy.id, true)
6565
await helper.sleep()
6666
}
6767
} catch (e) {

src/common/helper.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,26 @@ const getM2MUbahnToken = async () => {
4242
}
4343

4444
/**
45-
* Get the u-bahn record
45+
* Get the V5 Skill/Taxonomy record
46+
* @param {String} path the resource path
47+
* @param {String} params the query params
48+
* @returns {Object} the u-bahn user
49+
*/
50+
async function getV5SkillResource (path, params) {
51+
const token = await getM2MUbahnToken()
52+
const res = await axios.get(`${config.TC_BETA_API_URL}/${path}`, {
53+
params,
54+
headers: { Authorization: `Bearer ${token}` }
55+
})
56+
const result = _.head(_.get(res, 'data'))
57+
if (!result) {
58+
throw Error(`Cannot find u-bahn resource ${path} with params ${JSON.stringify(params)}`)
59+
}
60+
return result
61+
}
62+
63+
/**
64+
* Get the ubahn record
4665
* @param {String} path the resource path
4766
* @param {String} params the query params
4867
* @returns {Object} the u-bahn user
@@ -131,7 +150,7 @@ module.exports = {
131150
sleep,
132151
getM2MToken,
133152
getM2MUbahnToken,
134-
getUbahnResource,
153+
getV5SkillResource,
135154
deleteUserSkill,
136155
updateUserSkill,
137156
createUserSkill,

0 commit comments

Comments
 (0)