english version update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { prisma } from '../../prisma/client';
|
||||
import { createNotification } from '../notification/notification.controller';
|
||||
import { sendNotificationEmail } from '../notification/email.service';
|
||||
|
||||
function toNumeric(value: unknown): number {
|
||||
if (typeof value === 'bigint') {
|
||||
@@ -514,23 +515,50 @@ export class AdminController {
|
||||
return res.status(404).json({ error: 'Пользователь не найден' });
|
||||
}
|
||||
|
||||
if (!user.email) {
|
||||
return res.status(400).json({ error: 'У пользователя не указан email' });
|
||||
}
|
||||
|
||||
const now = new Date().toISOString();
|
||||
const logMsg = `[Admin] EMAIL-TEST | userId=${user.id} | username=${user.username} | email=${user.email} | time=${now}`;
|
||||
console.log(logMsg);
|
||||
|
||||
// Здесь должна быть реальная отправка email (имитация)
|
||||
await new Promise(resolve => setTimeout(resolve, 800));
|
||||
// Отправляем реальное email уведомление
|
||||
const emailResult = await sendNotificationEmail({
|
||||
to: user.email,
|
||||
username: user.username,
|
||||
title: 'Тестовое уведомление',
|
||||
message: 'Это тестовое email-уведомление от ospab.host. Если вы получили это письмо, email-уведомления настроены корректно.',
|
||||
actionUrl: '/dashboard/notifications',
|
||||
type: 'test_email'
|
||||
});
|
||||
|
||||
if (emailResult.status === 'error') {
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
error: `Ошибка отправки email: ${emailResult.message}`,
|
||||
details: { userId: user.id, email: user.email, time: now }
|
||||
});
|
||||
}
|
||||
|
||||
if (emailResult.status === 'skipped') {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: 'SMTP не настроен. Укажите SMTP_USER и SMTP_PASS в переменных окружения.',
|
||||
details: { userId: user.id, email: user.email, time: now }
|
||||
});
|
||||
}
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
message: 'Email-уведомление успешно отправлено (тест)',
|
||||
message: 'Email-уведомление успешно отправлено',
|
||||
details: {
|
||||
userId: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
type: 'email',
|
||||
time: now,
|
||||
status: 'sent (mock)'
|
||||
messageId: 'messageId' in emailResult ? emailResult.messageId : undefined
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user