fd4e324571
- 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.
97 lines
2.5 KiB
JavaScript
97 lines
2.5 KiB
JavaScript
/**
|
|
* Copyright (c) 2026 Niolla
|
|
* All rights reserved.
|
|
*
|
|
* This source code is proprietary and confidential.
|
|
* Unauthorized copying, modification, distribution, or use
|
|
* of this file, via any medium, is strictly prohibited.
|
|
*/
|
|
|
|
// app/models/User.model.js
|
|
|
|
module.exports = (sequelize, DataTypes) => {
|
|
const User = sequelize.define(
|
|
"User",
|
|
{
|
|
id: {
|
|
type: DataTypes.STRING,
|
|
primaryKey: true,
|
|
collate: "utf8mb4_general_ci",
|
|
},
|
|
firstName: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
lastName: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
email: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
unique: true,
|
|
},
|
|
password: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
},
|
|
accountType: {
|
|
type: DataTypes.ENUM("superadmin", "admin", "manager", "business_customer", "rider", "customer", "support_agent"),
|
|
defaultValue: "customer",
|
|
},
|
|
accountStatus: {
|
|
type: DataTypes.ENUM(
|
|
"PENDING_VERIFICATION",
|
|
"ACTIVE",
|
|
"SUSPENDED",
|
|
"DEACTIVATED",
|
|
),
|
|
allowNull: false,
|
|
defaultValue: "PENDING_VERIFICATION",
|
|
},
|
|
emailVerifiedAt: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
passwordChangedAt: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
defaultValue: null,
|
|
},
|
|
tokenVersion: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 },
|
|
lastLoginAt: { type: DataTypes.DATE, allowNull: true },
|
|
},
|
|
{
|
|
tableName: "users",
|
|
timestamps: true,
|
|
},
|
|
);
|
|
|
|
User.associate = (db) => {
|
|
User.hasMany(db.userPermission, {
|
|
foreignKey: "user_id",
|
|
as: "userPermissions",
|
|
});
|
|
User.hasOne(db.Profile, {
|
|
foreignKey: "user_id",
|
|
as: "profile",
|
|
});
|
|
User.hasOne(db.Customer, {
|
|
foreignKey: "user_id",
|
|
as: "customer",
|
|
});
|
|
User.hasOne(db.BusinessCustomer, {
|
|
foreignKey: "user_id",
|
|
as: "businessCustomer",
|
|
});
|
|
User.hasMany(db.AuthSession, { foreignKey: "user_id", as: "authSessions" });
|
|
User.hasMany(db.UserIdentity, { foreignKey: "user_id", as: "identities" });
|
|
User.hasMany(db.UserRole, { foreignKey: "user_id", as: "userRoles" });
|
|
User.hasMany(db.Address, { foreignKey: "user_id", as: "addresses" });
|
|
User.hasMany(db.BusinessApplication, { foreignKey: "user_id", as: "businessApplications" });
|
|
};
|
|
|
|
return User;
|
|
};
|