Presupuestador_web/server/src/contexts/sales/infrastructure/sequelize/quoteItem.model.ts

101 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-05-26 17:09:43 +00:00
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;
2024-07-09 16:21:12 +00:00
declare id_article: string; // number ??
2024-05-26 17:09:43 +00:00
declare position: number;
declare description: CreationOptional<string>;
declare quantity: CreationOptional<number>;
declare unit_price: CreationOptional<number>;
2024-07-09 16:21:12 +00:00
declare subtotal_price: CreationOptional<number>;
declare discount: CreationOptional<number>;
declare total_price: CreationOptional<number>;
2024-05-26 17:09:43 +00:00
2024-07-02 20:15:59 +00:00
declare quote: NonAttribute<Quote_Model>;
2024-05-26 17:09:43 +00:00
}
export default (sequelize: Sequelize) => {
QuoteItem_Model.init(
{
item_id: {
type: new DataTypes.UUID(),
primaryKey: true,
},
quote_id: {
type: new DataTypes.UUID(),
primaryKey: true,
},
2024-07-09 16:21:12 +00:00
id_article: {
type: DataTypes.BIGINT().UNSIGNED,
allowNull: false,
},
2024-05-26 17:09:43 +00:00
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,
},
2024-07-09 16:21:12 +00:00
subtotal_price: {
2024-05-26 17:09:43 +00:00
type: new DataTypes.BIGINT(),
allowNull: true,
},
2024-07-09 16:21:12 +00:00
discount: {
type: DataTypes.BIGINT(),
allowNull: true,
},
total_price: {
2024-05-26 17:09:43 +00:00
type: new DataTypes.BIGINT(),
allowNull: true,
},
},
{
sequelize,
tableName: "quote_items",
timestamps: false,
indexes: [],
}
);
return QuoteItem_Model;
};