diff options
author | LarsVomMars | 2020-10-01 17:04:39 +0200 |
---|---|---|
committer | LarsVomMars | 2020-10-01 17:04:39 +0200 |
commit | 417b247cf5b6e191ada3c3591cc002ebafc4dd3e (patch) | |
tree | 3c7bae22ae8fb325d6be0f55b987cd15ac038693 | |
parent | 590723afb4178e070a372d6e6054fe4d8549a4b0 (diff) |
AHHH
-rw-r--r-- | db.js | 25 |
1 files changed, 0 insertions, 25 deletions
@@ -29,31 +29,6 @@ class DB { for (const query of queries) await this.query(query); console.log("Tables created!"); }); - - fs.readFile(__dirname + "/names.csv", "utf8", (err, data) => { - if (err) throw err; - const classes = data.split("--"); - classes.forEach((clazz, classIndex) => { - const students = clazz.split("\n"); - students.forEach(async (student) => { - // Fix undefined - if (student && student.length > 3) { - const [_, surname, name] = student.split(","); - const names = name.split(" "); - const middlename = names.length > 1 && names[1] ? names.slice(1).join(" ") : null; - let username = surname.toLowerCase().slice(0, 6); - if (middlename) username += middlename[0].toLowerCase(); - username += names[0].toLowerCase().slice(0, 2); - const pwd = nanoid.nanoid(8); - const password = await bcrypt.hash(pwd, 12); - await this.query( - "INSERT INTO users (username, name, middlename, surname, password, class_id, type_id) VALUE (?,?,?,?,?,?,?)", - [username, names[0], middlename, surname, password, classIndex + 1, 2] - ); - } - }); - }); - }); } initValues() { |