diff --git a/backend/emails/emails.js b/backend/emails/emails.js index 1b1e7a7..73eb8ea 100644 --- a/backend/emails/emails.js +++ b/backend/emails/emails.js @@ -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 = 'finance@watonomous.ca' - const currencyFormatter = new Intl.NumberFormat('en-CA', { style: 'currency', currency: 'CAD', @@ -24,10 +22,6 @@ const getEmailToSection = async (reporter_id, recipients) => { // TODO: emailToSet.add('drayside@uwaterloo.ca') } - 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) { @@ -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, @@ -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, }) } @@ -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, @@ -350,11 +367,12 @@ module.exports = { sendEmailUPRPurchasedToReporter, sendEmailUPRPurchasedToCoordinator, sendEmailUPRReadyForPickupToReporter, + sendEmailUPRPickedUpToAdmin, sendEmailPPRCreatedToApprovers, sendEmailPPRApprovedToReporter, sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator, sendEmailPPRReimbursedToReporter, sendEmailSFReimbursementRequestToCoordinator, sendEmailSFConfirmReimbursementSubmitToCoordinator, - sendEmailSFReimbursementReceivedToTeam, + sendEmailSFReimbursementReceivedToAdmin, } diff --git a/backend/service/sendEmail.js b/backend/service/sendEmail.js index 3461c89..306564e 100644 --- a/backend/service/sendEmail.js +++ b/backend/service/sendEmail.js @@ -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 { @@ -16,6 +16,7 @@ const sendEmail = async ({ To, Subject, HTMLPart }) => { Email: process.env.WATO_FINANCE_FINANCE_EMAIL, }, To, + Cc, Subject, HTMLPart, }, diff --git a/backend/service/sponsorshipfunds.service.js b/backend/service/sponsorshipfunds.service.js index f38ef9c..47e6594 100644 --- a/backend/service/sponsorshipfunds.service.js +++ b/backend/service/sponsorshipfunds.service.js @@ -9,7 +9,7 @@ const { const { sendEmailSFReimbursementRequestToCoordinator, sendEmailSFConfirmReimbursementSubmitToCoordinator, - sendEmailSFReimbursementReceivedToTeam, + sendEmailSFReimbursementReceivedToAdmin, } = require('../emails/emails') const getAllSponsorshipFunds = () => { @@ -79,7 +79,7 @@ const updateSponsorshipFund = async (id, body) => { } if (status === 'REIMBURSED') { - await sendEmailSFReimbursementReceivedToTeam(annotatedSponsorshipFund) + await sendEmailSFReimbursementReceivedToAdmin(annotatedSponsorshipFund) } return newSponsorshipFund diff --git a/backend/service/uwfinancepurchases.service.js b/backend/service/uwfinancepurchases.service.js index 49c4d48..834349e 100644 --- a/backend/service/uwfinancepurchases.service.js +++ b/backend/service/uwfinancepurchases.service.js @@ -10,6 +10,7 @@ const { sendEmailUPRPurchasedToCoordinator, sendEmailUPRPurchasedToReporter, sendEmailUPRReadyForPickupToReporter, + sendEmailUPRPickedUpToAdmin, } = require('../emails/emails') const getAllUWFinancePurchases = () => { @@ -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 }