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