From 4714cff0b654637b1eb792bb1ce16e5a222e7d52 Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Fri, 24 Oct 2025 07:50:26 +0200 Subject: [PATCH] feat: Added reporting errors --- server.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 40b01b1..c588a5d 100644 --- a/server.js +++ b/server.js @@ -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}`);