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

@@ -2,14 +2,8 @@ const express = require('express');
const router = express.Router();
const { body, validationResult } = require('express-validator');
const nodemailer = require('nodemailer');
const Contact = require('../models/Contact');
const TelegramBot = require('node-telegram-bot-api');
// Initialize Telegram bot if token is provided
let bot = null;
if (process.env.TELEGRAM_BOT_TOKEN) {
bot = new TelegramBot(process.env.TELEGRAM_BOT_TOKEN, { polling: false });
}
const { Contact } = require('../models');
const telegramService = require('../services/telegram');
// Contact form validation
const contactValidation = [
@@ -48,7 +42,7 @@ router.post('/submit', contactValidation, async (req, res) => {
await sendEmailNotification(contact);
// Send Telegram notification
await sendTelegramNotification(contact);
await telegramService.sendNewContactAlert(contact);
res.json({
success: true,
@@ -108,7 +102,10 @@ router.post('/estimate', [
// Send notifications
await sendEmailNotification(contact);
await sendTelegramNotification(contact);
await telegramService.sendCalculatorQuote({
...contactData,
services: services.map(s => ({ name: s, price: 0 })) // Simplified for now
});
res.json({
success: true,
@@ -170,42 +167,7 @@ async function sendEmailNotification(contact) {
}
}
// Helper function to send Telegram notification
async function sendTelegramNotification(contact) {
if (!bot || !process.env.TELEGRAM_CHAT_ID) {
console.log('Telegram configuration not provided, skipping Telegram notification');
return;
}
try {
const message = `
🔔 *New Contact Form Submission*
👤 *Name:* ${contact.name}
📧 *Email:* ${contact.email}
📱 *Phone:* ${contact.phone || 'Not provided'}
🏢 *Company:* ${contact.company || 'Not provided'}
📝 *Subject:* ${contact.subject}
💬 *Message:*
${contact.message}
📍 *Source:* ${contact.source}
🕐 *Time:* ${contact.createdAt.toLocaleString()}
[View in Admin Panel](${process.env.SITE_URL}/admin/contacts/${contact._id})
`;
await bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message, {
parse_mode: 'Markdown',
disable_web_page_preview: true
});
console.log('Telegram notification sent successfully');
} catch (error) {
console.error('Telegram notification error:', error);
}
}
// Telegram notifications now handled by telegramService
// Helper function to calculate project estimate
function calculateProjectEstimate(services, projectType, timeline) {