-
Notifications
You must be signed in to change notification settings - Fork 55
PM 2321 - submit copilot request fails #858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
6bcc6f6
d5a8051
63e8aa6
dbdc3ce
451bec8
c7bb446
dff7fd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,11 @@ import moment from 'moment'; | |
import { Op } from 'sequelize'; | ||
|
||
import models from '../../models'; | ||
import { CONNECT_NOTIFICATION_EVENT, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, TEMPLATE_IDS, USER_ROLE } from '../../constants'; | ||
import { | ||
CONNECT_NOTIFICATION_EVENT, | ||
COPILOT_OPPORTUNITY_STATUS, | ||
COPILOT_REQUEST_STATUS, | ||
TEMPLATE_IDS, USER_ROLE } from '../../constants'; | ||
import util from '../../util'; | ||
import { createEvent } from '../../services/busApi'; | ||
import { getCopilotTypeLabel } from '../../utils/copilot'; | ||
|
@@ -47,7 +51,7 @@ module.exports = (req, data, existingTransaction) => { | |
type: data.type, | ||
status: { | ||
[Op.in]: [COPILOT_OPPORTUNITY_STATUS.ACTIVE], | ||
} | ||
}, | ||
}, | ||
}) | ||
.then((existingCopilotOpportunityOfSameType) => { | ||
|
@@ -66,7 +70,7 @@ module.exports = (req, data, existingTransaction) => { | |
const { subjects = [] } = await util.getRoleInfo(roles[0], req.log, req.id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling for the |
||
const emailEventType = CONNECT_NOTIFICATION_EVENT.EXTERNAL_ACTION_EMAIL; | ||
const copilotPortalUrl = config.get('copilotPortalUrl'); | ||
req.log.info("Sending emails to all copilots about new opportunity"); | ||
req.log.info('Sending emails to all copilots about new opportunity'); | ||
|
||
const sendNotification = (userName, recipient) => createEvent(emailEventType, { | ||
data: { | ||
|
@@ -75,20 +79,28 @@ module.exports = (req, data, existingTransaction) => { | |
work_manager_url: config.get('workManagerUrl'), | ||
opportunity_type: getCopilotTypeLabel(type), | ||
opportunity_title: opportunityTitle, | ||
start_date: moment(startDate).format("DD-MM-YYYY"), | ||
start_date: moment(startDate).format('DD-MM-YYYY'), | ||
}, | ||
sendgrid_template_id: TEMPLATE_IDS.CREATE_REQUEST, | ||
recipients: [recipient], | ||
version: 'v3', | ||
}, req.log); | ||
|
||
subjects.forEach(subject => sendNotification(subject.handle, subject.email)); | ||
const notificationPromises = subjects.map(subject => | ||
sendNotification(subject.handle, subject.email), | ||
); | ||
|
||
notificationPromises.push( | ||
sendNotification('Copilots', config.copilotsSlackEmail), | ||
); | ||
|
||
await Promise.all(notificationPromises); | ||
|
||
// send email to notify via slack | ||
sendNotification('Copilots', config.copilotsSlackEmail); | ||
|
||
|
||
req.log.info("Finished sending emails to copilots"); | ||
req.log.info('Finished sending emails to copilots'); | ||
|
||
return opportunity; | ||
}) | ||
.catch((err) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider formatting the import statement so that each constant is on a separate line for better readability, like the other constants in this block.