Skip to content

[DEV] Send weekly surveys for Work Periods #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const logger = require('./src/common/logger')
const eventHandlers = require('./src/eventHandlers')
const interviewService = require('./src/services/InterviewService')
const { processScheduler } = require('./src/services/PaymentSchedulerService')
const { sendSurveys } = require('./src/services/SurveyService')

// setup express app
const app = express()
Expand Down Expand Up @@ -98,7 +99,8 @@ const server = app.listen(app.get('port'), () => {
eventHandlers.init()
// schedule updateCompletedInterviews to run every hour
schedule.scheduleJob('0 0 * * * *', interviewService.updateCompletedInterviews)

// schedule sendSurveys
schedule.scheduleJob(config.WEEKLY_SURVEY.CRON, sendSurveys)
// schedule payment processing
schedule.scheduleJob(config.PAYMENT_PROCESSING.CRON, processScheduler)
})
Expand Down
10 changes: 10 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ module.exports = {
INTERNAL_MEMBER_GROUPS: process.env.INTERNAL_MEMBER_GROUPS || ['20000000', '20000001', '20000003', '20000010', '20000015'],
// Topcoder skills cache time in minutes
TOPCODER_SKILLS_CACHE_TIME: process.env.TOPCODER_SKILLS_CACHE_TIME || 60,
// weekly survey scheduler config
WEEKLY_SURVEY: {
CRON: process.env.WEEKLY_SURVEY_CRON || '0 1 * * 7',
BASE_URL: process.env.WEEKLY_SURVEY_BASE_URL || 'https://api.surveymonkey.net/v3/surveys',
JWT_TOKEN: process.env.WEEKLY_SURVEY_JWT_TOKEN || '',
SURVEY_ID: process.env.WEEKLY_SURVEY_SURVEY_ID || '',
SURVEY_MASTER_COLLECTOR_ID: process.env.WEEKLY_SURVEY_SURVEY_MASTER_COLLECTOR_ID || '',
SURVEY_MASTER_MESSAGE_ID: process.env.WEEKLY_SURVEY_SURVEY_MASTER_MESSAGE_ID || '',
SURVEY_CONTACT_GROUP_ID: process.env.WEEKLY_SURVEY_SURVEY_CONTACT_GROUP_ID || ''
},
// payment scheduler config
PAYMENT_PROCESSING: {
// switch off actual API calls in Payment Scheduler
Expand Down
44 changes: 44 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4595,6 +4595,10 @@ components:
format: float
example: 13
description: "The member rate."
sendWeeklySurvey:
type: boolean
example: true,
description: "whether we should send weekly survey to this ResourceBooking or no"
customerRate:
type: integer
format: float
Expand Down Expand Up @@ -4652,6 +4656,10 @@ components:
format: uuid
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
description: "The external id."
sendWeeklySurvey:
type: boolean
example: true,
description: "whether we should send weekly survey to this ResourceBooking or no"
jobId:
type: string
format: uuid
Expand Down Expand Up @@ -4709,6 +4717,10 @@ components:
format: float
example: 13.23
description: "The member rate."
sendWeeklySurvey:
type: boolean
example: true,
description: "whether we should send weekly survey to this ResourceBooking or no"
customerRate:
type: number
format: float
Expand Down Expand Up @@ -4745,6 +4757,22 @@ components:
type: string
format: uuid
description: "The resource booking id."
sentSurvey:
type: boolean
example: true
description: "whether we've already sent a survey for this WorkPeriod of no"
sentSurveyError:
description: "error details if error happened during sending survey"
type: object
properties:
errorMessage:
type: string
example: "error message"
description: "The error message"
errorCode:
type: integer
example: 429
description: "HTTP code of error"
userHandle:
type: string
example: "eisbilir"
Expand Down Expand Up @@ -4822,6 +4850,22 @@ components:
maximum: 10
example: 2
description: "The count of the days worked for that work period."
sentSurvey:
type: boolean
example: true
description: "whether we've already sent a survey for this WorkPeriod of no"
sentSurveyError:
description: "error details if error happened during sending survey"
type: object
properties:
errorMessage:
type: string
example: "error message"
description: "The error message"
errorCode:
type: integer
example: 429
description: "HTTP code of error"
WorkPeriodPayment:
required:
- id
Expand Down
46 changes: 46 additions & 0 deletions migrations/2021-07-26-add-send-weekly-survery-fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const config = require('config')
const moment = require('moment')

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction()
try {
await queryInterface.addColumn({ tableName: 'resource_bookings', schema: config.DB_SCHEMA_NAME }, 'send_weekly_survey',
{ type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true },
{ transaction })
await queryInterface.addColumn({ tableName: 'work_periods', schema: config.DB_SCHEMA_NAME }, 'sent_survey',
{ type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false },
{ transaction })
await queryInterface.addColumn({ tableName: 'work_periods', schema: config.DB_SCHEMA_NAME }, 'sent_survey_error',
{
type: Sequelize.JSONB({
errorCode: {
field: 'error_code',
type: Sequelize.INTEGER,
},
errorMessage: {
field: 'error_message',
type: Sequelize.STRING(255)
},
}), allowNull: true }, { transaction })
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')}'`,
{ transaction })
await transaction.commit()
} catch (err) {
await transaction.rollback()
throw err
}
},
down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction()
try {
await queryInterface.removeColumn({ tableName: 'resource_bookings', schema: config.DB_SCHEMA_NAME }, 'send_weekly_survey', { transaction })
await queryInterface.removeColumn({ tableName: 'work_periods', schema: config.DB_SCHEMA_NAME }, 'sent_survey', { transaction })
await queryInterface.removeColumn({ tableName: 'work_periods', schema: config.DB_SCHEMA_NAME }, 'sent_survey_error', { transaction } )
await transaction.commit()
} catch (err) {
await transaction.rollback()
throw err
}
},
}
10 changes: 10 additions & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ esIndexPropertyMapping[config.get('esConfig.ES_INDEX_RESOURCE_BOOKING')] = {
endDate: { type: 'date', format: 'yyyy-MM-dd' },
memberRate: { type: 'float' },
customerRate: { type: 'float' },
sendWeeklySurvey: { type: 'boolean' },
rateType: { type: 'keyword' },
billingAccountId: { type: 'integer', null_value: 0 },
workPeriods: {
Expand All @@ -189,6 +190,14 @@ esIndexPropertyMapping[config.get('esConfig.ES_INDEX_RESOURCE_BOOKING')] = {
},
projectId: { type: 'integer' },
userId: { type: 'keyword' },
sentSurvey: { type: 'boolean' },
sentSurveyError: {
type: 'nested',
properties: {
errorCode: { type: 'integer' },
errorMessage: { type: 'keyword' }
}
},
startDate: { type: 'date', format: 'yyyy-MM-dd' },
endDate: { type: 'date', format: 'yyyy-MM-dd' },
daysWorked: { type: 'integer' },
Expand Down Expand Up @@ -2012,6 +2021,7 @@ async function getMembersSuggest (fragment) {
}

module.exports = {
encodeQueryString,
getParamFromCliArgs,
promptUser,
sleep,
Expand Down
Loading