fix(shorts): GET /api/shorts всегда считает total, а не только при offset=0

This commit is contained in:
dev
2026-10-08 11:58:44 +03:00
parent b87979a5d6
commit 5d7882260a
+1 -5
View File
@@ -2784,15 +2784,11 @@ app.get('/api/shorts', requireAuth, async (req, res) => {
${where} ORDER BY sm.lesson_date DESC, sm.id DESC LIMIT $${params.length - 1} OFFSET $${params.length}`, ${where} ORDER BY sm.lesson_date DESC, sm.id DESC LIMIT $${params.length - 1} OFFSET $${params.length}`,
params params
); );
let total = 0;
if (offset === 0) {
const { rows: cnt } = await pool.query( const { rows: cnt } = await pool.query(
`SELECT COUNT(*)::int AS n FROM short_messages sm ${where}`, `SELECT COUNT(*)::int AS n FROM short_messages sm ${where}`,
params.slice(0, -2) params.slice(0, -2)
); );
total = cnt[0]?.n || 0; res.json({ items: rows, total: cnt[0]?.n || 0 });
}
res.json({ items: rows, total });
} catch (e) { } catch (e) {
res.status(500).json({ error: e.message }); res.status(500).json({ error: e.message });
} }