Uecko_ERP/apps/server/archive/contexts/auth/infraestructure/sequelize/user.model.ts
2025-05-04 22:06:57 +02:00

56 lines
1.2 KiB
TypeScript

import { DataTypes, InferAttributes, InferCreationAttributes, Model, Sequelize } from "sequelize";
export type UserCreationAttributes = InferCreationAttributes<UserModel>;
export class UserModel extends Model<
InferAttributes<UserModel>,
InferCreationAttributes<UserModel>
> {
// To avoid table creation
/*static async sync(): Promise<any> {
return Promise.resolve();
}*/
declare id: string;
declare username: string;
declare email: string;
}
export default (sequelize: Sequelize) => {
UserModel.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
},
username: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
},
},
{
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 }],
whereMergeStrategy: "and", // <- cómo tratar el merge de un scope
defaultScope: {},
scopes: {},
}
);
return UserModel;
};