completed user admin page

This commit is contained in:
PxlLoewe
2025-03-15 11:09:55 -07:00
parent abf3475c7c
commit 37d02ea0bc
23 changed files with 567 additions and 106 deletions

View File

@@ -0,0 +1,56 @@
import { Router } from "express";
import { sendMail } from "modules/mail";
import { sendPasswordChanged, sendCourseCompletedEmail } from "modules/mail";
const router = Router();
router.post("/send", async (req, res) => {
console.log(req.body);
const { to, subject, html } = req.body;
try {
await sendMail(to, subject, html);
// Send email logic here
res.status(200).json({ message: "Email sent successfully" });
} catch (error) {
res.status(500).json({ error: "Failed to send email" });
}
});
router.post("/template/:template", async (req, res) => {
const { template } = req.params;
const { to, data } = req.body;
if (!to || !data) {
res.status(400).json({ error: "Missing required fields" });
return;
}
if (!data.user) {
res.status(400).json({ error: "Missing user data" });
return;
}
console.log("template", template);
switch (template) {
case "password-change":
if (!data.password) {
res.status(400).json({ error: "Missing password data" });
return;
}
await sendPasswordChanged(to, data.user, data.password);
break;
case "course-completed":
if (!data.event) {
res.status(400).json({ error: "Missing event data" });
return;
}
await sendCourseCompletedEmail(to, data.user, data.event);
break;
default:
res.status(400).json({ error: "Invalid template" });
return;
}
res.status(200).json({ message: "Email sent successfully" });
});
export default router;

View File

@@ -0,0 +1,8 @@
import { Router } from "express";
import mailRouter from "./mail";
const router = Router();
router.use("/mail", mailRouter);
export default router;