1
0

feat: Added reporting errors
All checks were successful
Remote Deploy / deploy (push) Successful in 5s

This commit is contained in:
2025-10-24 07:50:26 +02:00
parent c202ce5207
commit 4714cff0b6

View File

@@ -26,7 +26,32 @@ app.get("/status", async (_, res) => {
}
})
// TODO: Reporting errors
app.post("/report", async (req, res) => {
const { class: className, location, content } = req.body;
if (!className || !location || !content) {
return res.status(400).json({ error: "Missing required fields." });
}
if (!["TIMETABLE", "ABSENCES", "OTHER"].includes(location)) {
return res.status(400).json({ error: "Invalid location value." });
}
const url = `https://n8n.local.jzitnik.dev/webhook/${process.env.WEBHOOK_UUID}`;
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "text/plain",
},
body: `${content}\n\nClass: ${className}\nLocation: ${location}`,
});
if (!res.ok) {
throw new Error(`Request failed`);
}
res.status(200).json({ message: "Report received successfully." });
});
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);