@@ -18,41 +18,6 @@ const assignCopilotOpportunityValidations = {
1818 } ) ,
1919} ;
2020
21- const sendEmailToAllApplicants = async ( req , opportunity , copilotRequest , applicationId ) => {
22- const allApplications = await models . Sequelize . CopilotApplication . findAll ( {
23- where : {
24- opportunityId : opportunity . id ,
25- id : {
26- [ Op . notIn ] : [ applicationId ] ,
27- }
28- }
29- } ) ;
30-
31- const userIds = allApplications . map ( item => item . userId ) ;
32-
33- const users = await util . getMemberDetailsByUserIds ( userIds , req . log , req . id ) ;
34-
35- users . forEach ( async ( user ) => {
36- req . log . debug ( `Sending email notification to copilots who are not accepted` ) ;
37- const emailEventType = CONNECT_NOTIFICATION_EVENT . EXTERNAL_ACTION_EMAIL ;
38- const copilotPortalUrl = config . get ( 'copilotPortalUrl' ) ;
39- const requestData = copilotRequest . data ;
40- createEvent ( emailEventType , {
41- data : {
42- opportunity_details_url : `${ copilotPortalUrl } /opportunity` ,
43- opportunity_title : requestData . opportunityTitle ,
44- user_name : user ? user . handle : "" ,
45- } ,
46- sendgrid_template_id : TEMPLATE_IDS . COPILOT_OPPORTUNITY_COMPLETED ,
47- recipients : [ user . email ] ,
48- version : 'v3' ,
49- } , req . log ) ;
50-
51- req . log . debug ( `Email sent to copilots who are not accepted` ) ;
52- } ) ;
53-
54- } ;
55-
5621module . exports = [
5722 validate ( assignCopilotOpportunityValidations ) ,
5823 async ( req , res , next ) => {
@@ -67,6 +32,41 @@ module.exports = [
6732 return next ( err ) ;
6833 }
6934
35+ const sendEmailToAllApplicants = async ( opportunity , copilotRequest , applicationId ) => {
36+ const allApplications = await models . Sequelize . CopilotApplication . findAll ( {
37+ where : {
38+ opportunityId : opportunity . id ,
39+ id : {
40+ [ Op . notIn ] : [ applicationId ] ,
41+ }
42+ }
43+ } ) ;
44+
45+ const userIds = allApplications . map ( item => item . userId ) ;
46+
47+ const users = await util . getMemberDetailsByUserIds ( userIds , req . log , req . id ) ;
48+
49+ users . forEach ( async ( user ) => {
50+ req . log . debug ( `Sending email notification to copilots who are not accepted` ) ;
51+ const emailEventType = CONNECT_NOTIFICATION_EVENT . EXTERNAL_ACTION_EMAIL ;
52+ const copilotPortalUrl = config . get ( 'copilotPortalUrl' ) ;
53+ const requestData = copilotRequest . data ;
54+ createEvent ( emailEventType , {
55+ data : {
56+ opportunity_details_url : `${ copilotPortalUrl } /opportunity` ,
57+ opportunity_title : requestData . opportunityTitle ,
58+ user_name : user ? user . handle : "" ,
59+ } ,
60+ sendgrid_template_id : TEMPLATE_IDS . COPILOT_OPPORTUNITY_COMPLETED ,
61+ recipients : [ user . email ] ,
62+ version : 'v3' ,
63+ } , req . log ) ;
64+
65+ req . log . debug ( `Email sent to copilots who are not accepted` ) ;
66+ } ) ;
67+
68+ } ;
69+
7070 return models . sequelize . transaction ( async ( t ) => {
7171 const opportunity = await models . CopilotOpportunity . findOne ( {
7272 where : { id : copilotOpportunityId } ,
@@ -171,7 +171,7 @@ module.exports = [
171171 req . log . debug ( `Email sent` ) ;
172172
173173 // Send email to all applicants about opportunity completion
174- await sendEmailToAllApplicants ( req , opportunity , copilotRequest , application . id ) ;
174+ await sendEmailToAllApplicants ( opportunity , copilotRequest , application . id ) ;
175175 } ;
176176
177177 const existingMember = activeMembers . find ( item => item . userId === userId ) ;
0 commit comments