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}`,
|
${where} ORDER BY sm.lesson_date DESC, sm.id DESC LIMIT $${params.length - 1} OFFSET $${params.length}`,
|
||||||
params
|
params
|
||||||
);
|
);
|
||||||
let total = 0;
|
const { rows: cnt } = await pool.query(
|
||||||
if (offset === 0) {
|
`SELECT COUNT(*)::int AS n FROM short_messages sm ${where}`,
|
||||||
const { rows: cnt } = await pool.query(
|
params.slice(0, -2)
|
||||||
`SELECT COUNT(*)::int AS n FROM short_messages sm ${where}`,
|
);
|
||||||
params.slice(0, -2)
|
res.json({ items: rows, total: cnt[0]?.n || 0 });
|
||||||
);
|
|
||||||
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 });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user