aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2021-01-25 18:59:16 +0100
committerMarvin Borner2021-01-25 18:59:16 +0100
commit648762d7a32b27fb43f6931aa93fc4022358ad1b (patch)
tree24dc45149be27698348661164aa9ebca9655f6be
parent23334817e85faea27234aba1c4c0ab75889c62e5 (diff)
idk
-rw-r--r--questions.txt2
-rw-r--r--questions/index.js17
-rw-r--r--questions/public/script.js10
-rw-r--r--tables.sql2
4 files changed, 10 insertions, 21 deletions
diff --git a/questions.txt b/questions.txt
index fb25a9d..118c921 100644
--- a/questions.txt
+++ b/questions.txt
@@ -1,2 +1,2 @@
Bist du blöd?
-Fällst du durch? \ No newline at end of file
+Fällst du durch?
diff --git a/questions/index.js b/questions/index.js
index daf419d..1f0f4ce 100644
--- a/questions/index.js
+++ b/questions/index.js
@@ -7,18 +7,12 @@ app.use("/", checkUser, express.static(__dirname + "/public"));
app.get("/api/question/:id", checkUser, async (req, res) => {
try {
- const questions = await db.query(
- `SELECT id, question
- FROM question_questions`
- );
+ const questions = await db.query("SELECT id, question FROM question_questions");
const id = +req.params.id;
if (id >= 0 && id < questions.length) {
const question = questions[id];
const answers = await db.query(
- `SELECT answer
- FROM question_answers
- WHERE question_id = ?
- AND user_id = ?`,
+ "SELECT answer FROM question_answers WHERE question_id = ? AND user_id = ?",
[question.id, req.session.uid],
);
question.answer = answers.length > 0 ? answers[0].answer : undefined;
@@ -36,12 +30,7 @@ app.get("/api/questions", checkUser, async (req, res) => {
const fail = { success: false };
try {
const questions = await db.query("SELECT id FROM question_questions");
- const answers = await db.query(
- `SELECT question_id
- FROM question_answers
- WHERE user_id = ?`,
- [req.session.uid],
- );
+ const answers = await db.query("SELECT question_id FROM question_answers WHERE user_id = ?", [req.session.uid]);
const resp = [];
let i = 0;
for (const question of questions) {
diff --git a/questions/public/script.js b/questions/public/script.js
index e5a03d0..aaeac00 100644
--- a/questions/public/script.js
+++ b/questions/public/script.js
@@ -30,7 +30,7 @@ fetch(`api/question/${qid}`)
} else getNext(); // Resets
});
-fetch(`api/questions`)
+fetch("api/questions")
.then((response) => response.json())
.then((response) => {
for (const elem of response) {
@@ -61,14 +61,14 @@ NodeList.prototype.on = function (listener, event) {
for (const node of this) {
node.addEventListener(listener, event);
}
-}
+};
buttons.on("click", async (e) => {
const body = JSON.stringify({
question: question_input.value,
answer: e.target.dataset.value === "1",
});
- const resp = await fetch(`api/answer`, {
+ const resp = await fetch("api/answer", {
method,
headers: { "Content-Type": "application/json" },
body,
@@ -76,8 +76,8 @@ buttons.on("click", async (e) => {
const res = await resp.json();
if (res.success) {
method = "PUT";
- getNext(qid);
+ getNext(qid + 1);
// document.querySelector(`.answer-btn[data-value="${e.target.dataset.value}"]`).style.opacity = "0.5";
// document.querySelector(`.answer-btn[data-value="${+!+e.target.dataset.value}"]`).style.opacity = "1"; // Let's not talk about it
}
-}); \ No newline at end of file
+});
diff --git a/tables.sql b/tables.sql
index 546c92e..eae1cd9 100644
--- a/tables.sql
+++ b/tables.sql
@@ -152,4 +152,4 @@ CREATE TABLE IF NOT EXISTS question_answers
CONSTRAINT `fk_question_user` FOREIGN KEY (user_id) REFERENCES users (id),
CONSTRAINT `fk_question_question` FOREIGN KEY (question_id) REFERENCES question_questions (id)
) ENGINE = InnoDB
- DEFAULT CHARSET = utf8; \ No newline at end of file
+ DEFAULT CHARSET = utf8;