lock as onlyAdmin endpoint

This commit is contained in:
SrGooglo 2025-02-25 23:09:54 +00:00
parent d05253c8cd
commit 7321876864

View File

@ -1,42 +1,43 @@
import templates from "../../templates" import templates from "../../templates"
export default { export default {
useContext: ["mailTransporter"], useContext: ["mailTransporter"],
middlewares: ["withAuthentication"], middlewares: ["withAuthentication", "onlyAdmin"],
fn: async (req, res) => { fn: async (req, res) => {
req.body = await req.urlencoded() req.body = await req.urlencoded()
let { to, subject, body, template } = req.body let { to, subject, body, template } = req.body
if (template) {
if (!templates[template]) {
throw new OperationError(404, "Template not found")
}
body = templates[template]({ if (template) {
...req.body if (!templates[template]) {
}) throw new OperationError(404, "Template not found")
} }
const mailOptions = { body = templates[template]({
from: process.env.SMTP_USERNAME, ...req.body,
to: to, })
subject: subject, }
html: 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({ console.log("Email sent! >", result)
code: 0,
message: "ok", return res.json({
result: result code: 0,
}) message: "ok",
} result: result,
} })
},
}