From a2c5699629c556b737e74b066e05ad037767ca25 Mon Sep 17 00:00:00 2001 From: klaas Date: Sat, 28 Sep 2024 15:02:25 +0200 Subject: [PATCH] =?UTF-8?q?Feature=20Request=20Seite=20f=C3=BCr=20Features?= =?UTF-8?q?,=20Bugs=20und=20Designvorschl=C3=A4ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 41 +++++++++++++++++++++++++++++++++++++++ views/partials/header.ejs | 6 +++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 148e4b4..9a8f505 100644 --- a/app.js +++ b/app.js @@ -1103,6 +1103,47 @@ app.post("/deleteMember", requireAuth, async (req, res) => { res.redirect("/teilnehmer"); }); +app.get("/feature", requireAuth, async (req, res) => { + try { + const featureResult = await pool.query( + "SELECT * FROM features ORDER BY datetime DESC;" + ); + const features = featureResult.rows; + res.render("feature", { features, session: req.session }); + } catch (error) { + console.error("Error:", error); + req.session.message = ["Error", error, "error"]; + res.redirect("/feature"); + } +}); + +app.post("/feature", requireAdmin, async (req, res) => { + const { title, body, type, urgency, user } = req.body; + console.log(user); + const userResult = await pool.query( + "SELECT id FROM users WHERE username = $1", + [user] + ); + console.log(userResult.rows[0].id); + try { + await pool.query( + "INSERT INTO features (title, body, type, urgency, fid_user) VALUES ($1, $2, $3, $4, $5);", + [title, body, type, urgency, userResult.rows[0].id] + ); + + const featureResult = await pool.query( + "SELECT * FROM features ORDER BY datetime DESC;" + ); + const features = featureResult.rows; + req.session.message = ["Erfolg", "Feature-request gespeichert", "success"]; + res.render("feature", { features, session: req.session }); + } catch (error) { + console.error("Error:", error); + req.session.message = ["Error", error, "error"]; + res.render("feature", { features, session: req.session }); + } +}); + const server = app.listen(port, "0.0.0.0", () => { log.Info(`Server is running on ${process.env.HOST}:${port}/`); }); diff --git a/views/partials/header.ejs b/views/partials/header.ejs index 32311a5..31c3eb3 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -45,6 +45,9 @@ + <% } else {%> - <% if (session && session.role === 'admin') { %> <% } %>