feat: Added reporting errors
All checks were successful
Remote Deploy / deploy (push) Successful in 5s
All checks were successful
Remote Deploy / deploy (push) Successful in 5s
This commit is contained in:
27
server.js
27
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}`);
|
||||
|
||||
Reference in New Issue
Block a user