Skip to content

Commit

Permalink
add CC to emails, add upr picked up email
Browse files Browse the repository at this point in the history
  • Loading branch information
ansonjwhe committed Jul 18, 2024
1 parent 4f82be3 commit 0fbfa19
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
40 changes: 29 additions & 11 deletions backend/emails/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ 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 currencyFormatter = new Intl.NumberFormat('en-CA', {
style: 'currency',
currency: 'CAD',
Expand All @@ -24,10 +22,6 @@ const getEmailToSection = async (reporter_id, recipients) => {
// TODO: emailToSet.add('[email protected]')
}

if (recipients.includes(EMAIL_RECIPIENTS.finance)) {
// emailToSet.add(process.env.WATO_FINANCE_FINANCE_EMAIL)
}

if (recipients.includes(EMAIL_RECIPIENTS.reporter)) {
const reporter = await getUserByUID(reporter_id)
if (reporter.email) {
Expand Down Expand Up @@ -204,6 +198,27 @@ const sendEmailUPRReadyForPickupToReporter = 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 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,
Expand Down Expand Up @@ -265,10 +280,14 @@ const sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator = async (ppr) => {
const To = await getEmailToSection(ppr.reporter_id, [
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,
})
}

Expand Down Expand Up @@ -328,15 +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.coordinator,
])
const To = await getEmailToSection(sf.reporter_id, [EMAIL_RECIPIENTS.admin])
await sendEmail({
Subject,
HTMLPart,
Expand All @@ -350,11 +367,12 @@ module.exports = {
sendEmailUPRPurchasedToReporter,
sendEmailUPRPurchasedToCoordinator,
sendEmailUPRReadyForPickupToReporter,
sendEmailUPRPickedUpToAdmin,
sendEmailPPRCreatedToApprovers,
sendEmailPPRApprovedToReporter,
sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator,
sendEmailPPRReimbursedToReporter,
sendEmailSFReimbursementRequestToCoordinator,
sendEmailSFConfirmReimbursementSubmitToCoordinator,
sendEmailSFReimbursementReceivedToTeam,
sendEmailSFReimbursementReceivedToAdmin,
}
3 changes: 2 additions & 1 deletion backend/service/sendEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const mailjet = Mailjet.apiConnect(
process.env.WATO_FINANCE_MAILJET_SECRET_KEY
)

const sendEmail = async ({ To, Subject, HTMLPart }) => {
const sendEmail = async ({ Subject, HTMLPart, To, Cc = [] }) => {
console.log('📧 Subject:', Subject)
console.log('📬 Recipients:', To)
try {
Expand All @@ -16,6 +16,7 @@ const sendEmail = async ({ To, Subject, HTMLPart }) => {
Email: process.env.WATO_FINANCE_FINANCE_EMAIL,
},
To,
Cc,
Subject,
HTMLPart,
},
Expand Down
4 changes: 2 additions & 2 deletions backend/service/sponsorshipfunds.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const {
sendEmailSFReimbursementRequestToCoordinator,
sendEmailSFConfirmReimbursementSubmitToCoordinator,
sendEmailSFReimbursementReceivedToTeam,
sendEmailSFReimbursementReceivedToAdmin,
} = require('../emails/emails')

const getAllSponsorshipFunds = () => {
Expand Down Expand Up @@ -79,7 +79,7 @@ const updateSponsorshipFund = async (id, body) => {
}

if (status === 'REIMBURSED') {
await sendEmailSFReimbursementReceivedToTeam(annotatedSponsorshipFund)
await sendEmailSFReimbursementReceivedToAdmin(annotatedSponsorshipFund)
}

return newSponsorshipFund
Expand Down
6 changes: 6 additions & 0 deletions backend/service/uwfinancepurchases.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
sendEmailUPRPurchasedToCoordinator,
sendEmailUPRPurchasedToReporter,
sendEmailUPRReadyForPickupToReporter,
sendEmailUPRPickedUpToAdmin,
} = require('../emails/emails')

const getAllUWFinancePurchases = () => {
Expand Down Expand Up @@ -55,6 +56,11 @@ const updateUWFinancePurchase = async (id, body) => {
const annotatedUPR = await getUWFinancePurchase(id)
await sendEmailUPRReadyForPickupToReporter(annotatedUPR)
}
// READY_FOR_PICKUP -> PICKED_UP
if (body.status === 'PICKED_UP') {
const annotatedUPR = await getUWFinancePurchase(id)
await sendEmailUPRPickedUpToAdmin(annotatedUPR)
}
return newPurchaseTicket
}

Expand Down

0 comments on commit 0fbfa19

Please sign in to comment.