172 lines
3.5 KiB
TypeScript
172 lines
3.5 KiB
TypeScript
import {
|
|
CreationOptional,
|
|
DataTypes,
|
|
InferAttributes,
|
|
InferCreationAttributes,
|
|
Model,
|
|
Sequelize,
|
|
} from "sequelize";
|
|
|
|
export type AccountCreationAttributes = InferCreationAttributes<AccountModel, {}> & {};
|
|
|
|
export class AccountModel extends Model<InferAttributes<AccountModel>, AccountCreationAttributes> {
|
|
// To avoid table creation
|
|
/*static async sync(): Promise<any> {
|
|
return Promise.resolve();
|
|
}*/
|
|
|
|
declare id: string;
|
|
|
|
declare is_freelancer: boolean;
|
|
declare name: string;
|
|
declare trade_name: CreationOptional<string>;
|
|
declare tin: string;
|
|
|
|
declare street: string;
|
|
declare city: string;
|
|
declare state: string;
|
|
declare postal_code: string;
|
|
declare country: string;
|
|
|
|
declare email: string;
|
|
declare phone: string;
|
|
declare fax: CreationOptional<string>;
|
|
declare website: CreationOptional<string>;
|
|
|
|
declare legal_record: string;
|
|
|
|
declare default_tax: number;
|
|
declare status: string;
|
|
declare lang_code: string;
|
|
declare currency_code: string;
|
|
declare logo: CreationOptional<string>;
|
|
}
|
|
|
|
export default (sequelize: Sequelize) => {
|
|
AccountModel.init(
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
primaryKey: true,
|
|
},
|
|
is_freelancer: {
|
|
type: DataTypes.BOOLEAN,
|
|
allowNull: false,
|
|
},
|
|
name: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
trade_name: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
tin: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
|
|
street: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
city: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
state: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
postal_code: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
country: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
|
|
email: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
validate: {
|
|
isEmail: true,
|
|
},
|
|
},
|
|
phone: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
fax: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
website: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
validate: {
|
|
isUrl: true,
|
|
},
|
|
},
|
|
legal_record: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: false,
|
|
},
|
|
|
|
default_tax: {
|
|
type: new DataTypes.SMALLINT(),
|
|
allowNull: false,
|
|
defaultValue: 2100,
|
|
},
|
|
|
|
logo: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
|
|
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,
|
|
tableName: "accounts",
|
|
|
|
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 AccountModel;
|
|
};
|