diff --git a/backend/emails/emails.js b/backend/emails/emails.js index af1ba9b..1b1e7a7 100644 --- a/backend/emails/emails.js +++ b/backend/emails/emails.js @@ -1,14 +1,8 @@ -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 = 'finance@watonomous.ca' -const DivisionEmails = { - software: 'software-leads@watonomous.ca', - mechanical: 'mechanical-leads@watonomous.ca', - business: 'business-leads@watonomous.ca', - electrical: 'electrical-leads@watonomous.ca', -} const currencyFormatter = new Intl.NumberFormat('en-CA', { style: 'currency', @@ -16,24 +10,18 @@ const currencyFormatter = new Intl.NumberFormat('en-CA', { }) 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('studentdesigncentreengineering@uwaterloo.ca') - // emailToSet.add('srfeeney@uwaterloo.ca') - } - - if (recipients.includes(EMAIL_RECIPIENTS.director)) { - // TODO: get director emails } if (recipients.includes(EMAIL_RECIPIENTS.faculty_advisor)) { - // emailToSet.add('drayside@uwaterloo.ca') + // TODO: emailToSet.add('drayside@uwaterloo.ca') } if (recipients.includes(EMAIL_RECIPIENTS.finance)) { @@ -47,10 +35,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 +113,19 @@ const getTicketLinkHTML = (ticketPath) => `

` -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 +135,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).
+ 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 +193,7 @@ const sendEmailUPRPurchasedToCoordinator = async (upr) => { }) } -const sendEmailUPRReadyForPickupToCoordinator = async (upr) => { +const sendEmailUPRReadyForPickupToReporter = async (upr) => { const Subject = `[Ready for pickup] ${upr.codename}` const HTMLPart = getMainMessageHTML( @@ -228,17 +212,19 @@ const sendEmailUPRReadyForPickupToCoordinator = async (upr) => { }) } -const sendEmailPPRApprovedToReporter = async (ppr) => { - const Subject = `[Ready to Buy] ${ppr.codename}` +// ******************** 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).
- 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 +234,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).
- 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).
+ 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,7 +263,6 @@ const sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator = async (ppr) => { (await getPPRTicketInfoHTML(ppr)) + getTicketLinkHTML(ppr.path) const To = await getEmailToSection(ppr.reporter_id, [ - EMAIL_RECIPIENTS.finance, EMAIL_RECIPIENTS.coordinator, ]) await sendEmail({ @@ -296,8 +281,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 +290,8 @@ const sendEmailPPRReimbursedToReporter = async (ppr) => { }) } +// ******************** SF EMAILS ******************** + const sendEmailSFReimbursementRequestToCoordinator = async (sf) => { const Subject = `[Action Needed] Submit Reimbursement Request ${sf.codename}` const HTMLPart = @@ -349,9 +335,7 @@ const sendEmailSFReimbursementReceivedToTeam = async (sf) => { (await getSFTicketInfoHTML(sf)) + getTicketLinkHTML(sf.path) const To = await getEmailToSection(sf.reporter_id, [ - EMAIL_RECIPIENTS.finance, EMAIL_RECIPIENTS.coordinator, - EMAIL_RECIPIENTS.team_captain, ]) await sendEmail({ Subject, @@ -365,9 +349,9 @@ module.exports = { sendEmailUPRApprovedToCoordinator, sendEmailUPRPurchasedToReporter, sendEmailUPRPurchasedToCoordinator, - sendEmailUPRReadyForPickupToCoordinator, - sendEmailPPRApprovedToReporter, + sendEmailUPRReadyForPickupToReporter, sendEmailPPRCreatedToApprovers, + sendEmailPPRApprovedToReporter, sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator, sendEmailPPRReimbursedToReporter, sendEmailSFReimbursementRequestToCoordinator, diff --git a/backend/models/constants.js b/backend/models/constants.js index 9fe88ef..1fe67d5 100644 --- a/backend/models/constants.js +++ b/backend/models/constants.js @@ -55,6 +55,7 @@ const TICKET_ENDPOINTS = Object.freeze({ }) const ADMIN_IDENTIFIERS = ['drayside', 'v2zheng', 'jw4he', 'william.li'] +const ADMIN_GROUP_EMAIL = 'finance-admin@watonomous.ca' module.exports = { ENDOWMENT_FUNDS, @@ -68,4 +69,5 @@ module.exports = { AUTH_ROLES, EMAIL_RECIPIENTS, ADMIN_IDENTIFIERS, + ADMIN_GROUP_EMAIL, } diff --git a/backend/service/uwfinancepurchases.service.js b/backend/service/uwfinancepurchases.service.js index 609cf41..49c4d48 100644 --- a/backend/service/uwfinancepurchases.service.js +++ b/backend/service/uwfinancepurchases.service.js @@ -9,7 +9,7 @@ const { sendEmailUPRApprovedToCoordinator, sendEmailUPRPurchasedToCoordinator, sendEmailUPRPurchasedToReporter, - sendEmailUPRReadyForPickupToCoordinator, + sendEmailUPRReadyForPickupToReporter, } = require('../emails/emails') const getAllUWFinancePurchases = () => { @@ -53,7 +53,7 @@ const updateUWFinancePurchase = async (id, body) => { // ORDERED -> READY_FOR_PICKUP if (body.status === 'READY_FOR_PICKUP') { const annotatedUPR = await getUWFinancePurchase(id) - await sendEmailUPRReadyForPickupToCoordinator(annotatedUPR) + await sendEmailUPRReadyForPickupToReporter(annotatedUPR) } return newPurchaseTicket }