@@ -188,7 +188,9 @@ function* notifyUserViaEmail(user, message) {
188188 */
189189function * getChallenge ( challengeId ) {
190190 // this is public API, M2M token is not needed
191- const res = yield request . get ( `${ config . TC_API_V4_BASE_URL } /challenges/${ challengeId } ` ) ;
191+ const url = `${ config . TC_API_V4_BASE_URL } /challenges/${ challengeId } `
192+ logger . info ( `calling public challenge api ${ url } ` )
193+ const res = yield request . get ( url ) ;
192194 if ( ! _ . get ( res , 'body.result.success' ) ) {
193195 throw new Error ( `Failed to get challenge by id ${ challengeId } ` ) ;
194196 }
@@ -198,10 +200,10 @@ function* getChallenge(challengeId) {
198200/**
199201 * Notify users of message.
200202 * @param {Array } users the users
201- * @param {Object } message the Kafka message
203+ * @param {Object } notification notifcation node
202204 * @returns {Array } the notifications
203205 */
204- function * notifyUsersOfMessage ( users , message ) {
206+ function * notifyUsersOfMessage ( users , notification ) {
205207 if ( ! users || users . length === 0 ) {
206208 logger . info ( 'No users to notify message.' ) ;
207209 return [ ] ;
@@ -212,7 +214,7 @@ function* notifyUsersOfMessage(users, message) {
212214 for ( let i = 0 ; i < users . length ; i += 1 ) {
213215 const user = users [ i ] ;
214216 // construct notification, rest fields are set in consumer.js
215- notifications . push ( { userId : user . userId } ) ;
217+ notifications . push ( { userId : user . userId , notification : notification } ) ;
216218
217219 /* TODO Sachin disabled this code
218220 if (config.ENABLE_EMAILS) {
@@ -287,6 +289,34 @@ function filterChallengeUsers(usersInfo, filterOnRoles = [], filterOnUsers = [])
287289 return users
288290}
289291
292+ /**
293+ * modify notification template
294+ * @param {Object } ruleSet rule
295+ * @param {Object } data values to be filled
296+ *
297+ * @returns {Object } notification node
298+ */
299+ function * modifyNotificationNode ( ruleSet , data ) {
300+ const notification = _ . get ( ruleSet , "notification" )
301+ const id = data . id || data . challengeId || 0
302+ const name = _ . get ( data , "name" )
303+
304+ notification . id = id
305+
306+ if ( name ) {
307+ notification . name = name
308+ } else {
309+ try {
310+ const challenge = yield getChallenge ( id )
311+ notification . name = _ . get ( challenge , "challengeTitle" )
312+ } catch ( error ) {
313+ notification . name = ''
314+ logger . error ( `Error in fetching challenge detail : ${ error } ` )
315+ }
316+ }
317+ return notification
318+ }
319+
290320module . exports = {
291321 getM2MToken,
292322 getUsersBySkills,
@@ -297,4 +327,5 @@ module.exports = {
297327 notifyUsersOfMessage,
298328 getUsersInfoFromChallenge,
299329 filterChallengeUsers,
330+ modifyNotificationNode,
300331} ;
0 commit comments