import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize, } from "sequelize"; import { Quote_Model } from "./quote.model"; export type QuoteItemCreationAttributes = InferCreationAttributes< QuoteItem_Model, { omit: "quote" } >; export class QuoteItem_Model extends Model< InferAttributes, InferCreationAttributes > { static associate(connection: Sequelize) { const { Quote_Model, QuoteItem_Model } = connection.models; QuoteItem_Model.belongsTo(Quote_Model, { as: "quote", foreignKey: "quote_id", onDelete: "CASCADE", }); } declare quote_id: string; declare item_id: string; declare id_article: string; // number ?? declare position: number; declare description: CreationOptional; declare quantity: CreationOptional; declare unit_price: CreationOptional; declare subtotal_price: CreationOptional; declare discount: CreationOptional; declare total_price: CreationOptional; declare quote: NonAttribute; } export default (sequelize: Sequelize) => { QuoteItem_Model.init( { item_id: { type: new DataTypes.UUID(), primaryKey: true, }, quote_id: { type: new DataTypes.UUID(), primaryKey: true, }, id_article: { type: DataTypes.BIGINT().UNSIGNED, allowNull: false, }, position: { type: new DataTypes.MEDIUMINT(), autoIncrement: false, allowNull: false, }, description: { type: new DataTypes.TEXT(), allowNull: true, }, quantity: { type: DataTypes.BIGINT(), allowNull: true, }, unit_price: { type: new DataTypes.BIGINT(), allowNull: true, }, subtotal_price: { type: new DataTypes.BIGINT(), allowNull: true, }, discount: { type: DataTypes.BIGINT(), allowNull: true, }, total_price: { type: new DataTypes.BIGINT(), allowNull: true, }, }, { sequelize, tableName: "quote_items", timestamps: false, indexes: [], } ); return QuoteItem_Model; };