146 lines
3.8 KiB
TypeScript
146 lines
3.8 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; // 0 trailing, 1 basic
|
|
payment_plan_interval?: number; // how often the payment plan is charged (e.g. 0 monthly, 1 yearly)
|
|
payment_plan_trial_end?: Date; // when the payment plan trial ends
|
|
payment_plan_cancel_at?: Date; // when the payment plan will be canceled (e.g. after trial)
|
|
payment_plan_canceled_at?: Date; // when the payment plan was canceled
|
|
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_interval: number;
|
|
declare payment_plan_trial_end: Date;
|
|
declare payment_plan_cancel_at: Date;
|
|
declare payment_plan_canceled_at: Date;
|
|
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_interval: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
},
|
|
payment_plan_trial_end: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
},
|
|
payment_plan_cancel_at: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
},
|
|
payment_plan_canceled_at: {
|
|
type: DataTypes.DATE,
|
|
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;
|