aboutsummaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
Diffstat (limited to 'admin')
-rw-r--r--admin/index.js13
-rw-r--r--admin/public/votes.js6
2 files changed, 14 insertions, 5 deletions
diff --git a/admin/index.js b/admin/index.js
index 99c876a..8d71896 100644
--- a/admin/index.js
+++ b/admin/index.js
@@ -3,7 +3,16 @@ const db = require("../db");
const app = express.Router();
const { checkUser, checkAdmin } = require("../auth");
-app.use("/", checkAdmin, express.static(__dirname + "/public"));
+// app.use("/", checkAdmin, express.static(__dirname + "/public"));
+app.use(
+ "/",
+ (req, res, next) => {
+ console.log(req.path);
+ if ((req.session.loggedIn && req.session.isAdmin) || req.path.startsWith("/api/votes")) next();
+ else res.redirect("/");
+ },
+ express.static(__dirname + "/public"),
+);
// For debugging ig
app.get("/api/all", checkAdmin, async (req, res) => {
@@ -45,7 +54,7 @@ app.get("/api/answers", checkAdmin, async (req, res) => {
res.json(answers);
});
-app.get("/api/votes", checkAdmin, async (req, res) => {
+app.get("/api/votes", 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",
);
diff --git a/admin/public/votes.js b/admin/public/votes.js
index 62ff374..1bde08b 100644
--- a/admin/public/votes.js
+++ b/admin/public/votes.js
@@ -1,11 +1,11 @@
let date;
let chart;
-fetch("api/votes")
+fetch("/admin/api/votes")
.then((response) => response.json())
.then((response) => {
data = response;
- render("bar");
+ render("pie");
});
function render(type) {
@@ -42,7 +42,7 @@ function render(type) {
}
let index = 0;
-const types = ["pie", "doughnut", "polarArea", "radar", "line", "bar"];
+const types = ["doughnut", "bar", "polarArea", "radar", "line", "pie"];
document.getElementById("switch").addEventListener("click", () => {
chart.destroy();
render(types[index]);