import { DataTypes, Model } from "sequelize"; import sequelize from "../database/database"; interface UserAttributes { user_id: string; store_id: string; // TODO: change to role_id role: string; account_name: string; username: string; password?: string; // can be null if user is created by store owner - password is set by user when they first login calendar_max_future_booking_days?: number; calendar_min_earliest_booking_time?: number; calendar_using_primary_calendar?: boolean; language: string; state: number; // like active, deleted, etc analytics_enabled: boolean; } class User extends Model implements UserAttributes { declare user_id: string; declare store_id: string; declare role: string; declare account_name: string; declare username: string; declare password: string; declare calendar_max_future_booking_days: number; declare calendar_min_earliest_booking_time: number; declare calendar_using_primary_calendar: boolean; declare language: string; declare state: number; declare analytics_enabled: boolean; } User.init( { // Model attributes are defined here user_id: { primaryKey: true, type: DataTypes.STRING, allowNull: false, }, store_id: { type: DataTypes.STRING, allowNull: false, }, role: { type: DataTypes.STRING, allowNull: false, }, account_name: { type: DataTypes.STRING, unique: true, }, username: { type: DataTypes.STRING, allowNull: false, }, password: { type: DataTypes.STRING, // allowNull defaults to true }, calendar_max_future_booking_days: { type: DataTypes.INTEGER, // allowNull defaults to true }, calendar_min_earliest_booking_time: { type: DataTypes.INTEGER, // allowNull defaults to true }, calendar_using_primary_calendar: { type: DataTypes.BOOLEAN, // allowNull defaults to true }, language: { type: DataTypes.STRING, allowNull: false, }, state: { type: DataTypes.INTEGER, allowNull: false, }, analytics_enabled: { type: DataTypes.BOOLEAN, allowNull: false, }, }, { tableName: "users", sequelize, // passing the `sequelize` instance is required createdAt: "created_at", updatedAt: "updated_at", } ); export default User;