Skip to content

Commit dcbef2c

Browse files
authored
Merge branch 'dev' into feature/notifications-api
2 parents 8cb97d5 + 16cc100 commit dcbef2c

File tree

6 files changed

+56
-35
lines changed

6 files changed

+56
-35
lines changed

app-constants.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ const WorkPeriodPaymentStatus = {
114114
* The top rule has priority over the bottom rules.
115115
*/
116116
const PaymentStatusRules = [
117-
{ paymentStatus: AggregatePaymentStatus.NO_DAYS, condition: { daysWorked: 0 } },
118117
{ paymentStatus: AggregatePaymentStatus.IN_PROGRESS, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.SCHEDULED, WorkPeriodPaymentStatus.IN_PROGRESS] } },
119118
{ paymentStatus: AggregatePaymentStatus.COMPLETED, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.COMPLETED], hasDueDays: false } },
120119
{ paymentStatus: AggregatePaymentStatus.PARTIALLY_COMPLETED, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.COMPLETED], hasDueDays: true } },
121-
{ paymentStatus: AggregatePaymentStatus.PENDING, condition: { hasDueDays: true } }
120+
{ paymentStatus: AggregatePaymentStatus.PENDING, condition: { hasDueDays: true } },
121+
{ paymentStatus: AggregatePaymentStatus.NO_DAYS, condition: { daysWorked: 0 } }
122122
]
123123

