diff --git a/backend/src/controllers/adminController.js b/backend/src/controllers/adminController.js index 8df3ff9..30cad04 100644 --- a/backend/src/controllers/adminController.js +++ b/backend/src/controllers/adminController.js @@ -295,13 +295,18 @@ function getUserSessions(req, res) { /* ── GET /api/admin/sessions ─────────────────────────────────────────── */ function getAllSessions(req, res) { - const { subject, user_id } = req.query; + const { subject, user_id, status } = req.query; const limit = Math.min(500, Math.max(1, Number(req.query.limit) || 200)); const offset = Math.max(0, Number(req.query.offset) || 0); - const where = ['ts.status = \'completed\'']; + // По умолчанию показываем и завершённые, и НЕзавершённые (in_progress) — иначе зависшие + // сессии не находились в списке (см. алерт «Зависла»). Опционально сужаем по ?status=. + const where = []; const params = []; + if (status && ['completed', 'in_progress', 'abandoned'].includes(status)) { + where.push('ts.status = ?'); params.push(status); + } if (subject) { where.push('s.slug = ?'); params.push(subject); } if (user_id) { where.push('ts.user_id = ?'); params.push(Number(user_id)); } @@ -317,7 +322,7 @@ function getAllSessions(req, res) { FROM test_sessions ts LEFT JOIN subjects s ON s.id = ts.subject_id JOIN users u ON u.id = ts.user_id - WHERE ${where.join(' AND ')} + ${where.length ? 'WHERE ' + where.join(' AND ') : ''} ORDER BY ts.started_at DESC LIMIT ? OFFSET ? `).all(...params);