@@ -315,22 +315,23 @@ getTeamJob.schema = Joi.object().keys({
315
315
*/
316
316
async function sendEmail ( currentUser , data ) {
317
317
const template = emailTemplates [ data . template ]
318
-
319
318
const dataCC = data . cc || [ ]
320
319
const templateCC = template . cc || [ ]
321
320
const dataRecipients = data . recipients || [ ]
322
321
const templateRecipients = template . recipients || [ ]
323
-
324
- await helper . postEvent ( config . EMAIL_TOPIC , {
325
- data : data . data , // substitutions
326
- sendgrid_template_id : template . sendgridTemplateId ,
327
- version : 'v3' ,
322
+ let emailProps = {
328
323
// override template if coming data already have the 'from' address
329
324
from : data . from || template . from ,
330
325
// create a set of uniq. recipients & CCs, from both coming data & template
331
326
recipients : _ . uniq ( [ ...dataRecipients , ...templateRecipients ] ) ,
332
327
cc : _ . uniq ( [ ...dataCC , ...templateCC ] )
333
- } )
328
+ } ;
329
+ let emailData = {
330
+ data : { ...data . data , ...emailProps } ,
331
+ sendgrid_template_id : template . sendgridTemplateId ,
332
+ version : 'v3'
333
+ }
334
+ await helper . postEvent ( config . EMAIL_TOPIC , { ...emailData , ...emailProps } )
334
335
}
335
336
336
337
sendEmail . schema = Joi . object ( ) . keys ( {
0 commit comments