diff options
author | LarsVomMars | 2020-10-03 12:59:22 +0200 |
---|---|---|
committer | LarsVomMars | 2020-10-03 12:59:30 +0200 |
commit | 069e4d5a3bb03d4fcba46ae40657eb55b8581c53 (patch) | |
tree | 4428dddd1ed5b05d356874d161e3d7ba5cac52dd | |
parent | 0fd8f61362403934550b360cbd65f1b41d66c870 (diff) |
Delte owner
-rw-r--r-- | quotes/index.js | 3 | ||||
-rw-r--r-- | quotes/public/script.js | 5 |
2 files changed, 5 insertions, 3 deletions
diff --git a/quotes/index.js b/quotes/index.js index 9683009..5aa0646 100644 --- a/quotes/index.js +++ b/quotes/index.js @@ -22,7 +22,8 @@ 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, (q.user_id = ?) AS owner 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", + [req.session.uid], ); res.json(quotes); }); diff --git a/quotes/public/script.js b/quotes/public/script.js index 20587fe..8132019 100644 --- a/quotes/public/script.js +++ b/quotes/public/script.js @@ -21,10 +21,11 @@ function appendQuote(response) { "beforeend", `<li>${elem["name"]} ${elem["middlename"] ? elem["middlename"] : " "}${elem["surname"]}: ${ elem["quote"] - } <span data-id="${elem["id"]}">[Löschen]</span></li>`, + }${elem["owner"] ? '<span data-id="' + elem["id"] + '">[Löschen]</span></li>' : ""}`, ); - document.querySelector(`li span[data-id="${elem["id"]}"]`).addEventListener("click", (event) => { + const span = document.querySelector(`li span[data-id="${elem["id"]}"]`); + if (span) span.addEventListener("click", (event) => { fetch("api/delete/" + event.target.getAttribute("data-id"), { method: "DELETE" }) .then((response) => response.text()) .then((response) => { |