Files
Zumri-Backend/app/models/user/businessCustomer.model.js
T
Sathira Sri Sathara fd4e324571 feat: implement customer profile management and business application features
- Added customer profile controller with endpoints for retrieving, updating, and deactivating user profiles.
- Introduced address model and routes for managing user addresses.
- Created business application model and service for handling business applications, including approval and rejection processes.
- Developed business contact and credit account models to support business customer functionalities.
- Implemented settlement term model for managing payment terms.
- Added email templates for business application notifications (approved, rejected, received, and status changes).
- Enhanced validation schemas for customer and business inputs to ensure data integrity.
- Created unit tests for business application service and validation schemas to ensure functionality and correctness.
- Added migration scripts to set up new database tables and columns for customer and business features.
2026-09-03 14:58:26 +05:30

78 lines
2.2 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 },
},
{
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" });
};
return BusinessCustomer;
};