124124
/**
@@ -144,6 +144,11 @@ const PaymentProcessingSwitch = {
144144
OFF: 'OFF'
145145
}
146146

147+
const WeeklySurveySwitch = {
148+
ON: 'ON',
149+
OFF: 'OFF'
150+
}
151+
147152
const PaymentSchedulerStatus = {
148153
START_PROCESS: 'start-process',
149154
CREATE_CHALLENGE: 'create-challenge',
@@ -173,6 +178,7 @@ module.exports = {
173178
PaymentSchedulerStatus,
174179
PaymentProcessingSwitch,
175180
PaymentStatusRules,
181+
WeeklySurveySwitch,
176182
ActiveWorkPeriodPaymentStatuses,
177183
JobStatus,
178184
JobCandidateStatus

app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const interviewService = require('./src/services/InterviewService')
1616
const { processScheduler } = require('./src/services/PaymentSchedulerService')
1717
const { sendSurveys } = require('./src/services/SurveyService')
1818
const notificationSchedulerService = require('./src/services/NotificationsSchedulerService')
19+
const { WeeklySurveySwitch } = require('./app-constants')
1920

2021
// setup express app
2122
const app = express()
@@ -101,7 +102,9 @@ const server = app.listen(app.get('port'), () => {
101102
// schedule updateCompletedInterviews to run every hour
102103
schedule.scheduleJob('0 0 * * * *', interviewService.updateCompletedInterviews)
103104
// schedule sendSurveys
104-
schedule.scheduleJob(config.WEEKLY_SURVEY.CRON, sendSurveys)
105+
if (WeeklySurveySwitch.ON === config.WEEKLY_SURVEY.SWITCH) {
106+
schedule.scheduleJob(config.WEEKLY_SURVEY.CRON, sendSurveys)
107+
}
105108
// schedule payment processing
106109
schedule.scheduleJob(config.PAYMENT_PROCESSING.CRON, processScheduler)
107110

config/default.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ module.exports = {
3333

3434
// the Topcoder v5 url
3535
TC_API: process.env.TC_API || 'https://api.topcoder-dev.com/v5',
36+
// the Topcoder Beta API url currently v5.1
37+
TC_BETA_API: process.env.TC_BETA_API || 'https://api.topcoder-dev.com/v5.1',
3638
// the organization id
3739
ORG_ID: process.env.ORG_ID || '36ed815b-3da1-49f1-a043-aaed0a4e81ad',
38-
// the referenced skill provider id
39-
TOPCODER_SKILL_PROVIDER_ID: process.env.TOPCODER_SKILL_PROVIDER_ID || '9cc0795a-6e12-4c84-9744-15858dba1861',
40+
// the referenced taxonomy id
41+
TOPCODER_TAXONOMY_ID: process.env.TOPCODER_TAXONOMY_ID || '7637ae1a-3b7c-44eb-a5ed-10ea02f1885d',
4042

4143
TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users',
4244
// the api to find topcoder members
@@ -190,6 +192,7 @@ module.exports = {
190192
TOPCODER_SKILLS_CACHE_TIME: process.env.TOPCODER_SKILLS_CACHE_TIME || 60,
191193
// weekly survey scheduler config
192194
WEEKLY_SURVEY: {
195+
SWITCH: process.env.WEEKLY_SURVEY_SWITCH || 'OFF',
193196
CRON: process.env.WEEKLY_SURVEY_CRON || '0 1 * * 7',
194197
BASE_URL: process.env.WEEKLY_SURVEY_BASE_URL || 'https://api.surveymonkey.net/v3/surveys',
195198
JWT_TOKEN: process.env.WEEKLY_SURVEY_JWT_TOKEN || '',

docs/swagger.yaml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,7 +3212,7 @@ paths:
32123212
schema:
32133213
type: array
32143214
items:
3215-
$ref: "#/components/schemas/UbahnSkill"
3215+
$ref: "#/components/schemas/SkillInSkillsAPI"
32163216
headers:
32173217
X-Next-Page:
32183218
schema:
@@ -5574,17 +5574,25 @@ components:
55745574
type: string
55755575
example: "React"
55765576
description: The skill name.
5577-
UbahnSkill:
5578-
type: object
5577+
SkillInSkillsAPI:
5578+
required:
5579+
- "id"
5580+
- "name"
5581+
- "taxonomyId"
5582+
- "taxonomyName"
5583+
- "metadata"
55795584
properties:
55805585
id:
55815586
type: "string"
55825587
format: "UUID"
55835588
description: "The skill id"
5584-
skillProviderId:
5589+
taxonomyId:
55855590
type: "string"
55865591
format: "UUID"
5587-
description: "The referenced skill provider id"
5592+
description: "The referenced taxonomy id"
5593+
taxonomyName:
5594+
type: "string"
5595+
description: "The referenced taxonomy name"
55885596
name:
55895597
type: "string"
55905598
description: "The name of the skill"
@@ -5594,22 +5602,20 @@ components:
55945602
uri:
55955603
type: "string"
55965604
description: "The uri for the skill"
5597-
created:
5598-
type: "string"
5599-
format: "date-time"
5600-
description: "When the entity was created."
5601-
updated:
5602-
type: "string"
5603-
format: "date-time"
5604-
description: "When the entity was updated."
5605-
createdBy:
5606-
type: "string"
5607-
format: "UUID"
5608-
description: "Creator of the entity."
5609-
updatedBy:
5610-
type: "string"
5611-
format: "UUID"
5612-
description: "User that last updated the entity."
5605+
metadata:
5606+
type: "object"
5607+
description: "The metadata for the skill"
5608+
properties:
5609+
updated:
5610+
type: "string"
5611+
format: "date-time"
5612+
description: "The last updated timestamp of the skill"
5613+
challengeProminence:
5614+
type: "string"
5615+
description: "The challenge prominence ranging from [0, 1]"
5616+
memberProminence:
5617+
type: "string"
5618+
description: "The member prominence ranging from [0, 1]"
56135619
JobForTeam:
56145620
properties:
56155621
id:

src/bootstrap.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Joi = require('joi')
33
const config = require('config')
44
const path = require('path')
55
const _ = require('lodash')
6-
const { Interviews, AggregatePaymentStatus, WorkPeriodPaymentStatus, WorkPeriodPaymentUpdateStatus, PaymentProcessingSwitch } = require('../app-constants')
6+
const { Interviews, AggregatePaymentStatus, WorkPeriodPaymentStatus, WorkPeriodPaymentUpdateStatus, PaymentProcessingSwitch, WeeklySurveySwitch } = require('../app-constants')
77
const logger = require('./common/logger')
88

99
const allowedInterviewStatuses = _.values(Interviews.Status)
@@ -51,8 +51,12 @@ buildServices(path.join(__dirname, 'services'))
5151
const paymentProcessingSwitchSchema = Joi.string().label('PAYMENT_PROCESSING_SWITCH').valid(
5252
...Object.values(PaymentProcessingSwitch)
5353
)
54+
const weeklySurveySwitchSchema = Joi.string().label('WEEKLY_SURVEY_SWITCH').valid(
55+
...Object.values(WeeklySurveySwitch)
56+
)
5457
try {
5558
Joi.attempt(config.PAYMENT_PROCESSING.SWITCH, paymentProcessingSwitchSchema)
59+
Joi.attempt(config.WEEKLY_SURVEY.SWITCH, weeklySurveySwitchSchema)
5660
} catch (err) {
5761
console.error(err.message)
5862
process.exit(1)

src/common/helper.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ async function listUsersByExternalId (externalId) {
951951
context: 'listUserByExternalId',
952952
message: `response body: ${JSON.stringify(res.body)}`
953953
})
954+
954955
return res.body
955956
}
956957

@@ -1093,9 +1094,7 @@ async function getUserById (userId, enrich) {
10931094
const user = _.pick(res.body, ['id', 'handle', 'firstName', 'lastName'])
10941095

10951096
if (enrich) {
1096-
user.skills = (res.body.skills || []).map((skillObj) =>
1097-
_.pick(skillObj.skill, ['id', 'name'])
1098-
)
1097+
user.skills = await Promise.all((res.body.skills || []).map(async (userSkill) => getSkillById(userSkill.skillId)))
10991098
const attributes = _.get(res, 'body.attributes', [])
11001099
user.attributes = _.map(attributes, (attr) =>
11011100
_.pick(attr, ['id', 'value', 'attribute.id', 'attribute.name'])
@@ -1212,7 +1211,7 @@ async function getProjectById (currentUser, id) {
12121211

12131212
/**
12141213
* Function to search skills from v5/skills
1215-
* - only returns skills from Topcoder Skills Provider defined by `TOPCODER_SKILL_PROVIDER_ID`
1214+
* - only returns skills from Topcoder Skills API defined by `TOPCODER_TAXONOMY_ID`
12161215
*
12171216
* @param {Object} criteria the search criteria
12181217
* @returns the request result
@@ -1221,9 +1220,9 @@ async function getTopcoderSkills (criteria) {
12211220
const token = await getM2MUbahnToken()
12221221
try {
12231222
const res = await request
1224-
.get(`${config.TC_API}/skills`)
1223+
.get(`${config.TC_BETA_API}/skills`)
12251224
.query({
1226-
skillProviderId: config.TOPCODER_SKILL_PROVIDER_ID,
1225+
taxonomyId: config.TOPCODER_TAXONOMY_ID,
12271226
...criteria
12281227
})
12291228
.set('Authorization', `Bearer ${token}`)
@@ -1249,7 +1248,7 @@ async function getTopcoderSkills (criteria) {
12491248

12501249
/**
12511250
* Function to search and retrive all skills from v5/skills
1252-
* - only returns skills from Topcoder Skills Provider defined by `TOPCODER_SKILL_PROVIDER_ID`
1251+
* - only returns skills from Topcoder Skills API defined by `TOPCODER_TAXONOMY_ID`
12531252
*
12541253
* @param {Object} criteria the search criteria
12551254
* @returns the request result
@@ -1273,7 +1272,7 @@ async function getAllTopcoderSkills (criteria) {
12731272
async function getSkillById (skillId) {
12741273
const token = await getM2MUbahnToken()
12751274
const res = await request
1276-
.get(`${config.TC_API}/skills/${skillId}`)
1275+
.get(`${config.TC_BETA_API}/skills/${skillId}`)
12771276
.set('Authorization', `Bearer ${token}`)
12781277
.set('Content-Type', 'application/json')
12791278
.set('Accept', 'application/json')

0 commit comments

Comments
 (0)