@@ -132,30 +132,44 @@ router.route('/')
132132
133133 const report = await db . models . report . findOne ( { where : { id : req . report . id } } ) ;
134134 const reportProject = await db . models . reportProject . findOne ( { where : { report_id : req . report . id } } ) ;
135- const notif = await db . models . notification . findOrCreate ( {
135+ const project = await db . models . project . findOne ( { where : { id : reportProject . project_id } } ) ;
136+ const template = await db . models . template . findOne ( { where : { id : report . templateId } } ) ;
137+ const userGroup = await db . models . userGroup . findOne ( { where : { name : 'admin' } } ) ;
138+
139+ const notifyReq = await db . models . notification . findOrCreate ( {
136140 where : {
137141 userId : req . user . id ,
138142 eventType : NOTIFICATION_EVENT . USER_BOUND ,
139143 templateId : report . templateId ,
140144 projectId : reportProject . project_id ,
145+ userGroupId : userGroup . id ,
146+ } ,
147+ } ) ;
148+
149+ const notifyBinding = await db . models . notification . findOrCreate ( {
150+ where : {
151+ userId : bindUser . id ,
152+ eventType : NOTIFICATION_EVENT . USER_BOUND ,
153+ templateId : report . templateId ,
154+ projectId : reportProject . project_id ,
155+ userGroupId : userGroup . id ,
141156 } ,
142157 } ) ;
143158
144159 // Try sending email
145160 try {
146161 await email . notifyUsers (
147162 `${ bindUser . firstName } ${ bindUser . lastName } has been bound to a report` ,
148- `User ${ bindUser . firstName } ${ bindUser . lastName } has been bound to report ${ req . report . ident } as ${ role } ` ,
163+ `User ${ bindUser . firstName } ${ bindUser . lastName } has been bound to report ${ req . report . ident } as ${ role } .
164+ Report Type: ${ template . name }
165+ Patient Id: ${ report . patientId }
166+ Project: ${ project . name } ` ,
149167 {
150- eventType : NOTIFICATION_EVENT . USER_BOUND ,
151- templateId : req . report . templateId ,
168+ id : [ notifyReq [ 0 ] . id , notifyBinding [ 0 ] . id ] ,
152169 } ,
153170 ) ;
154-
155- await notif [ 0 ] . update ( { status : 'Success' } , { userId : req . user . id } ) ;
156171 logger . info ( 'Email sent successfully' ) ;
157172 } catch ( error ) {
158- await notif [ 0 ] . update ( { status : 'Unsuccess' } , { userId : req . user . id } ) ;
159173 logger . error ( `Email not sent successfully: ${ error } ` ) ;
160174 }
161175
0 commit comments