From 73218768648c5f70cbf2309dfc329c69e82e3ce4 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Tue, 25 Feb 2025 23:09:54 +0000 Subject: [PATCH] lock as onlyAdmin endpoint --- .../services/ems/routes/dispatch/post.js | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/packages/server/services/ems/routes/dispatch/post.js b/packages/server/services/ems/routes/dispatch/post.js index dc4e7f8e..9c7ced91 100644 --- a/packages/server/services/ems/routes/dispatch/post.js +++ b/packages/server/services/ems/routes/dispatch/post.js @@ -1,42 +1,43 @@ import templates from "../../templates" export default { - useContext: ["mailTransporter"], - middlewares: ["withAuthentication"], - fn: async (req, res) => { - req.body = await req.urlencoded() + useContext: ["mailTransporter"], + middlewares: ["withAuthentication", "onlyAdmin"], + fn: async (req, res) => { + req.body = await req.urlencoded() - let { to, subject, body, template } = req.body - - if (template) { - if (!templates[template]) { - throw new OperationError(404, "Template not found") - } + let { to, subject, body, template } = req.body - body = templates[template]({ - ...req.body - }) - } + if (template) { + if (!templates[template]) { + throw new OperationError(404, "Template not found") + } - const mailOptions = { - from: process.env.SMTP_USERNAME, - to: to, - subject: subject, - html: body - } + body = templates[template]({ + ...req.body, + }) + } - console.log(mailOptions) + const mailOptions = { + from: process.env.SMTP_USERNAME, + to: to, + subject: subject, + html: body, + } - console.log(`Sending email to ${to}...`) + console.log(mailOptions) - const result = await this.default.contexts.mailTransporter.sendMail(mailOptions) + console.log(`Sending email to ${to}...`) - console.log("Email sent! >", result) + const result = + await this.default.contexts.mailTransporter.sendMail(mailOptions) - return res.json({ - code: 0, - message: "ok", - result: result - }) - } -} \ No newline at end of file + console.log("Email sent! >", result) + + return res.json({ + code: 0, + message: "ok", + result: result, + }) + }, +}