91 lines
2.1 KiB
JavaScript
91 lines
2.1 KiB
JavaScript
module.exports = (sequelize, DataTypes) => {
|
|
const Product = sequelize.define("products", {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
autoIncrement: true,
|
|
primaryKey: true,
|
|
},
|
|
product_name: {
|
|
type: DataTypes.STRING(1000),
|
|
allowNull: false,
|
|
unique: true,
|
|
validate: {
|
|
len: {
|
|
args: [1, 1000],
|
|
msg: "Product Name is too long. Maximum allowed length is 1000 characters."
|
|
}}
|
|
},
|
|
hs_code: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
unique: true,
|
|
validate: {
|
|
len: {
|
|
args: [0, 10],
|
|
msg: "Invalid HS Code: maximum length is 10 digits."
|
|
}}
|
|
},
|
|
hs_description: {
|
|
type: DataTypes.STRING(1000),
|
|
allowNull: true,
|
|
validate: {
|
|
len: {
|
|
args: [0, 1000],
|
|
msg: "HS Description is too long. Maximum allowed length is 1000 characters."
|
|
}}
|
|
},
|
|
unit_id: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
},
|
|
weight_in_ib: {
|
|
type: DataTypes.DECIMAL(18, 10),
|
|
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;
|
|
};
|
|
|