Files
Zumri-Backend/app/models/user/businessCustomer.model.js
T
Sathira Sri Sathara 5643d89236 feat: implement business pricing service and money utilities
- Added `businessPricing.service.js` to handle business customer pricing logic.
- Introduced `money.js` for money parsing, formatting, and calculations.
- Created `pricing.service.js` to manage variant quoting and promotion application.
- Updated validation schemas in `catalogue.schemas.js` and `inventoryMerchandising.schemas.js` for new pricing and inventory features.
- Implemented cron job for inventory reservation expiry in `inventoryReservationExpiry.cron.js`.
- Created database migrations for catalogue and inventory structures.
- Added unit tests for catalogue localization, validation, and inventory merchandising functionalities.
2026-09-03 19:25:13 +05:30

80 lines
2.4 KiB
JavaScript

//app/models/user/businessCustomer.model.js
module.exports = (sequelize, DataTypes) => {
const BusinessCustomer = sequelize.define(
"BusinessCustomer",
{
business_customer_id: {
type: DataTypes.STRING,
primaryKey: true,
},
user_id: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
businessName: {
type: DataTypes.STRING,
allowNull: false,
},
businessRegistrationNumber: {
type: DataTypes.STRING,
allowNull: false, unique: true,
},
businessType: {
type: DataTypes.STRING,
allowNull: false,
},
contactName: {
type: DataTypes.STRING,
allowNull: false,
},
phoneNumber: {
type: DataTypes.STRING,
allowNull: false,
},
businessEmail: {
type: DataTypes.STRING,
allowNull: false,
},
expectedMonthlyVolume: {
type: DataTypes.STRING,
allowNull: false,
},
note: {
type: DataTypes.STRING,
allowNull: true,
},
legalName: DataTypes.STRING,
taxNumber: DataTypes.STRING,
website: DataTypes.STRING,
partnerId: { type: DataTypes.STRING, allowNull: false, unique: true },
status: { type: DataTypes.ENUM("ACTIVE", "SUSPENDED", "CLOSED"), allowNull: false, defaultValue: "ACTIVE" },
approvedAt: { type: DataTypes.DATE, allowNull: false },
approvedBy: { type: DataTypes.STRING, allowNull: false },
settlement_term_id: { type: DataTypes.STRING, allowNull: true },
business_tier_id: { type: DataTypes.STRING, allowNull: true },
},
{
tableName: "business_customers",
timestamps: true,
},
);
BusinessCustomer.associate = (db) => {
BusinessCustomer.belongsTo(db.User, {
foreignKey: "user_id",
as: "user",
});
BusinessCustomer.hasMany(db.BusinessContact, { foreignKey: "business_profile_id", as: "contacts" });
BusinessCustomer.hasMany(db.Address, { foreignKey: "business_profile_id", as: "addresses" });
BusinessCustomer.hasOne(db.BusinessCreditAccount, { foreignKey: "business_profile_id", as: "creditAccount" });
BusinessCustomer.belongsTo(db.SettlementTerm, { foreignKey: "settlement_term_id", as: "settlementTerm" });
BusinessCustomer.belongsTo(db.BusinessTier, { foreignKey: "business_tier_id", as: "businessTier" });
};
return BusinessCustomer;
};