diff options
author | Marvin Borner | 2020-10-03 11:56:46 +0200 |
---|---|---|
committer | Marvin Borner | 2020-10-03 11:56:46 +0200 |
commit | 148a9a5a63ed3e73d0a8709e7972fd1b1586c5b8 (patch) | |
tree | d5650c856ea18f1f0a7306028844587d4697e7be /poll/index.js | |
parent | 970dfec33a2cd53ad72ba0da59c129f65d6032f6 (diff) |
Added class-specific filter
Diffstat (limited to 'poll/index.js')
-rw-r--r-- | poll/index.js | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/poll/index.js b/poll/index.js index ab9ee6f..74b5875 100644 --- a/poll/index.js +++ b/poll/index.js @@ -8,6 +8,11 @@ app.use("/", checkUser, express.static(__dirname + "/public")); app.post("/api/answer", checkUser, async (req, res) => { if (!req.body.answer || !req.body.question) return res.send("error"); try { + const user_class = (await db.query("SELECT class_id FROM users WHERE id = ?", [req.session.uid]))[0].class_id; + const answer_class = (await db.query("SELECT class_id FROM users WHERE id = ?", [parseInt(req.body.answer)]))[0] + .class_id; + if (user_class != answer_class) return res.send("error"); + await db.query("INSERT INTO ranking_answers (question_id, user_id, answer_id) VALUE (?,?,?)", [ parseInt(req.body.question), req.session.uid, @@ -25,7 +30,7 @@ app.get("/api/get", checkUser, async (req, res) => { const question = ( await db.query( "SELECT q.id, q.question, t.name FROM ranking_questions AS q INNER JOIN types AS t ON type_id = t.id WHERE q.id NOT IN (SELECT question_id FROM ranking_answers WHERE user_id = ?) AND t.name = 'pupil' LIMIT 1", - [req.session.uid] + [req.session.uid], ) )[0]; res.json(question); |