feat: Реализован полный CRUD для админ-панели и улучшена функциональность

- Portfolio CRUD: добавление, редактирование, удаление, переключение публикации
- Services CRUD: полное управление услугами с возможностью активации/деактивации
- Banner system: новая модель Banner с CRUD операциями и аналитикой кликов
- Telegram integration: расширенные настройки бота, обнаружение чатов, отправка сообщений
- Media management: улучшенная загрузка файлов с оптимизацией изображений и превью
- UI improvements: обновлённые админ-панели с rich-text редактором и drag&drop загрузкой
- Database: добавлена таблица banners с полями для баннеров и аналитики
This commit is contained in:
2025-10-22 20:32:16 +09:00
parent 150891b29d
commit 9477ff6de0
69 changed files with 11451 additions and 2321 deletions

View File

@@ -1,75 +1,78 @@
const mongoose = require('mongoose');
const { DataTypes } = require('sequelize');
const bcrypt = require('bcryptjs');
const { sequelize } = require('../config/database');
const userSchema = new mongoose.Schema({
const User = sequelize.define('User', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
email: {
type: String,
required: true,
type: DataTypes.STRING,
allowNull: false,
unique: true,
lowercase: true,
trim: true
validate: {
isEmail: true
},
set(value) {
this.setDataValue('email', value.toLowerCase().trim());
}
},
password: {
type: String,
required: true,
minlength: 6
type: DataTypes.STRING,
allowNull: false,
validate: {
len: [6, 255]
}
},
name: {
type: String,
required: true,
trim: true
type: DataTypes.STRING,
allowNull: false,
validate: {
len: [1, 100]
},
set(value) {
this.setDataValue('name', value.trim());
}
},
role: {
type: String,
enum: ['admin', 'moderator'],
default: 'admin'
type: DataTypes.ENUM('admin', 'moderator'),
defaultValue: 'admin'
},
avatar: {
type: String,
default: null
type: DataTypes.STRING,
allowNull: true
},
isActive: {
type: Boolean,
default: true
type: DataTypes.BOOLEAN,
defaultValue: true
},
lastLogin: {
type: Date,
default: null
},
createdAt: {
type: Date,
default: Date.now
},
updatedAt: {
type: Date,
default: Date.now
type: DataTypes.DATE,
allowNull: true
}
}, {
timestamps: true
});
// Hash password before saving
userSchema.pre('save', async function(next) {
if (!this.isModified('password')) return next();
try {
const salt = await bcrypt.genSalt(12);
this.password = await bcrypt.hash(this.password, salt);
next();
} catch (error) {
next(error);
tableName: 'users',
timestamps: true,
hooks: {
beforeSave: async (user) => {
if (user.changed('password')) {
const salt = await bcrypt.genSalt(12);
user.password = await bcrypt.hash(user.password, salt);
}
}
}
});
// Compare password method
userSchema.methods.comparePassword = async function(candidatePassword) {
// Instance methods
User.prototype.comparePassword = async function(candidatePassword) {
return bcrypt.compare(candidatePassword, this.password);
};
// Update last login
userSchema.methods.updateLastLogin = function() {
User.prototype.updateLastLogin = function() {
this.lastLogin = new Date();
return this.save();
};
module.exports = mongoose.model('User', userSchema);
module.exports = User;