Skip to content
Snippets Groups Projects
Commit aef5ee6e authored by alrwasheda's avatar alrwasheda :speech_balloon:
Browse files

createGodWorker renamed to createInitialWorker

parent 0a802431
No related branches found
No related tags found
No related merge requests found
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;
......@@ -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());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment