import { DataTypes, InferAttributes, InferCreationAttributes, Model, Sequelize } from "sequelize"; export type CustomerCreationAttributes = InferCreationAttributes & {}; export class CustomerModel extends Model< InferAttributes, InferCreationAttributes > { // To avoid table creation /*static async sync(): Promise { return Promise.resolve(); }*/ declare id: string; declare company_id: string; declare reference: string; declare is_company: boolean; declare name: string; declare trade_name: string; declare tin: string; declare street: string; declare street2: string; declare city: string; declare state: string; declare postal_code: string; declare country: string; declare email: string; declare phone: string; declare fax: string; declare website: string; declare legal_record: string; declare default_tax: string; declare status: string; declare lang_code: string; declare currency_code: string; static associate(database: Sequelize) {} static hooks(database: Sequelize) {} } export default (database: Sequelize) => { CustomerModel.init( { id: { type: DataTypes.UUID, primaryKey: true, }, company_id: { type: DataTypes.UUID, allowNull: false, }, reference: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, is_company: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, name: { type: DataTypes.STRING, allowNull: false, }, trade_name: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, tin: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, street: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, street2: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, city: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, state: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, postal_code: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, country: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, email: { type: DataTypes.STRING, allowNull: false, defaultValue: "", validate: { isEmail: true, }, }, phone: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, fax: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, website: { type: DataTypes.STRING, allowNull: false, defaultValue: "", validate: { isUrl: true, }, }, legal_record: { type: DataTypes.TEXT, allowNull: false, defaultValue: "", }, default_tax: { type: DataTypes.STRING, allowNull: false, defaultValue: "", }, lang_code: { type: DataTypes.STRING(2), allowNull: false, defaultValue: "es", }, currency_code: { type: new DataTypes.STRING(3), allowNull: false, defaultValue: "EUR", }, status: { type: DataTypes.STRING, allowNull: false, defaultValue: "active", }, }, { sequelize: database, tableName: "customers", paranoid: true, // softs deletes timestamps: true, createdAt: "created_at", updatedAt: "updated_at", deletedAt: "deleted_at", indexes: [ { name: "company_idx", fields: ["company_id"], unique: false }, { name: "email_idx", fields: ["email"], unique: true }, ], whereMergeStrategy: "and", // <- cómo tratar el merge de un scope defaultScope: {}, scopes: {}, } ); return CustomerModel; };