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

enable timeline notifications #29

Merged
merged 1 commit into from
Dec 9, 2020
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
2 changes: 2 additions & 0 deletions src/services/ProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const constants = require('../constants')
const groupService = require('./groupsService')
const termsService = require('./termsService')
const copilotPaymentService = require('./copilotPaymentService')
const timelineService = require('./timelineService')

/**
* Get group information by V5 UUID
Expand Down Expand Up @@ -376,6 +377,7 @@ async function processCreate (message) {
for (const resource of (challengeResourcesResponse.body || [])) {
await helper.postBusEvent(config.RESOURCE_CREATE_TOPIC, _.pick(resource, ['id', 'challengeId', 'memberId', 'memberHandle', 'roleId', 'created', 'createdBy', 'updated', 'updatedBy', 'legacyId']))
}
await timelineService.enableTimelineNotifications(newChallenge.body.result.content.id, _.get(message, 'payload.createdBy'))
logger.debug('End of processCreate')
} catch (e) {
logger.error('processCreate Catch', e)
Expand Down
48 changes: 48 additions & 0 deletions src/services/timelineService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Timeline Service
* Interacts with InformixDB
*/
const logger = require('../common/logger')
const helper = require('../common/helper')

const QUERY_ENABLE_TIMELINE_NOTIFICATIONS = 'INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (?, "11", "On", ?, CURRENT, ?, CURRENT)'

/**
* Prepare Informix statement
* @param {Object} connection the Informix connection
* @param {String} sql the sql
* @return {Object} Informix statement
*/
async function prepare (connection, sql) {
// logger.debug(`Preparing SQL ${sql}`)
const stmt = await connection.prepareAsync(sql)
return Promise.promisifyAll(stmt)
}

/**
* Enable timeline notifications
* @param {Number} challengeLegacyId the legacy challenge ID
* @param {String} createdBy the created by
*/
async function enableTimelineNotifications (challengeLegacyId, createdBy) {
const connection = await helper.getInformixConnection()
let result = null
try {
// await connection.beginTransactionAsync()
const query = await prepare(connection, QUERY_ENABLE_TIMELINE_NOTIFICATIONS)
result = await query.executeAsync([challengeLegacyId, createdBy, createdBy])
// await connection.commitTransactionAsync()
} catch (e) {
logger.error(`Error in 'enableTimelineNotifications' ${e}, rolling back transaction`)
await connection.rollbackTransactionAsync()
throw e
} finally {
logger.info(`Notifications have been enabled for challenge ${challengeLegacyId}`)
await connection.closeAsync()
}
return result
}

module.exports = {
enableTimelineNotifications
}