From 68b06d4cdd24607cee4f016425c4380aea6d556d Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Wed, 7 Oct 2020 23:11:08 +0200 Subject: Fixed duplicated entry for teacher polls --- db.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/db.js b/db.js index eea9fae..16f2970 100644 --- a/db.js +++ b/db.js @@ -35,7 +35,7 @@ class DB { fs.readFile(__dirname + "/names.csv", "utf8", async (err, data) => { if (err) throw err; - await this.query("INSERT INTO types (name) VALUES ('teacher'), ('pupil')"); + await this.query("INSERT INTO types (name) VALUES ('pupil'), ('teacher')"); await this.query( "INSERT INTO class (name) VALUES ('TGM13.1'), ('TGM13.2'), ('TGTM13.1'), ('TGI13.1'), ('TGI13.2'), ('teacher')" ); @@ -43,10 +43,13 @@ class DB { fs.readFile(__dirname + "/poll.txt", "utf8", (err, data) => { if (err) throw err; - const questions = data.split("\n"); - questions.forEach((question) => { - if (question.length > 0) - this.query("INSERT INTO ranking_questions (question, type_id) VALUE (?,?)", [question, 2]); + const parts = data.split("--"); + parts.forEach((part, i) => { + const questions = part.split("\n"); + questions.forEach((question) => { + if (question.length > 0) + this.query("INSERT INTO ranking_questions (question, type_id) VALUE (?,?)", [question, i+1]); + }); }); }); -- cgit v1.2.3