From 055084b9c510499495934da1929cfaeb38fd4a6e Mon Sep 17 00:00:00 2001 From: dev Date: Tue, 13 Oct 2026 01:20:00 +0300 Subject: [PATCH] =?UTF-8?q?fix(shorts):=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20LIMIT/OFFSET=20=D0=B8=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BB=D0=B0=D1=81=D1=82=D1=8C=20=D0=B2=D0=B8=D0=B4=D0=B8?= =?UTF-8?q?=D0=BC=D0=BE=D1=81=D1=82=D0=B8=20=D1=84=D0=B8=D0=BB=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=20=D0=B2=20/api/shorts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 77743fc..5f0e0b0 100644 --- a/server.js +++ b/server.js @@ -3478,6 +3478,9 @@ app.get('/api/shorts', requireAuth, async (req, res) => { params.push(`%${search}%`); where += ` AND (sm.resident ILIKE $${params.length} OR sm.topic ILIKE $${params.length} OR sm.message ILIKE $${params.length})`; } + const countParams = params.slice(); + const limitParam = params.length + 1; + const offsetParam = params.length + 2; params.push(limit, offset); const scope = branchScope(req.user); let studentIdSql; @@ -3485,9 +3488,10 @@ app.get('/api/shorts', requireAuth, async (req, res) => { studentIdSql = `(SELECT s.id FROM students s WHERE TRIM(s.name) = TRIM(sm.resident) AND s.deleted_at IS NULL LIMIT 1)`; } else if (scope.ids.length) { params.push(scope.ids); + const branchParam = params.length; studentIdSql = `(SELECT s.id FROM students s LEFT JOIN groups g ON g.id = s.group_id WHERE TRIM(s.name) = TRIM(sm.resident) AND s.deleted_at IS NULL - AND (s.group_id IS NULL OR g.branch_id = ANY($${params.length}::int[])) LIMIT 1)`; + AND (s.group_id IS NULL OR g.branch_id = ANY($${branchParam}::int[])) LIMIT 1)`; } else { studentIdSql = `(SELECT s.id FROM students s WHERE TRIM(s.name) = TRIM(sm.resident) AND s.deleted_at IS NULL AND s.group_id IS NULL LIMIT 1)`; } @@ -3497,12 +3501,12 @@ app.get('/api/shorts', requireAuth, async (req, res) => { COALESCE((SELECT MAX(swm.delta) FROM student_work_marks swm WHERE swm.short_message_id = sm.id), 0) AS delta, ${studentIdSql} AS student_id FROM short_messages sm LEFT JOIN users u ON u.id = sm.author_id - ${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 $${limitParam} OFFSET $${offsetParam}`, params ); const { rows: cnt } = await pool.query( `SELECT COUNT(*)::int AS n FROM short_messages sm ${where}`, - params.slice(0, -2) + countParams ); res.json({ items: rows, total: cnt[0]?.n || 0 }); } catch (e) {