From 4e9154b12ea3ddd9da32d2a4d1ebc30f13678c59 Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Wed, 7 Oct 2020 23:42:34 +0200 Subject: User profile boilerplate --- profile/public/script.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 profile/public/script.js (limited to 'profile/public/script.js') diff --git a/profile/public/script.js b/profile/public/script.js new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From fdb9bba6c88a4fd8981c30bf8ea06aa0709db45e Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Sat, 10 Oct 2020 12:05:53 +0200 Subject: Dynamic question loading --- profile/index.js | 12 ++++++++---- profile/public/index.html | 6 ++---- profile/public/script.js | 14 ++++++++++++++ profile/public/style.css | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 8 deletions(-) (limited to 'profile/public/script.js') diff --git a/profile/index.js b/profile/index.js index 4bfc1f7..2f1cb50 100644 --- a/profile/index.js +++ b/profile/index.js @@ -2,14 +2,16 @@ const express = require("express"); const db = require("../db"); const app = express.Router(); -app.use("/", express.static(__dirname + "/public/")); +app.use("/", express.static(__dirname + "/public")); // Basic API app.get("/api/user", async (req, res) => {}); app.get("/api/questions", async (req, res) => { const questions = await db.query("SELECT id, question FROM profile_questions"); - const answers = await db.query("SELECT answer, question_id FROM profile_answers WHERE user_id = ?", [req.session.uid]); + const answers = await db.query("SELECT answer, question_id FROM profile_answers WHERE user_id = ?", [ + req.session.uid, + ]); for (const answer of answers) { const qid = questions.findIndex((question) => question.id === answer.question_id); @@ -18,7 +20,9 @@ app.get("/api/questions", async (req, res) => { res.json(questions); }); -app.post("/api/add", async (req, res) => {}); +app.post("/api/add", async (req, res) => { + await db.query("INSERT INTO profile_answers (question_id, user_id, answer) VALUES (?, ?, ?)"); +}); app.put("/api/update", async (req, res) => {}); @@ -31,4 +35,4 @@ app.put("/api/comment", async (req, res) => {}); app.delete("/api/comment", async (req, res) => {}); -module.exports = app; \ No newline at end of file +module.exports = app; diff --git a/profile/public/index.html b/profile/public/index.html index 30f9de8..5fcee74 100644 --- a/profile/public/index.html +++ b/profile/public/index.html @@ -21,14 +21,12 @@
- +