чистка PG
This commit is contained in:
103
notifications.js
103
notifications.js
@@ -1,5 +1,4 @@
|
||||
// notifications.js
|
||||
const postgresLogger = require('./postgres');
|
||||
const { getDb } = require('./database');
|
||||
const emailNotifications = require('./email-notifications');
|
||||
|
||||
@@ -86,24 +85,6 @@ async function sendTaskNotifications(type, taskId, taskTitle, taskDescription, a
|
||||
}
|
||||
}
|
||||
|
||||
// Логируем в PostgreSQL (если настроено)
|
||||
let postgresLogIds = [];
|
||||
if (postgresLogger.initialized) {
|
||||
postgresLogIds = await logNotificationToPostgres({
|
||||
type,
|
||||
taskId,
|
||||
taskTitle,
|
||||
taskDescription,
|
||||
authorId,
|
||||
authorName,
|
||||
authorLogin,
|
||||
recipients,
|
||||
comment,
|
||||
status,
|
||||
userName
|
||||
});
|
||||
}
|
||||
|
||||
// 5. Отправляем email уведомления выбранным получателям
|
||||
for (const recipient of recipients) {
|
||||
const taskData = {
|
||||
@@ -217,90 +198,6 @@ async function checkUpcomingDeadlines() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Логирует уведомление в PostgreSQL
|
||||
*/
|
||||
async function logNotificationToPostgres(data) {
|
||||
try {
|
||||
const {
|
||||
type,
|
||||
taskId,
|
||||
taskTitle,
|
||||
taskDescription,
|
||||
authorId,
|
||||
authorName,
|
||||
authorLogin,
|
||||
recipients = [],
|
||||
comment = '',
|
||||
status = '',
|
||||
userName = '',
|
||||
error = ''
|
||||
} = data;
|
||||
|
||||
// Создаем сообщение
|
||||
let messageContent = '';
|
||||
switch (type) {
|
||||
case 'created':
|
||||
messageContent = `Создана новая задача: ${taskTitle}`;
|
||||
break;
|
||||
case 'updated':
|
||||
messageContent = `Обновлена задача: ${taskTitle}`;
|
||||
break;
|
||||
case 'rework':
|
||||
messageContent = `Задача возвращена на доработку: ${taskTitle}. Комментарий: ${comment}`;
|
||||
break;
|
||||
case 'closed':
|
||||
messageContent = `Задача закрыта: ${taskTitle}`;
|
||||
break;
|
||||
case 'status_changed':
|
||||
messageContent = `Изменен статус задачи: ${taskTitle}. Новый статус: ${getStatusText(status)}`;
|
||||
break;
|
||||
}
|
||||
|
||||
const logIds = [];
|
||||
|
||||
for (const recipient of recipients) {
|
||||
const logId = await postgresLogger.logNotification({
|
||||
taskId,
|
||||
taskTitle,
|
||||
taskDescription,
|
||||
notificationType: type,
|
||||
authorId,
|
||||
authorName,
|
||||
authorLogin,
|
||||
recipientId: recipient.user_id,
|
||||
recipientName: recipient.user_name,
|
||||
recipientLogin: recipient.user_login,
|
||||
messageContent: `${messageContent}\n\nЗадача: ${taskTitle}\nОписание: ${taskDescription || 'Без описания'}\nАвтор: ${authorName}`,
|
||||
messageSubject: getNotificationSubject(type, taskTitle),
|
||||
deliveryMethods: ['email', 'telegram', 'vk'],
|
||||
comments: error ? `Ошибка: ${error}` : comment
|
||||
});
|
||||
|
||||
if (logId) {
|
||||
logIds.push(logId);
|
||||
}
|
||||
}
|
||||
|
||||
return logIds;
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Ошибка логирования в PostgreSQL:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновляет статус доставки уведомления в PostgreSQL
|
||||
*/
|
||||
async function updatePostgresLogStatus(logIds, status, errorMessage = null, sentAt = null) {
|
||||
if (!logIds || logIds.length === 0) return;
|
||||
|
||||
for (const logId of logIds) {
|
||||
await postgresLogger.updateNotificationStatus(logId, status, errorMessage, sentAt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает тему уведомления в зависимости от типа
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user