mass refactor
This commit is contained in:
@@ -233,8 +233,8 @@ export class NotificationService {
|
||||
SELECT m.created_at
|
||||
FROM messages m
|
||||
JOIN matches mt ON m.match_id = mt.id
|
||||
WHERE (mt.user1_id = $1 OR mt.user2_id = $1)
|
||||
AND (mt.user1_id = $2 OR mt.user2_id = $2)
|
||||
WHERE (mt.user_id_1 = $1 OR mt.user_id_2 = $1)
|
||||
AND (mt.user_id_1 = $2 OR mt.user_id_2 = $2)
|
||||
AND m.sender_id = $1
|
||||
ORDER BY m.created_at DESC
|
||||
LIMIT 1
|
||||
@@ -347,10 +347,33 @@ export class NotificationService {
|
||||
// Планировщик уведомлений (вызывается периодически)
|
||||
async processScheduledNotifications(): Promise<void> {
|
||||
try {
|
||||
// Проверим, существует ли таблица scheduled_notifications
|
||||
const tableCheck = await query(`
|
||||
SELECT EXISTS (
|
||||
SELECT FROM information_schema.tables
|
||||
WHERE table_name = 'scheduled_notifications'
|
||||
) as exists
|
||||
`);
|
||||
|
||||
if (!tableCheck.rows[0].exists) {
|
||||
// Если таблицы нет, создаем её
|
||||
await query(`
|
||||
CREATE TABLE IF NOT EXISTS scheduled_notifications (
|
||||
id UUID PRIMARY KEY,
|
||||
user_id UUID REFERENCES users(id),
|
||||
type VARCHAR(50) NOT NULL,
|
||||
data JSONB,
|
||||
scheduled_at TIMESTAMP NOT NULL,
|
||||
is_processed BOOLEAN DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
)
|
||||
`);
|
||||
}
|
||||
|
||||
// Получаем запланированные уведомления
|
||||
const result = await query(`
|
||||
SELECT * FROM scheduled_notifications
|
||||
WHERE scheduled_at <= $1 AND processed = false
|
||||
WHERE scheduled_at <= $1 AND is_processed = false
|
||||
ORDER BY scheduled_at ASC
|
||||
LIMIT 100
|
||||
`, [new Date()]);
|
||||
@@ -370,7 +393,7 @@ export class NotificationService {
|
||||
|
||||
// Отмечаем как обработанное
|
||||
await query(
|
||||
'UPDATE scheduled_notifications SET processed = true WHERE id = $1',
|
||||
'UPDATE scheduled_notifications SET is_processed = true WHERE id = $1',
|
||||
[notification.id]
|
||||
);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user