aboutsummaryrefslogtreecommitdiff
path: root/quotes/index.js
diff options
context:
space:
mode:
authorMarvin Borner2020-10-03 12:31:15 +0200
committerMarvin Borner2020-10-03 12:31:27 +0200
commit7285ce6a534baed7c94c28d6ccaadc959156e94d (patch)
treefcc3d94a7f270db040a69a0d3627260b87098bde /quotes/index.js
parent9e18568e9d51a6e07d71dd0ec987e8acf737fac2 (diff)
Added quote deletion
Diffstat (limited to 'quotes/index.js')
-rw-r--r--quotes/index.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/quotes/index.js b/quotes/index.js
index c0014c6..9683009 100644
--- a/quotes/index.js
+++ b/quotes/index.js
@@ -22,9 +22,20 @@ app.post("/api/add", checkUser, async (req, res) => {
app.get("/api/list", checkUser, async (req, res) => {
const quotes = await db.query(
- "SELECT q.id, a.name, a.middlename, a.surname, q.quote, c.name AS class FROM quotes AS q INNER JOIN users AS a ON author_id = a.id INNER JOIN class AS c ON a.class_id = c.id ORDER BY a.name"
+ "SELECT q.id, a.name, a.middlename, a.surname, q.quote, c.name AS class FROM quotes AS q INNER JOIN users AS a ON author_id = a.id INNER JOIN class AS c ON a.class_id = c.id ORDER BY a.name",
);
res.json(quotes);
});
+app.delete("/api/delete/:id", checkUser, async (req, res) => {
+ if (!req.params.id) return res.send("error");
+ try {
+ await db.query("DELETE FROM quotes WHERE id = ? AND user_id = ?", [req.params.id, req.session.uid]);
+ res.send("ok");
+ } catch (e) {
+ console.error(e);
+ res.send("error");
+ }
+});
+
module.exports = app;