aboutsummaryrefslogtreecommitdiff
path: root/mottovote/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'mottovote/index.js')
-rw-r--r--mottovote/index.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/mottovote/index.js b/mottovote/index.js
index a485a8b..d22ba29 100644
--- a/mottovote/index.js
+++ b/mottovote/index.js
@@ -20,6 +20,7 @@ app.get("/api/list", checkUser, async (req, res) => {
app.put("/api/vote", checkUser, async (req, res) => {
await db.query("DELETE FROM motto_votes WHERE user_id = ?", [req.session.uid]);
try {
+ if (req.body.entries().length > 3) return res.send("error");
for (const mid in req.body) {
await db.query(
"INSERT INTO motto_votes (user_id, motto_id, votes) VALUES (?, ?, ?)",
@@ -33,4 +34,10 @@ app.put("/api/vote", checkUser, async (req, res) => {
}
});
+// Vote result - admin
+app.get("/api/get", checkUser, async (req, res) => {
+ const votes = await db.query("SELECT m.id, m.name, m.description, SUM(votes) votes FROM motto_votes mv RIGHT JOIN mottos m on mv.motto_id = m.id GROUP BY m.id, m.name, m.description ORDER BY SUM(votes) DESC");
+ res.json(votes);
+});
+
module.exports = app; \ No newline at end of file