-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,25 @@ | ||
const { EMAIL_RECIPIENTS } = require('../models/constants') | ||
const { EMAIL_RECIPIENTS, ADMIN_GROUP_EMAIL } = require('../models/constants') | ||
const { sendEmail } = require('../service/sendEmail') | ||
const { getUserByUID } = require('../service/users.service') | ||
|
||
const FINANCE_GROUP_EMAIL = '[email protected]' | ||
const DivisionEmails = { | ||
software: '[email protected]', | ||
mechanical: '[email protected]', | ||
business: '[email protected]', | ||
electrical: '[email protected]', | ||
} | ||
|
||
const currencyFormatter = new Intl.NumberFormat('en-CA', { | ||
style: 'currency', | ||
currency: 'CAD', | ||
}) | ||
|
||
const getEmailToSection = async (reporter_id, recipients) => { | ||
const emailToSet = new Set([FINANCE_GROUP_EMAIL]) | ||
const emailToSet = new Set([ADMIN_GROUP_EMAIL]) | ||
|
||
if (recipients.includes(EMAIL_RECIPIENTS.admin)) { | ||
// TODO: use ADMIN_IDENTIFIERS (rename to ADMIN_EMAILS) after migrating to new onboarding data | ||
emailToSet.add(ADMIN_GROUP_EMAIL) | ||
} | ||
|
||
if (recipients.includes(EMAIL_RECIPIENTS.coordinator)) { | ||
// TODO: determine which is the correct coordinator email | ||
// emailToSet.add('[email protected]') | ||
// emailToSet.add('[email protected]') | ||
} | ||
|
||
if (recipients.includes(EMAIL_RECIPIENTS.director)) { | ||
// TODO: get director emails | ||
} | ||
|
||
if (recipients.includes(EMAIL_RECIPIENTS.faculty_advisor)) { | ||
// emailToSet.add('[email protected]') | ||
} | ||
|
||
if (recipients.includes(EMAIL_RECIPIENTS.finance)) { | ||
// emailToSet.add(process.env.WATO_FINANCE_FINANCE_EMAIL) | ||
// TODO: emailToSet.add('[email protected]') | ||
} | ||
|
||
if (recipients.includes(EMAIL_RECIPIENTS.reporter)) { | ||
|
@@ -47,10 +29,6 @@ const getEmailToSection = async (reporter_id, recipients) => { | |
} | ||
} | ||
|
||
if (recipients.includes(EMAIL_RECIPIENTS.team_captain)) { | ||
// TODO: get team captain emails | ||
} | ||
|
||
return [...emailToSet].map((Email) => ({ Email })) | ||
} | ||
|
||
|
@@ -129,18 +107,19 @@ const getTicketLinkHTML = (ticketPath) => ` | |
</p> | ||
` | ||
|
||
const sendEmailPPRCreatedToApprovers = async (ppr) => { | ||
const Subject = `[Seeking Approval] ${ppr.codename}` | ||
// ******************** UPR EMAILS ******************** | ||
|
||
const sendEmailUPRCreatedToApprovers = async (upr) => { | ||
const Subject = `[Seeking Approval] ${upr.codename}` | ||
const HTMLPart = | ||
getMainMessageHTML( | ||
'A new Personal Purchase Request needs your approval!' | ||
'A new UW Finance Purchase Request needs your approval!' | ||
) + | ||
(await getPPRTicketInfoHTML(ppr)) + | ||
getTicketLinkHTML(ppr.path) | ||
const To = await getEmailToSection(ppr.reporter_id, [ | ||
(await getUPRTicketInfoHTML(upr)) + | ||
getTicketLinkHTML(upr.path) | ||
const To = await getEmailToSection(upr.reporter_id, [ | ||
EMAIL_RECIPIENTS.faculty_advisor, | ||
EMAIL_RECIPIENTS.team_captain, | ||
EMAIL_RECIPIENTS.director, | ||
EMAIL_RECIPIENTS.admin, | ||
]) | ||
|
||
await sendEmail({ | ||
|
@@ -150,18 +129,17 @@ const sendEmailPPRCreatedToApprovers = async (ppr) => { | |
}) | ||
} | ||
|
||
const sendEmailUPRCreatedToApprovers = async (upr) => { | ||
const Subject = `[Seeking Approval] ${upr.codename}` | ||
const sendEmailUPRApprovedToCoordinator = async (upr) => { | ||
const Subject = `[Ready to Buy] ${upr.codename}` | ||
const HTMLPart = | ||
getMainMessageHTML( | ||
'A new UW Finance Purchase Request needs your approval!' | ||
`A new UW Finance Purchase Request has been approved! Please purchase the approved item(s).<br> | ||
After purchase, update the purchase order number and requisition number at the ticket link below.` | ||
) + | ||
(await getUPRTicketInfoHTML(upr)) + | ||
getTicketLinkHTML(upr.path) | ||
const To = await getEmailToSection(upr.reporter_id, [ | ||
EMAIL_RECIPIENTS.faculty_advisor, | ||
EMAIL_RECIPIENTS.team_captain, | ||
EMAIL_RECIPIENTS.director, | ||
EMAIL_RECIPIENTS.coordinator, | ||
]) | ||
|
||
await sendEmail({ | ||
|
@@ -209,7 +187,7 @@ const sendEmailUPRPurchasedToCoordinator = async (upr) => { | |
}) | ||
} | ||
|
||
const sendEmailUPRReadyForPickupToCoordinator = async (upr) => { | ||
const sendEmailUPRReadyForPickupToReporter = async (upr) => { | ||
const Subject = `[Ready for pickup] ${upr.codename}` | ||
const HTMLPart = | ||
getMainMessageHTML( | ||
|
@@ -220,25 +198,48 @@ const sendEmailUPRReadyForPickupToCoordinator = async (upr) => { | |
const To = await getEmailToSection(upr.reporter_id, [ | ||
EMAIL_RECIPIENTS.reporter, | ||
]) | ||
const Cc = await getEmailToSection(upr.reporter_id, [ | ||
EMAIL_RECIPIENTS.coordinator, // cc'd for convenience if reporter needs to contact coordinator | ||
]) | ||
|
||
await sendEmail({ | ||
Subject, | ||
HTMLPart, | ||
To, | ||
Cc, | ||
}) | ||
} | ||
|
||
const sendEmailPPRApprovedToReporter = async (ppr) => { | ||
const Subject = `[Ready to Buy] ${ppr.codename}` | ||
const sendEmailUPRPickedUpToAdmin = async (upr) => { | ||
const Subject = `[Picked up] ${upr.codename}` | ||
const HTMLPart = | ||
getMainMessageHTML(`${upr.codename} has been picked up!`) + | ||
(await getUPRTicketInfoHTML(upr)) + | ||
getTicketLinkHTML(upr.path) | ||
const To = await getEmailToSection(upr.reporter_id, [ | ||
EMAIL_RECIPIENTS.admin, | ||
]) | ||
|
||
await sendEmail({ | ||
Subject, | ||
HTMLPart, | ||
To, | ||
}) | ||
} | ||
|
||
// ******************** PPR EMAILS ******************** | ||
|
||
const sendEmailPPRCreatedToApprovers = async (ppr) => { | ||
const Subject = `[Seeking Approval] ${ppr.codename}` | ||
const HTMLPart = | ||
getMainMessageHTML( | ||
`Your Personal Purchase Request has been approved! Please purchase the approved item(s).<br> | ||
Upload your proof of purchase at the ticket link below to request reimbursement.` | ||
'A new Personal Purchase Request needs your approval!' | ||
) + | ||
(await getPPRTicketInfoHTML(ppr)) + | ||
getTicketLinkHTML(ppr.path) | ||
const To = await getEmailToSection(ppr.reporter_id, [ | ||
EMAIL_RECIPIENTS.reporter, | ||
EMAIL_RECIPIENTS.faculty_advisor, | ||
EMAIL_RECIPIENTS.admin, | ||
]) | ||
|
||
await sendEmail({ | ||
|
@@ -248,17 +249,17 @@ const sendEmailPPRApprovedToReporter = async (ppr) => { | |
}) | ||
} | ||
|
||
const sendEmailUPRApprovedToCoordinator = async (upr) => { | ||
const Subject = `[Ready to Buy] ${upr.codename}` | ||
const sendEmailPPRApprovedToReporter = async (ppr) => { | ||
const Subject = `[Ready to Buy] ${ppr.codename}` | ||
const HTMLPart = | ||
getMainMessageHTML( | ||
`A new UW Finance Purchase Request has been approved! Please purchase the approved item(s).<br> | ||
After purchase, update the purchase order number and requisition number at the ticket link below.` | ||
`Your Personal Purchase Request has been approved! Please purchase the approved item(s).<br> | ||
Upload your proof of purchase at the ticket link below to request reimbursement.` | ||
) + | ||
(await getUPRTicketInfoHTML(upr)) + | ||
getTicketLinkHTML(upr.path) | ||
const To = await getEmailToSection(upr.reporter_id, [ | ||
EMAIL_RECIPIENTS.coordinator, | ||
(await getPPRTicketInfoHTML(ppr)) + | ||
getTicketLinkHTML(ppr.path) | ||
const To = await getEmailToSection(ppr.reporter_id, [ | ||
EMAIL_RECIPIENTS.reporter, | ||
]) | ||
|
||
await sendEmail({ | ||
|
@@ -277,13 +278,16 @@ const sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator = async (ppr) => { | |
(await getPPRTicketInfoHTML(ppr)) + | ||
getTicketLinkHTML(ppr.path) | ||
const To = await getEmailToSection(ppr.reporter_id, [ | ||
EMAIL_RECIPIENTS.finance, | ||
EMAIL_RECIPIENTS.coordinator, | ||
]) | ||
const Cc = await getEmailToSection(ppr.reporter_id, [ | ||
EMAIL_RECIPIENTS.reporter, // cc'd for convenience if coordinator needs to contact reporter | ||
]) | ||
await sendEmail({ | ||
Subject, | ||
HTMLPart, | ||
To, | ||
Cc, | ||
}) | ||
} | ||
|
||
|
@@ -296,8 +300,7 @@ const sendEmailPPRReimbursedToReporter = async (ppr) => { | |
(await getPPRTicketInfoHTML(ppr)) + | ||
getTicketLinkHTML(ppr.path) | ||
const To = await getEmailToSection(ppr.reporter_id, [ | ||
EMAIL_RECIPIENTS.finance, | ||
EMAIL_RECIPIENTS.coordinator, | ||
EMAIL_RECIPIENTS.reporter, | ||
]) | ||
await sendEmail({ | ||
Subject, | ||
|
@@ -306,6 +309,8 @@ const sendEmailPPRReimbursedToReporter = async (ppr) => { | |
}) | ||
} | ||
|
||
// ******************** SF EMAILS ******************** | ||
|
||
const sendEmailSFReimbursementRequestToCoordinator = async (sf) => { | ||
const Subject = `[Action Needed] Submit Reimbursement Request ${sf.codename}` | ||
const HTMLPart = | ||
|
@@ -342,17 +347,13 @@ const sendEmailSFConfirmReimbursementSubmitToCoordinator = async (sf) => { | |
}) | ||
} | ||
|
||
const sendEmailSFReimbursementReceivedToTeam = async (sf) => { | ||
const sendEmailSFReimbursementReceivedToAdmin = async (sf) => { | ||
const Subject = `[Reimbursed] ${sf.codename}` | ||
const HTMLPart = | ||
getMainMessageHTML(`${sf.codename} has been reimbursed!`) + | ||
(await getSFTicketInfoHTML(sf)) + | ||
getTicketLinkHTML(sf.path) | ||
const To = await getEmailToSection(sf.reporter_id, [ | ||
EMAIL_RECIPIENTS.finance, | ||
EMAIL_RECIPIENTS.coordinator, | ||
EMAIL_RECIPIENTS.team_captain, | ||
]) | ||
const To = await getEmailToSection(sf.reporter_id, [EMAIL_RECIPIENTS.admin]) | ||
await sendEmail({ | ||
Subject, | ||
HTMLPart, | ||
|
@@ -365,12 +366,13 @@ module.exports = { | |
sendEmailUPRApprovedToCoordinator, | ||
sendEmailUPRPurchasedToReporter, | ||
sendEmailUPRPurchasedToCoordinator, | ||
sendEmailUPRReadyForPickupToCoordinator, | ||
sendEmailPPRApprovedToReporter, | ||
sendEmailUPRReadyForPickupToReporter, | ||
sendEmailUPRPickedUpToAdmin, | ||
sendEmailPPRCreatedToApprovers, | ||
sendEmailPPRApprovedToReporter, | ||
sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator, | ||
sendEmailPPRReimbursedToReporter, | ||
sendEmailSFReimbursementRequestToCoordinator, | ||
sendEmailSFConfirmReimbursementSubmitToCoordinator, | ||
sendEmailSFReimbursementReceivedToTeam, | ||
sendEmailSFReimbursementReceivedToAdmin, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ const TICKET_ENDPOINTS = Object.freeze({ | |
}) | ||
|
||
const ADMIN_IDENTIFIERS = ['drayside', 'v2zheng', 'jw4he', 'william.li'] | ||
const ADMIN_GROUP_EMAIL = '[email protected]' | ||
|
||
module.exports = { | ||
ENDOWMENT_FUNDS, | ||
|
@@ -68,4 +69,5 @@ module.exports = { | |
AUTH_ROLES, | ||
EMAIL_RECIPIENTS, | ||
ADMIN_IDENTIFIERS, | ||
ADMIN_GROUP_EMAIL, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters