Uecko_ERP/apps/server/src/contexts/auth/infraestructure/sequelize/auth-user.model.ts

63 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-01-30 10:45:31 +00:00
import { DataTypes, InferAttributes, InferCreationAttributes, Model } from "sequelize";
import { sequelize } from "../../../../config/database";
export type AuthUserCreationAttributes = InferCreationAttributes<AuthUserModel>;
class AuthUserModel extends Model<
InferAttributes<AuthUserModel>,
InferCreationAttributes<AuthUserModel>
> {
public id!: string;
public username!: string;
public email!: string;
public password!: string;
public roles!: string[];
public 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.ARRAY(DataTypes.STRING),
allowNull: false,
defaultValue: [],
},
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 };