Major Features: - Authentication & Authorization with JWT and role-based access - Complete User Management System with CRUD operations - Course Management System with publishing and enrollment - Modern React UI with Tailwind CSS and responsive design - Internationalization (i18n) with English and Arabic support - File Upload System for images and documents - RESTful API with Express.js and Sequelize ORM - PostgreSQL database with proper relationships - Super Admin password change functionality - CSV import for bulk user creation - Modal-based user add/edit operations - Search, filter, and pagination capabilities Technical Improvements: - Fixed homepage routing and accessibility issues - Resolved API endpoint mismatches and data rendering - Enhanced security with proper validation and hashing - Optimized performance with React Query and caching - Improved error handling and user feedback - Clean code structure with ESLint compliance Bug Fixes: - Fixed non-functional Add/Edit/Delete buttons - Resolved CSV import BOM issues - Fixed modal rendering and accessibility - Corrected API base URL configuration - Enhanced backend stability and error handling This version represents a complete, production-ready Course Management System.
93 lines
No EOL
1.9 KiB
JavaScript
93 lines
No EOL
1.9 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const bcrypt = require('bcryptjs');
|
|
const { sequelize } = require('../config/database');
|
|
|
|
const User = sequelize.define('User', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true
|
|
},
|
|
firstName: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
validate: {
|
|
notEmpty: true,
|
|
len: [2, 50]
|
|
}
|
|
},
|
|
lastName: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
validate: {
|
|
notEmpty: true,
|
|
len: [2, 50]
|
|
}
|
|
},
|
|
email: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
unique: true,
|
|
validate: {
|
|
isEmail: true
|
|
}
|
|
},
|
|
password: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
validate: {
|
|
len: [6, 100]
|
|
}
|
|
},
|
|
role: {
|
|
type: DataTypes.ENUM('super_admin', 'trainer', 'trainee'),
|
|
allowNull: false,
|
|
defaultValue: 'trainee'
|
|
},
|
|
phone: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
avatar: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
isActive: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: true
|
|
},
|
|
lastLogin: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true
|
|
},
|
|
requiresPasswordChange: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: false
|
|
}
|
|
}, {
|
|
tableName: 'users',
|
|
hooks: {
|
|
beforeCreate: async (user) => {
|
|
if (user.password) {
|
|
user.password = await bcrypt.hash(user.password, 12);
|
|
}
|
|
},
|
|
beforeUpdate: async (user) => {
|
|
if (user.changed('password')) {
|
|
user.password = await bcrypt.hash(user.password, 12);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// Instance method to compare password
|
|
User.prototype.comparePassword = async function(candidatePassword) {
|
|
return await bcrypt.compare(candidatePassword, this.password);
|
|
};
|
|
|
|
// Instance method to get full name
|
|
User.prototype.getFullName = function() {
|
|
return `${this.firstName} ${this.lastName}`;
|
|
};
|
|
|
|
module.exports = User;
|