From aef5ee6eef82ea153a300104ea946556c7b94931 Mon Sep 17 00:00:00 2001 From: Hanen Alrwasheda <alrwasheda@mi.fu-berlin.de> Date: Mon, 13 Dec 2021 01:20:27 +0100 Subject: [PATCH] createGodWorker renamed to createInitialWorker --- .../db/{createGodWorker.ts => createInitialWorker.ts} | 9 +++++---- server/src/server.ts | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) rename server/src/db/{createGodWorker.ts => createInitialWorker.ts} (59%) diff --git a/server/src/db/createGodWorker.ts b/server/src/db/createInitialWorker.ts similarity index 59% rename from server/src/db/createGodWorker.ts rename to server/src/db/createInitialWorker.ts index 8ad0ea1..9e7461e 100644 --- a/server/src/db/createGodWorker.ts +++ b/server/src/db/createInitialWorker.ts @@ -1,17 +1,18 @@ import bcrypt from "bcrypt"; import Worker from "./models/Worker"; -const createGodWorker = async () => { - //inserting initial worker(coordinator), only if table stills empty and has not GOD-Worker. Otherwise it will try to create new worker by each server-run, which will result in having errors(e.g. duplicate primary key) +const createInitialWorkerIfNotExists = async () => { + //inserting initial-worker(coordinator), only if table stills empty and has no initial-Worker. Otherwise it will try to create new worker by each server-run, which will result in having errors(e.g. duplicate primary key) const tableEmpty = await Worker.findAll(); if (tableEmpty.length === 0) { //password as plain text const plainTextPassword = "coordinator_password"; - //create hashed-password and store worker-data into DB + //create hashed-password const saltRounds = 10; const hashedPassword = await bcrypt.hash(plainTextPassword, saltRounds); + //store initital-worker-data into DB await Worker.create({ email: "coordinator_email@email-provider.com", password: hashedPassword, @@ -21,4 +22,4 @@ const createGodWorker = async () => { }); } }; -export default createGodWorker; +export default createInitialWorkerIfNotExists; diff --git a/server/src/server.ts b/server/src/server.ts index 40cef8c..8f77b3d 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -7,12 +7,12 @@ import initializeDatabase from "./db"; // import apiRouter from "./routes"; import sendMail from "./mail"; import router from "./routes"; -import createGodWorker from "./db/createGodWorker"; +import createInitialWorkerIfNotExists from "./db/createInitialWorker"; let init = async () => { //DB const sequelize = await initializeDatabase(); - await createGodWorker(); + await createInitialWorkerIfNotExists(); // server const app = express(); app.use(express.json()); -- GitLab