From 4ae93926259fa54250fef6117ad8e81a1739f9b7 Mon Sep 17 00:00:00 2001 From: Hadi Ahmed Date: Mon, 24 Oct 2022 23:11:48 -0400 Subject: [PATCH] Inform treasurer on budget submission --- api/src/routes/budgets.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/api/src/routes/budgets.js b/api/src/routes/budgets.js index 8cb5c6c5..3c9bec0b 100644 --- a/api/src/routes/budgets.js +++ b/api/src/routes/budgets.js @@ -17,7 +17,7 @@ import { Router } from "express"; import Models from "../models/index.js"; -import { fiscal_year_list, committee_lut, ACCESS_LEVEL, logger, max_fiscal_year_count } from "../common_items.js"; +import { fiscal_year_list, committee_lut, ACCESS_LEVEL, logger, max_fiscal_year_count, mailer, current_fiscal_year } from "../common_items.js"; const router = Router(); @@ -86,14 +86,28 @@ router.post("/:comm", async(req, res, next) => { await Models.budgets.addBudget(budget); } + res.status(201).send("Budget submitted for approval"); + + // Inform the treasurer there is a budget to approve + if (process.env.SEND_MAIL !== "yes") return next(); // SEND_MAIL must be "yes" or no mail is sent + await mailer.sendMail({ + to: process.env.TREAS_EMAIL, + subject: `Budget submitted by ${committee_lut[req.params.comm][0]}`, + text: `${committee_lut[req.params.comm][0]} has submitted a new budget for the current fiscal year.\n`+ + "Please visit Boiler Books at your earliest convenience to review and/or approve the budget.\n\n"+ + "This email was automatically sent by Boiler Books", + html: `

${committee_lut[req.params.comm][0]} has submitted a new budget for the current fiscal year.

+

Please visit Boiler Books at your earliest convenience to review and/or approve the budget.

+
+ This email was automatically sent by Boiler Books`, + }); + + return next(); } catch (err) { logger.error(err.stack); res.status(500).send("Internal Server Error"); return next(); } - - res.status(201).send("Budget submitted for approval"); - return next(); }); /*