@@ -14,49 +14,48 @@ const {
1414 BUS_API_EVENT ,
1515 SCHEDULED_EVENT_PERIOD ,
1616 SETTINGS_EMAIL_SERVICE_ID ,
17- ACTIVE_USER_STATUSES
17+ ACTIVE_USER_STATUSES ,
1818} = require ( '../constants' ) ;
1919const { EVENTS , EVENT_BUNDLES } = require ( '../events-config' ) ;
2020const helpers = require ( '../helpers' ) ;
2121const service = require ( '../service' ) ;
2222
2323
24- function replacePlaceholders ( term , data ) {
24+ function replacePlaceholders ( term , data ) {
2525 let placeholders = term . match ( / < [ a - z A - Z ] + > / g) ;
2626 let ret = term ;
27- if ( placeholders && placeholders . length ) {
28- _ ( placeholders ) . each ( p => {
29- let values = _ . map ( data , p . slice ( 1 , - 1 ) ) ;
27+ if ( placeholders && placeholders . length ) {
28+ _ ( placeholders ) . each ( p => {
29+ let values = _ . map ( data , p . slice ( 1 , - 1 ) ) ;
3030 const total = values . length ;
31- let replacement = values . length < 3 ?
32- values . join ( ', ' ) :
33- values . slice ( 0 , 2 ) . join ( ', ' ) + ' and ' + ( total - 3 ) + 'others' ;
31+ let replacement = values . length < 3 ?
32+ values . join ( ', ' ) :
33+ values . slice ( 0 , 2 ) . join ( ', ' ) + ' and ' + ( total - 3 ) + 'others' ;
3434 ret = ret . replace ( p , values . join ( ', ' ) ) ;
35- } )
35+ } ) ;
3636 }
3737 return ret ;
3838}
3939
40- function getSections ( projectUserEvents ) {
40+ function getSections ( projectUserEvents ) {
4141 let sections = [ ] ;
4242 _ . chain ( projectUserEvents )
4343 . groupBy ( value => getEventGroupKey ( value ) )
44- . forIn ( ( value , key ) => {
45- if ( ! EVENT_BUNDLES [ key ] . groupBy ) {
44+ . forIn ( ( value , key ) => {
45+ if ( ! EVENT_BUNDLES [ key ] . groupBy ) {
4646 sections . push ( {
47- title :replacePlaceholders ( EVENT_BUNDLES [ key ] . title , _ ( value ) . map ( g => g . data . data ) . value ( ) ) ,
48- [ key ] :true ,
49- notifications : _ ( value ) . map ( v => v . data . data ) . value ( )
47+ title : replacePlaceholders ( EVENT_BUNDLES [ key ] . title , _ ( value ) . map ( g => g . data . data ) . value ( ) ) ,
48+ [ key ] : true ,
49+ notifications : _ ( value ) . map ( v => v . data . data ) . value ( ) ,
5050 } ) ;
5151 } else {
52- _ . chain ( value ) . groupBy ( n => n . data . data [ EVENT_BUNDLES [ key ] . groupBy ] ) . forIn ( ( groupValue , groupKey ) => {
53-
52+ _ . chain ( value ) . groupBy ( n => n . data . data [ EVENT_BUNDLES [ key ] . groupBy ] ) . forIn ( ( groupValue , groupKey ) => {
5453 let title = EVENT_BUNDLES [ key ] . title ;
55- title = replacePlaceholders ( title , _ ( groupValue ) . map ( g => g . data . data ) . value ( ) ) ;
54+ title = replacePlaceholders ( title , _ ( groupValue ) . map ( g => g . data . data ) . value ( ) ) ;
5655 sections . push ( {
5756 title,
58- [ key ] :true ,
59- notifications : _ ( groupValue ) . map ( g => g . data . data ) . value ( )
57+ [ key ] : true ,
58+ notifications : _ ( groupValue ) . map ( g => g . data . data ) . value ( ) ,
6059 } ) ;
6160 } ) . value ( ) ;
6261 }
@@ -92,7 +91,7 @@ function handleScheduledEvents(events, setEventsStatus) {
9291 . mapValues ( projectUserEvents => ( {
9392 id : _ . get ( projectUserEvents , '[0].data.data.projectId' ) ,
9493 name : _ . get ( projectUserEvents , '[0].data.data.projectName' ) ,
95- sections : getSections ( projectUserEvents )
94+ sections : getSections ( projectUserEvents ) ,
9695 } ) )
9796 . values ( )
9897 . value ( ) ,
@@ -104,7 +103,7 @@ function handleScheduledEvents(events, setEventsStatus) {
104103
105104 // update common values for bundled email
106105 eventMessage . replyTo = config . DEFAULT_REPLY_EMAIL ;
107- eventMessage . version = "v3" ;
106+ eventMessage . version = 'v3' ;
108107 eventMessage . cc = [ ] ;
109108 eventMessage . from = {
110109 name : config . REPLY_EMAIL_FROM ,
@@ -145,8 +144,8 @@ function getEventGroupKey(value) {
145144 . keys ( )
146145 . find ( key => _ . includes ( _ . get ( EVENT_BUNDLES , `${ key } .types` ) , _ . get ( value , 'data.data.type' ) ) )
147146 . value ( ) ;
148- if ( ! key ) return 'DEFAULT' ;
149- return key ;
147+ if ( ! key ) return 'DEFAULT' ;
148+ return key ;
150149}
151150
152151/**
@@ -157,7 +156,7 @@ function getEventGroupKey(value) {
157156 */
158157function wrapIndividualNotification ( data ) {
159158 const key = getEventGroupKey ( data ) ;
160- const subject = replacePlaceholders ( EVENT_BUNDLES [ key ] . subject , [ data . data . data ] ) ;
159+ const subject = replacePlaceholders ( EVENT_BUNDLES [ key ] . subject , [ data . data . data ] ) ;
161160
162161 return {
163162 subject,
@@ -212,7 +211,7 @@ function handler(topicName, messageJSON, notification) {
212211 // don't send email notification for inactive users, ideally we should not have generated
213212 // notifications for inactive users, however, for now handling it here as safe gaurd
214213 if ( userStatus && ACTIVE_USER_STATUSES . indexOf ( userStatus ) === - 1 ) {
215- logger . error ( ` Notification generated for inactive user, ignoring` ) ;
214+ logger . error ( ' Notification generated for inactive user, ignoring' ) ;
216215 return ;
217216 }
218217 if ( config . ENABLE_DEV_MODE === 'true' ) {
@@ -236,16 +235,16 @@ function handler(topicName, messageJSON, notification) {
236235 emailToAffectedUser : notification . contents . userEmail === userEmail ,
237236 } ,
238237 recipients,
239- version :"v3" ,
238+ version : 'v3' ,
240239 from : {
241240 name : notification . contents . userHandle ,
242241 email : config . DEFAULT_REPLY_EMAIL ,
243242 } ,
244243 categories,
245244 } ;
246- eventMessage . data [ eventMessage . data . type ] = true ;
247- _ . assign ( eventMessage . data , notification . contents ) ;
248-
245+ eventMessage . data [ eventMessage . data . type ] = true ;
246+ _ . assign ( eventMessage . data , notification . contents ) ;
247+
249248
250249 // default values that get overridden when the notification is about topics/posts updates
251250 let reference = 'project' ;
@@ -256,7 +255,7 @@ function handler(topicName, messageJSON, notification) {
256255 messagingEvent = true ;
257256 eventMessage . data . topicId = parseInt ( messageJSON . topicId , 10 ) ;
258257 eventMessage . data . postId = messageJSON . postId ? parseInt ( messageJSON . postId , 10 ) : null ;
259- if ( messageJSON . postContent ) {
258+ if ( messageJSON . postContent ) {
260259 eventMessage . data . post = helpers . markdownToHTML ( messageJSON . postContent ) ;
261260 }
262261
@@ -304,9 +303,9 @@ function handler(topicName, messageJSON, notification) {
304303 // if we find the event category for the notification, use the bundle settings from the first event
305304 if ( eventBundle && eventBundle . types && eventBundle . types . length ) {
306305 const firstEvtInBundle = eventBundle . types [ 0 ] ;
307- const firstEvtBundleSettingPath = `notifications['${ firstEvtInBundle } '].${ SETTINGS_EMAIL_SERVICE_ID } .bundlePeriod`
306+ const firstEvtBundleSettingPath = `notifications['${ firstEvtInBundle } '].${ SETTINGS_EMAIL_SERVICE_ID } .bundlePeriod` ;
308307 let firstEvtBundlePeriod = _ . get ( settings , firstEvtBundleSettingPath ) ;
309- bundlePeriod = firstEvtBundlePeriod
308+ bundlePeriod = firstEvtBundlePeriod ;
310309 logger . debug ( 'Assuming bundle period of first event in the event category=>' , bundlePeriod ) ;
311310 }
312311 }
@@ -315,7 +314,7 @@ function handler(topicName, messageJSON, notification) {
315314 }
316315 logger . debug ( 'bundlePeriod=>' , bundlePeriod ) ;
317316
318- if ( bundlePeriod && " immediately" !== bundlePeriod && ! requiresImmediateAttention ) {
317+ if ( bundlePeriod && ' immediately' !== bundlePeriod && ! requiresImmediateAttention ) {
319318 if ( ! SCHEDULED_EVENT_PERIOD [ bundlePeriod ] ) {
320319 throw new Error ( `User's '${ notification . userId } ' setting for service`
321320 + ` '${ SETTINGS_EMAIL_SERVICE_ID } ' option 'bundlePeriod' has unsupported value '${ bundlePeriod } '.` ) ;
@@ -332,7 +331,7 @@ function handler(topicName, messageJSON, notification) {
332331 } ) ;
333332 } else {
334333 // send single field "notificationsHTML" with the rendered template
335- eventMessage . data = wrapIndividualNotification ( { data :eventMessage } ) ;
334+ eventMessage . data = wrapIndividualNotification ( { data : eventMessage } ) ;
336335 console . log ( eventMessage . data . contents ) ;
337336
338337 // send event to bus api
0 commit comments