import { sequelize } from "@config/database"; import { DataTypes, InferAttributes, InferCreationAttributes, Model } from "sequelize"; export type AuthUserCreationAttributes = InferCreationAttributes; class AuthUserModel extends Model< InferAttributes, InferCreationAttributes > { declare id: string; declare username: string; declare email: string; declare password: string; declare roles: string[]; declare isActive: boolean; } AuthUserModel.init( { id: { type: DataTypes.UUID, primaryKey: true, allowNull: false, }, username: { type: DataTypes.STRING, allowNull: false, }, email: { type: DataTypes.STRING, allowNull: false, unique: true, }, password: { type: DataTypes.STRING, allowNull: false, }, roles: { type: DataTypes.STRING, allowNull: false, defaultValue: "USER", get(this: AuthUserModel): string[] { const rawValue = this.getDataValue("roles") as any; return String(rawValue).split(";"); }, set(this: AuthUserModel, value: string[]) { const rawValue = value.join(";") as any; this.setDataValue("roles", rawValue); }, }, isActive: { type: DataTypes.BOOLEAN, defaultValue: true, }, }, { sequelize, tableName: "users", paranoid: true, // softs deletes timestamps: true, createdAt: "created_at", updatedAt: "updated_at", deletedAt: "deleted_at", indexes: [{ name: "email_idx", fields: ["email"], unique: true }], } ); export { AuthUserModel };