import { DataTypes, InferAttributes, InferCreationAttributes, Model, Op, Sequelize, } from "sequelize"; export type TCreationUser_Attributes = InferCreationAttributes; export class User_Model extends Model< InferAttributes, InferCreationAttributes > { // To avoid table creation /*static async sync(): Promise { return Promise.resolve(); }*/ static associate(connection: Sequelize) {} declare id: string; declare name: string; declare email: string; declare password: string; } export default (sequelize: Sequelize) => { User_Model.init( { id: { type: new DataTypes.UUID(), primaryKey: true, }, name: { type: DataTypes.STRING, }, email: { type: DataTypes.STRING, allowNull: false, }, password: { type: DataTypes.STRING, allowNull: false, }, }, { sequelize, tableName: "users", paranoid: true, // softs deletes timestamps: true, //version: true, createdAt: "created_at", updatedAt: "updated_at", deletedAt: "deleted_at", indexes: [{ name: "email_idx", fields: ["email"] }], whereMergeStrategy: "and", // <- cómo tratar el merge de un scope scopes: { quickSearch(value) { return { where: { [Op.or]: { name: { [Op.like]: `%${value}%`, }, email: { [Op.like]: `%${value}%`, }, }, }, }; }, }, }, ); return User_Model; };