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

name changed -> deleted

parent 006036d8
No related branches found
No related tags found
No related merge requests found
import bcrypt from "bcrypt";
import envVars from "../config";
import Worker from "./models/Worker";
const createInitialWorkerIfNotExists = async () => {
const numberOfWorkers = await Worker.count();
if (numberOfWorkers === 0) {
const initialCoordinatorPassword = envVars.INITIAL_COORDINATOR_PASSWORD;
const initialCoordinatorEmail = envVars.INITIAL_COORDINATOR_EMAIL;
const hashedPassword = await bcrypt.hash(initialCoordinatorPassword, 10);
await Worker.create({
email: initialCoordinatorEmail,
password: hashedPassword,
first_name: "coordinator_firstName",
last_name: "coordinator_lastName",
role: "coordinator",
});
}
};
export default createInitialWorkerIfNotExists;
import { DataTypes, Model, Optional, Sequelize } from "sequelize";
interface WorkerAttributes {
id: string;
email: string;
first_name: string;
last_name: string;
password: string;
role: string;
}
export interface WorkerInput extends Optional<WorkerAttributes, "id"> {}
class Worker
extends Model<WorkerAttributes, WorkerInput>
implements WorkerAttributes
{
declare id: string;
declare email: string;
declare first_name: string;
declare last_name: string;
declare password: string;
declare role: string;
declare readonly createdAt: Date;
declare readonly updatedAt: Date;
}
export const initWorker = async (sequelizeConnection: Sequelize) => {
Worker.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false,
},
email: {
type: new DataTypes.STRING(),
allowNull: false,
unique: true,
},
first_name: {
type: new DataTypes.STRING(),
allowNull: false,
},
last_name: {
type: new DataTypes.STRING(),
allowNull: false,
},
password: {
type: new DataTypes.STRING(),
allowNull: false,
},
role: {
type: new DataTypes.STRING(),
allowNull: false,
},
},
{
tableName: "worker",
sequelize: sequelizeConnection,
}
);
};
export default Worker;
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