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

Commit 6edf5ca

Browse files
author
James Cori
committed
Merge branch 'develop'
2 parents fb377f0 + 179d797 commit 6edf5ca

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

src/app.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, a
6464

6565
try {
6666
if (topic === config.CREATE_CHALLENGE_TOPIC) {
67-
// create shut off. Only works with challenges of status draft, which happens on update
68-
// await ProcessorService.processCreate(messageJSON)
67+
await ProcessorService.processCreate(messageJSON)
6968
} else {
7069
await ProcessorService.processUpdate(messageJSON)
7170
}

src/services/ProcessorService.js

+2
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

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Timeline Service
3+
* Interacts with InformixDB
4+
*/
5+
const util = require('util')
6+
const logger = require('../common/logger')
7+
const helper = require('../common/helper')
8+
9+
const QUERY_GET_TIMELINE_NOTIFICATION_SETTINGS = 'SELECT value FROM project_info WHERE project_id = %d and project_info_type_id = %d'
10+
const QUERY_CREATE_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)'
11+
const QUERY_UPDATE_TIMELINE_NOTIFICATIONS = 'UPDATE project_info SET value = "On", modify_user = ?, modify_date = CURRENT WHERE project_info_type_id = "11" AND project_id = ?'
12+
13+
/**
14+
* Prepare Informix statement
15+
* @param {Object} connection the Informix connection
16+
* @param {String} sql the sql
17+
* @return {Object} Informix statement
18+
*/
19+
async function prepare (connection, sql) {
20+
// logger.debug(`Preparing SQL ${sql}`)
21+
const stmt = await connection.prepareAsync(sql)
22+
return Promise.promisifyAll(stmt)
23+
}
24+
25+
/**
26+
* Get teh timeline notification settings entry
27+
* @param {Number} challengeLegacyId the legacy challenge ID
28+
*/
29+
async function getTimelineNotifications (challengeLegacyId) {
30+
// logger.debug(`Getting Groups for Challenge ${challengeLegacyId}`)
31+
const connection = await helper.getInformixConnection()
32+
let result = null
33+
try {
34+
result = await connection.queryAsync(util.format(QUERY_GET_TIMELINE_NOTIFICATION_SETTINGS, challengeLegacyId, 11))
35+
} catch (e) {
36+
logger.error(`Error in 'getTermsForChallenge' ${e}`)
37+
throw e
38+
} finally {
39+
await connection.closeAsync()
40+
}
41+
return result
42+
}
43+
44+
/**
45+
* Enable timeline notifications
46+
* @param {Number} challengeLegacyId the legacy challenge ID
47+
* @param {String} createdBy the created by
48+
*/
49+
async function enableTimelineNotifications (challengeLegacyId, createdBy) {
50+
const connection = await helper.getInformixConnection()
51+
let result = null
52+
try {
53+
// await connection.beginTransactionAsync()
54+
const [existing] = await getTimelineNotifications(challengeLegacyId)
55+
if (existing) {
56+
const query = await prepare(connection, QUERY_UPDATE_TIMELINE_NOTIFICATIONS)
57+
result = await query.executeAsync([createdBy, challengeLegacyId])
58+
} else {
59+
const query = await prepare(connection, QUERY_CREATE_TIMELINE_NOTIFICATIONS)
60+
result = await query.executeAsync([challengeLegacyId, createdBy, createdBy])
61+
}
62+
// await connection.commitTransactionAsync()
63+
logger.info(`Notifications have been enabled for challenge ${challengeLegacyId}`)
64+
} catch (e) {
65+
logger.error(`Error in 'enableTimelineNotifications' ${e}, rolling back transaction`)
66+
await connection.rollbackTransactionAsync()
67+
throw e
68+
} finally {
69+
await connection.closeAsync()
70+
}
71+
return result
72+
}
73+
74+
module.exports = {
75+
getTimelineNotifications,
76+
enableTimelineNotifications
77+
}

0 commit comments

Comments
 (0)