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,107 +1,121 @@
const mongoose = require('mongoose');
const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const portfolioSchema = new mongoose.Schema({
const Portfolio = sequelize.define('Portfolio', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
title: {
type: String,
required: true,
trim: true
type: DataTypes.STRING,
allowNull: false,
validate: {
len: [1, 255]
},
set(value) {
this.setDataValue('title', value.trim());
}
},
description: {
type: String,
required: true
type: DataTypes.TEXT,
allowNull: false
},
shortDescription: {
type: String,
required: true,
maxlength: 200
type: DataTypes.STRING(200),
allowNull: false
},
category: {
type: String,
required: true,
enum: ['web-development', 'mobile-app', 'ui-ux-design', 'branding', 'e-commerce', 'other']
type: DataTypes.ENUM('web-development', 'mobile-app', 'ui-ux-design', 'branding', 'e-commerce', 'other'),
allowNull: false
},
technologies: {
type: DataTypes.ARRAY(DataTypes.STRING),
defaultValue: []
},
images: {
type: DataTypes.JSONB,
defaultValue: []
},
technologies: [{
type: String,
trim: true
}],
images: [{
url: {
type: String,
required: true
},
alt: {
type: String,
default: ''
},
isPrimary: {
type: Boolean,
default: false
}
}],
clientName: {
type: String,
trim: true
type: DataTypes.STRING,
allowNull: true,
set(value) {
this.setDataValue('clientName', value ? value.trim() : null);
}
},
projectUrl: {
type: String,
trim: true
type: DataTypes.STRING,
allowNull: true,
validate: {
isUrl: true
}
},
githubUrl: {
type: String,
trim: true
type: DataTypes.STRING,
allowNull: true,
validate: {
isUrl: true
}
},
status: {
type: String,
enum: ['completed', 'in-progress', 'planning'],
default: 'completed'
type: DataTypes.ENUM('completed', 'in-progress', 'planning'),
defaultValue: 'completed'
},
featured: {
type: Boolean,
default: false
type: DataTypes.BOOLEAN,
defaultValue: false
},
publishedAt: {
type: Date,
default: Date.now
type: DataTypes.DATE,
defaultValue: DataTypes.NOW
},
completedAt: {
type: Date
type: DataTypes.DATE,
allowNull: true
},
isPublished: {
type: Boolean,
default: true
type: DataTypes.BOOLEAN,
defaultValue: true
},
viewCount: {
type: Number,
default: 0
type: DataTypes.INTEGER,
defaultValue: 0
},
likes: {
type: Number,
default: 0
type: DataTypes.INTEGER,
defaultValue: 0
},
order: {
type: Number,
default: 0
type: DataTypes.INTEGER,
defaultValue: 0
},
seo: {
metaTitle: String,
metaDescription: String,
keywords: [String]
type: DataTypes.JSONB,
defaultValue: {}
}
}, {
timestamps: true
tableName: 'portfolios',
timestamps: true,
indexes: [
{
fields: ['category', 'publishedAt']
},
{
fields: ['featured', 'publishedAt']
},
{
type: 'gin',
fields: ['technologies']
}
]
});
// Index for search and sorting
portfolioSchema.index({ title: 'text', description: 'text', technologies: 'text' });
portfolioSchema.index({ category: 1, publishedAt: -1 });
portfolioSchema.index({ featured: -1, publishedAt: -1 });
// Virtual for primary image
portfolioSchema.virtual('primaryImage').get(function() {
Portfolio.prototype.getPrimaryImage = function() {
if (!this.images || this.images.length === 0) return null;
const primary = this.images.find(img => img.isPrimary);
return primary || (this.images.length > 0 ? this.images[0] : null);
});
return primary || this.images[0];
};
portfolioSchema.set('toJSON', { virtuals: true });
module.exports = mongoose.model('Portfolio', portfolioSchema);
module.exports = Portfolio;