Skip to content

Commit 6bcc6f6

Browse files
committed
await copilot emails
1 parent ccfcc6e commit 6bcc6f6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/routes/copilotRequest/approveRequest.service.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import moment from 'moment';
44
import { Op } from 'sequelize';
55

66
import models from '../../models';
7-
import { CONNECT_NOTIFICATION_EVENT, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, TEMPLATE_IDS, USER_ROLE } from '../../constants';
7+
import {
8+
CONNECT_NOTIFICATION_EVENT,
9+
COPILOT_OPPORTUNITY_STATUS,
10+
COPILOT_REQUEST_STATUS,
11+
TEMPLATE_IDS, USER_ROLE } from '../../constants';
812
import util from '../../util';
913
import { createEvent } from '../../services/busApi';
1014
import { getCopilotTypeLabel } from '../../utils/copilot';
@@ -47,7 +51,7 @@ module.exports = (req, data, existingTransaction) => {
4751
type: data.type,
4852
status: {
4953
[Op.in]: [COPILOT_OPPORTUNITY_STATUS.ACTIVE],
50-
}
54+
},
5155
},
5256
})
5357
.then((existingCopilotOpportunityOfSameType) => {
@@ -66,7 +70,7 @@ module.exports = (req, data, existingTransaction) => {
6670
const { subjects = [] } = await util.getRoleInfo(roles[0], req.log, req.id);
6771
const emailEventType = CONNECT_NOTIFICATION_EVENT.EXTERNAL_ACTION_EMAIL;
6872
const copilotPortalUrl = config.get('copilotPortalUrl');
69-
req.log.info("Sending emails to all copilots about new opportunity");
73+
req.log.info('Sending emails to all copilots about new opportunity');
7074

7175
const sendNotification = (userName, recipient) => createEvent(emailEventType, {
7276
data: {
@@ -75,20 +79,28 @@ module.exports = (req, data, existingTransaction) => {
7579
work_manager_url: config.get('workManagerUrl'),
7680
opportunity_type: getCopilotTypeLabel(type),
7781
opportunity_title: opportunityTitle,
78-
start_date: moment(startDate).format("DD-MM-YYYY"),
82+
start_date: moment(startDate).format('DD-MM-YYYY'),
7983
},
8084
sendgrid_template_id: TEMPLATE_IDS.CREATE_REQUEST,
8185
recipients: [recipient],
8286
version: 'v3',
8387
}, req.log);
8488

85-
subjects.forEach(subject => sendNotification(subject.handle, subject.email));
89+
const notificationPromises = subjects.map(subject =>
90+
sendNotification(subject.handle, subject.email),
91+
);
92+
93+
notificationPromises.push(
94+
sendNotification('Copilots', config.copilotsSlackEmail),
95+
);
96+
97+
await Promise.all(notificationPromises);
8698

8799
// send email to notify via slack
88100
sendNotification('Copilots', config.copilotsSlackEmail);
89101

90-
req.log.info("Finished sending emails to copilots");
91-
102+
req.log.info('Finished sending emails to copilots');
103+
92104
return opportunity;
93105
})
94106
.catch((err) => {

0 commit comments

Comments
 (0)