Presupuestador_web/server/src/contexts/sales/infrastructure/sequelize/quoteItem.model.ts
2024-07-09 18:21:12 +02:00

101 lines
2.3 KiB
TypeScript

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<QuoteItem_Model, { omit: "quote" }>,
InferCreationAttributes<QuoteItem_Model, { omit: "quote" }>
> {
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<string>;
declare quantity: CreationOptional<number>;
declare unit_price: CreationOptional<number>;
declare subtotal_price: CreationOptional<number>;
declare discount: CreationOptional<number>;
declare total_price: CreationOptional<number>;
declare quote: NonAttribute<Quote_Model>;
}
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;
};