import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize, } from "sequelize"; import { QuoteItem_Model } from "./quoteItem.model"; export type QuoteCreationAttributes = InferCreationAttributes; export class Quote_Model extends Model< InferAttributes, InferCreationAttributes > { static associate(connection: Sequelize) { const { Quote_Model, QuoteItem_Model, Dealer_Model } = connection.models; Quote_Model.hasMany(QuoteItem_Model, { as: "items", foreignKey: "quote_id", onDelete: "CASCADE", }); Quote_Model.belongsTo(Dealer_Model, { as: "dealer", foreignKey: "dealer_id", onDelete: "RESTRICT", }); } declare id: string; declare status: string; declare date: CreationOptional; declare language_code: string; declare currency_code: string; declare subtotal: number; declare total: number; declare items: NonAttribute; } export default (sequelize: Sequelize) => { Quote_Model.init( { id: { type: new DataTypes.UUID(), primaryKey: true, }, status: { type: new DataTypes.STRING(), allowNull: false, }, date: { type: new DataTypes.DATE(), allowNull: false, }, language_code: { type: new DataTypes.STRING(), allowNull: false, }, currency_code: { type: new DataTypes.STRING(), allowNull: false, }, subtotal: { type: new DataTypes.BIGINT(), allowNull: true, }, total: { type: new DataTypes.BIGINT(), allowNull: true, }, }, { sequelize, tableName: "quotes", paranoid: true, // softs deletes timestamps: true, //version: true, createdAt: "created_at", updatedAt: "updated_at", deletedAt: "deleted_at", indexes: [ { name: "status_idx", fields: ["status"] }, { name: "deleted_at_idx", fields: ["deleted_at"] }, ], } ); return Quote_Model; };