diff options
Diffstat (limited to 'mottovote/index.js')
-rw-r--r-- | mottovote/index.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/mottovote/index.js b/mottovote/index.js new file mode 100644 index 0000000..4806e55 --- /dev/null +++ b/mottovote/index.js @@ -0,0 +1,21 @@ +const express = require("express"); +const db = require("../db"); +const { checkUser } = require("../auth"); +const app = express.Router(); + + +app.use("/", express.static(__dirname + "/public/")); + +app.get("/api/list", async (req, res) => { + const mottos = await db.query("SELECT id, name, description FROM motto_votes ORDER BY name, description"); + res.json(mottos); +}); + +app.put("/api/vote", async (req, res) => { + for (const mid in req.body) { + await db.query("UPDATE motto_votes SET votes = votes + ? WHERE id = ?", [req.body[mid], mid]); + } + res.send("ok"); +}); + +module.exports = app;
\ No newline at end of file |