Skip to content

Commit 1057409

Browse files
Merge pull request #445 from topcoder-platform/feature/weekly-surveys
[DEV] Send weekly surveys for Work Periods
2 parents e5d8118 + 06469ea commit 1057409

11 files changed

+577
-9
lines changed

app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const logger = require('./src/common/logger')
1414
const eventHandlers = require('./src/eventHandlers')
1515
const interviewService = require('./src/services/InterviewService')
1616
const { processScheduler } = require('./src/services/PaymentSchedulerService')
17+
const { sendSurveys } = require('./src/services/SurveyService')
1718

1819
// setup express app
1920
const app = express()
@@ -98,7 +99,8 @@ const server = app.listen(app.get('port'), () => {
9899
eventHandlers.init()
99100
// schedule updateCompletedInterviews to run every hour
100101
schedule.scheduleJob('0 0 * * * *', interviewService.updateCompletedInterviews)
101-
102+
// schedule sendSurveys
103+
schedule.scheduleJob(config.WEEKLY_SURVEY.CRON, sendSurveys)
102104
// schedule payment processing
103105
schedule.scheduleJob(config.PAYMENT_PROCESSING.CRON, processScheduler)
104106
})

config/default.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ module.exports = {
180180
INTERNAL_MEMBER_GROUPS: process.env.INTERNAL_MEMBER_GROUPS || ['20000000', '20000001', '20000003', '20000010', '20000015'],
181181
// Topcoder skills cache time in minutes
182182
TOPCODER_SKILLS_CACHE_TIME: process.env.TOPCODER_SKILLS_CACHE_TIME || 60,
183+
// weekly survey scheduler config
184+
WEEKLY_SURVEY: {
185+
CRON: process.env.WEEKLY_SURVEY_CRON || '0 1 * * 7',
186+
BASE_URL: process.env.WEEKLY_SURVEY_BASE_URL || 'https://api.surveymonkey.net/v3/surveys',
187+
JWT_TOKEN: process.env.WEEKLY_SURVEY_JWT_TOKEN || '',
188+
SURVEY_ID: process.env.WEEKLY_SURVEY_SURVEY_ID || '',
189+
SURVEY_MASTER_COLLECTOR_ID: process.env.WEEKLY_SURVEY_SURVEY_MASTER_COLLECTOR_ID || '',
190+
SURVEY_MASTER_MESSAGE_ID: process.env.WEEKLY_SURVEY_SURVEY_MASTER_MESSAGE_ID || '',
191+
SURVEY_CONTACT_GROUP_ID: process.env.WEEKLY_SURVEY_SURVEY_CONTACT_GROUP_ID || ''
192+
},
183193
// payment scheduler config
184194
PAYMENT_PROCESSING: {
185195
// switch off actual API calls in Payment Scheduler

docs/swagger.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,6 +4595,10 @@ components:
45954595
format: float
45964596
example: 13
45974597
description: "The member rate."
4598+
sendWeeklySurvey:
4599+
type: boolean
4600+
example: true,
4601+
description: "whether we should send weekly survey to this ResourceBooking or no"
45984602
customerRate:
45994603
type: integer
46004604
format: float
@@ -4652,6 +4656,10 @@ components:
46524656
format: uuid
46534657
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
46544658
description: "The external id."
4659+
sendWeeklySurvey:
4660+
type: boolean
4661+
example: true,
4662+
description: "whether we should send weekly survey to this ResourceBooking or no"
46554663
jobId:
46564664
type: string
46574665
format: uuid
@@ -4709,6 +4717,10 @@ components:
47094717
format: float
47104718
example: 13.23
47114719
description: "The member rate."
4720+
sendWeeklySurvey:
4721+
type: boolean
4722+
example: true,
4723+
description: "whether we should send weekly survey to this ResourceBooking or no"
47124724
customerRate:
47134725
type: number
47144726
format: float
@@ -4745,6 +4757,22 @@ components:
47454757
type: string
47464758
format: uuid
47474759
description: "The resource booking id."
4760+
sentSurvey:
4761+
type: boolean
4762+
example: true
4763+
description: "whether we've already sent a survey for this WorkPeriod of no"
4764+
sentSurveyError:
4765+
description: "error details if error happened during sending survey"
4766+
type: object
4767+
properties:
4768+
errorMessage:
4769+
type: string
4770+
example: "error message"
4771+
description: "The error message"
4772+
errorCode:
4773+
type: integer
4774+
example: 429
4775+
description: "HTTP code of error"
47484776
userHandle:
47494777
type: string
47504778
example: "eisbilir"
@@ -4822,6 +4850,22 @@ components:
48224850
maximum: 10
48234851
example: 2
48244852
description: "The count of the days worked for that work period."
4853+
sentSurvey:
4854+
type: boolean
4855+
example: true
4856+
description: "whether we've already sent a survey for this WorkPeriod of no"
4857+
sentSurveyError:
4858+
description: "error details if error happened during sending survey"
4859+
type: object
4860+
properties:
4861+
errorMessage:
4862+
type: string
4863+
example: "error message"
4864+
description: "The error message"
4865+
errorCode:
4866+
type: integer
4867+
example: 429
4868+
description: "HTTP code of error"
48254869
WorkPeriodPayment:
48264870
required:
48274871
- id
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const config = require('config')
2+
const moment = require('moment')
3+
4+
module.exports = {
5+
up: async (queryInterface, Sequelize) => {
6+
const transaction = await queryInterface.sequelize.transaction()
7+
try {
8+
await queryInterface.addColumn({ tableName: 'resource_bookings', schema: config.DB_SCHEMA_NAME }, 'send_weekly_survey',
9+
{ type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true },
10+
{ transaction })
11+
await queryInterface.addColumn({ tableName: 'work_periods', schema: config.DB_SCHEMA_NAME }, 'sent_survey',
12+
{ type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false },
13+
{ transaction })
14+
await queryInterface.addColumn({ tableName: 'work_periods', schema: config.DB_SCHEMA_NAME }, 'sent_survey_error',
15+
{
16+
type: Sequelize.JSONB({
17+
errorCode: {
18+
field: 'error_code',
19+
type: Sequelize.INTEGER,
20+
},
21+
errorMessage: {
22+
field: 'error_message',
23+
type: Sequelize.STRING(255)
24+
},
25+
}), allowNull: true }, { transaction })
26+
await queryInterface.sequelize.query(`UPDATE ${config.DB_SCHEMA_NAME}.work_periods SET sent_survey = true where payment_status = 'completed' and end_date <= '${moment().subtract(7, 'days').format('YYYY-MM-DD')}'`,
27+
{ transaction })
28+
await transaction.commit()
29+
} catch (err) {
30+
await transaction.rollback()
31+
throw err
32+
}
33+
},
34+
down: async (queryInterface, Sequelize) => {
35+
const transaction = await queryInterface.sequelize.transaction()
36+
try {
37+
await queryInterface.removeColumn({ tableName: 'resource_bookings', schema: config.DB_SCHEMA_NAME }, 'send_weekly_survey', { transaction })
38+
await queryInterface.removeColumn({ tableName: 'work_periods', schema: config.DB_SCHEMA_NAME }, 'sent_survey', { transaction })
39+
await queryInterface.removeColumn({ tableName: 'work_periods', schema: config.DB_SCHEMA_NAME }, 'sent_survey_error', { transaction } )
40+
await transaction.commit()
41+
} catch (err) {
42+
await transaction.rollback()
43+
throw err
44+
}
45+
},
46+
}

src/common/helper.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ esIndexPropertyMapping[config.get('esConfig.ES_INDEX_RESOURCE_BOOKING')] = {
176176
endDate: { type: 'date', format: 'yyyy-MM-dd' },
177177
memberRate: { type: 'float' },
178178
customerRate: { type: 'float' },
179+
sendWeeklySurvey: { type: 'boolean' },
179180
rateType: { type: 'keyword' },
180181
billingAccountId: { type: 'integer', null_value: 0 },
181182
workPeriods: {
@@ -189,6 +190,14 @@ esIndexPropertyMapping[config.get('esConfig.ES_INDEX_RESOURCE_BOOKING')] = {
189190
},
190191
projectId: { type: 'integer' },
191192
userId: { type: 'keyword' },
193+
sentSurvey: { type: 'boolean' },
194+
sentSurveyError: {
195+
type: 'nested',
196+
properties: {
197+
errorCode: { type: 'integer' },
198+
errorMessage: { type: 'keyword' }
199+
}
200+
},
192201
startDate: { type: 'date', format: 'yyyy-MM-dd' },
193202
endDate: { type: 'date', format: 'yyyy-MM-dd' },
194203
daysWorked: { type: 'integer' },
@@ -2012,6 +2021,7 @@ async function getMembersSuggest (fragment) {
20122021
}
20132022

20142023
module.exports = {
2024+
encodeQueryString,
20152025
getParamFromCliArgs,
20162026
promptUser,
20172027
sleep,

0 commit comments

Comments
 (0)