module.exports = (sequelize, DataTypes) => { const Product = sequelize.define("products", { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, product_name: { type: DataTypes.STRING, allowNull: false, unique: true, }, hs_code: { type: DataTypes.INTEGER, allowNull: true, unique: true, }, hs_description: { type: DataTypes.TEXT, allowNull: true, }, unit_id: { type: DataTypes.INTEGER, allowNull: true, }, is_active: { type: DataTypes.BOOLEAN, defaultValue: true, }, created_at: { type: DataTypes.DATE, defaultValue: DataTypes.NOW, }, created_by: { type: DataTypes.INTEGER, allowNull: false, }, updated_at: { type: DataTypes.DATE, allowNull: true, }, updated_by: { type: DataTypes.INTEGER, allowNull: true, }, }, { tableName: "products", timestamps: false, }); Product.associate = (models) => { Product.hasMany(models.EstablishmentProduct, { foreignKey: "product_id", as: "establishment_products", }); Product.hasMany(models.SubmissionProduct, { foreignKey: "product_id", as: "submission_products", }); Product.belongsTo(models.UnitMaster, { foreignKey: "unit_id", as: "unit", }); }; return Product; };