@@ -3,10 +3,36 @@ import { Op } from 'sequelize';
33
44import models from '../../models' ;
55import util from '../../util' ;
6- import { COPILOT_APPLICATION_STATUS , COPILOT_OPPORTUNITY_STATUS , COPILOT_REQUEST_STATUS , EVENT , INVITE_STATUS , RESOURCES } from '../../constants' ;
6+ import { CONNECT_NOTIFICATION_EVENT , COPILOT_APPLICATION_STATUS , COPILOT_OPPORTUNITY_STATUS , COPILOT_REQUEST_STATUS , EVENT , INVITE_STATUS , RESOURCES , TEMPLATE_IDS } from '../../constants' ;
7+ import { createEvent } from '../../services/busApi' ;
78import { PERMISSION } from '../../permissions/constants' ;
89
910
11+ const sendEmailToAllApplicants = async ( req , copilotRequest , applications ) => {
12+ const userIds = applications . map ( item => item . userId ) ;
13+ const users = await util . getMemberDetailsByUserIds ( userIds , req . log , req . id ) ;
14+
15+ users . forEach ( async ( user ) => {
16+ req . log . debug ( `Sending email notification to copilots who applied` ) ;
17+ const emailEventType = CONNECT_NOTIFICATION_EVENT . EXTERNAL_ACTION_EMAIL ;
18+ const copilotPortalUrl = config . get ( 'copilotPortalUrl' ) ;
19+ const requestData = copilotRequest . data ;
20+ createEvent ( emailEventType , {
21+ data : {
22+ opportunity_details_url : `${ copilotPortalUrl } /opportunity` ,
23+ opportunity_title : requestData . opportunityTitle ,
24+ user_name : user ? user . handle : "" ,
25+ } ,
26+ sendgrid_template_id : TEMPLATE_IDS . COPILOT_OPPORTUNITY_CANCELED ,
27+ recipients : [ user . email ] ,
28+ version : 'v3' ,
29+ } , req . log ) ;
30+
31+ req . log . debug ( `Email sent to copilots who applied` ) ;
32+ } ) ;
33+
34+ } ;
35+
1036module . exports = [
1137 ( req , res , next ) => {
1238 if ( ! util . hasPermissionByReq ( PERMISSION . CANCEL_COPILOT_OPPORTUNITY , req ) ) {
@@ -93,6 +119,8 @@ module.exports = [
93119 invite . toJSON ( ) ) ;
94120 }
95121
122+ await sendEmailToAllApplicants ( req , copilotRequest , applications )
123+
96124 res . status ( 200 ) . send ( { id : opportunity . id } ) ;
97125 } )
98126
0 commit comments