From 83007e8e3b13ee1eb0670ebd04f4530394cbffc9 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 1 Oct 2020 18:26:45 +0200 Subject: Fixed Lars --- db.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/db.js b/db.js index dbef8f4..ab6a7f2 100644 --- a/db.js +++ b/db.js @@ -35,13 +35,16 @@ class DB { } initValues() { - fs.readFile(__dirname + "/names.csv", "utf8", (err, data) => { + fs.readFile(__dirname + "/names.csv", "utf8", async (err, data) => { if (err) throw err; const classes = data.split("--"); const userPasswords = []; - classes.forEach((clazz, classIndex) => { + console.log("Generating users"); + for (const [classIndex, clazz] of classes.entries()) { const students = clazz.split("\n"); - students.forEach(async (student) => { + // students.forEach(async (student) => { + for (const student of students) { + console.log("."); // Fix undefined if (student && student.length > 3) { const [_, surname, name] = student.split(","); @@ -58,9 +61,12 @@ class DB { [username, names[0].replace("\r", ""), middlename, surname, password, classIndex + 1, 2] ); } - }); + } + } + fs.writeFile(__dirname + "/users.json", JSON.stringify(userPasswords), (err) => { + if (err) console.error(err); }); - fs.writeFile(__dirname + "/users.json", JSON.stringify(userPasswords), console.error); + console.log("Initialized users!"); }); } -- cgit v1.2.3