fix(shorts): GET /api/shorts всегда считает total, а не только при offset=0
This commit is contained in:
@@ -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}`,
|
||||
params
|
||||
);
|
||||
let total = 0;
|
||||
if (offset === 0) {
|
||||
const { rows: cnt } = await pool.query(
|
||||
`SELECT COUNT(*)::int AS n FROM short_messages sm ${where}`,
|
||||
params.slice(0, -2)
|
||||
);
|
||||
total = cnt[0]?.n || 0;
|
||||
}
|
||||
res.json({ items: rows, total });
|
||||
const { rows: cnt } = await pool.query(
|
||||
`SELECT COUNT(*)::int AS n FROM short_messages sm ${where}`,
|
||||
params.slice(0, -2)
|
||||
);
|
||||
res.json({ items: rows, total: cnt[0]?.n || 0 });
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: e.message });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user