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

Commit 0b50a0b

Browse files
authored
Merge pull request #29 from topcoder-platform/fix-timline-notif
enable timeline notifications
2 parents eef5e98 + f7763d7 commit 0b50a0b

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/services/ProcessorService.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const constants = require('../constants')
1313
const groupService = require('./groupsService')
1414
const termsService = require('./termsService')
1515
const copilotPaymentService = require('./copilotPaymentService')
16+
const timelineService = require('./timelineService')
1617

1718
/**
1819
* Get group information by V5 UUID
@@ -376,6 +377,7 @@ async function processCreate (message) {
376377
for (const resource of (challengeResourcesResponse.body || [])) {
377378
await helper.postBusEvent(config.RESOURCE_CREATE_TOPIC, _.pick(resource, ['id', 'challengeId', 'memberId', 'memberHandle', 'roleId', 'created', 'createdBy', 'updated', 'updatedBy', 'legacyId']))
378379
}
380+
await timelineService.enableTimelineNotifications(newChallenge.body.result.content.id, _.get(message, 'payload.createdBy'))
379381
logger.debug('End of processCreate')
380382
} catch (e) {
381383
logger.error('processCreate Catch', e)

src/services/timelineService.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Timeline Service
3+
* Interacts with InformixDB
4+
*/
5+
const logger = require('../common/logger')
6+
const helper = require('../common/helper')
7+
8+
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)'
9+
10+
/**
11+
* Prepare Informix statement
12+
* @param {Object} connection the Informix connection
13+
* @param {String} sql the sql
14+
* @return {Object} Informix statement
15+
*/
16+
async function prepare (connection, sql) {
17+
// logger.debug(`Preparing SQL ${sql}`)
18+
const stmt = await connection.prepareAsync(sql)
19+
return Promise.promisifyAll(stmt)
20+
}
21+
22+
/**
23+
* Enable timeline notifications
24+
* @param {Number} challengeLegacyId the legacy challenge ID
25+
* @param {String} createdBy the created by
26+
*/
27+
async function enableTimelineNotifications (challengeLegacyId, createdBy) {
28+
const connection = await helper.getInformixConnection()
29+
let result = null
30+
try {
31+
// await connection.beginTransactionAsync()
32+
const query = await prepare(connection, QUERY_ENABLE_TIMELINE_NOTIFICATIONS)
33+
result = await query.executeAsync([challengeLegacyId, createdBy, createdBy])
34+
// await connection.commitTransactionAsync()
35+
} catch (e) {
36+
logger.error(`Error in 'enableTimelineNotifications' ${e}, rolling back transaction`)
37+
await connection.rollbackTransactionAsync()
38+
throw e
39+
} finally {
40+
logger.info(`Notifications have been enabled for challenge ${challengeLegacyId}`)
41+
await connection.closeAsync()
42+
}
43+
return result
44+
}
45+
46+
module.exports = {
47+
enableTimelineNotifications
48+
}

0 commit comments

Comments
 (0)