customer-dashboard-api/src/models/user.ts

140 lines
3.5 KiB
TypeScript

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;
email: 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
google_account_name?: string;
google_account_picture?: string;
analytics_enabled: boolean;
payment_plan: number;
payment_plan_status?: string;
payment_plan_trial_end?: number;
payment_plan_canceled_at?: number;
stripe_customer_id?: string;
}
class User extends Model<UserAttributes> implements UserAttributes {
declare user_id: string;
declare store_id: string;
declare role: string;
declare email: 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 google_account_name: string;
declare google_account_picture: string;
declare analytics_enabled: boolean;
declare payment_plan: number;
declare payment_plan_status: string;
declare payment_plan_trial_end: number;
declare payment_plan_canceled_at: number;
declare stripe_customer_id: string;
declare created_at: Date;
}
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,
},
email: {
type: DataTypes.STRING,
// allowNull defaults to 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,
},
google_account_name: {
type: DataTypes.STRING,
allowNull: true,
},
google_account_picture: {
type: DataTypes.STRING(1050),
allowNull: true,
},
analytics_enabled: {
type: DataTypes.BOOLEAN,
allowNull: false,
},
payment_plan: {
type: DataTypes.TINYINT,
allowNull: false,
},
payment_plan_status: {
type: DataTypes.STRING,
allowNull: true,
},
payment_plan_trial_end: {
type: DataTypes.INTEGER,
allowNull: true,
},
payment_plan_canceled_at: {
type: DataTypes.INTEGER,
allowNull: true,
},
stripe_customer_id: {
type: DataTypes.STRING,
allowNull: true,
},
},
{
tableName: "users",
sequelize, // passing the `sequelize` instance is required
createdAt: "created_at",
updatedAt: "updated_at",
}
);
export default User;