feat(report-card): decorative waves + exclude current entry from student works

This commit is contained in:
dev
2026-10-20 15:36:14 +03:00
parent ea8722b544
commit 451ca278cc
4 changed files with 32 additions and 5 deletions
+9 -2
View File
@@ -8210,8 +8210,10 @@ app.get('/api/students/works-by-name', requireAuth, async (req, res) => {
const name = String(req.query.name || '').trim().slice(0, 150);
if (!name) return res.json({ photos: [] });
let limit = 3;
let excludeEntry = null;
try {
limit = optInt(req.query.limit, 1, 24) ?? 3;
excludeEntry = optInt(req.query.exclude_entry, 1, Infinity);
} catch {
return res.status(400).json({ error: 'Неверный limit' });
}
@@ -8223,16 +8225,21 @@ app.get('/api/students/works-by-name', requireAuth, async (req, res) => {
params.push(bs.ids);
branch = ` AND g.branch_id = ANY($${params.length}::int[])`;
}
let excl = '';
if (excludeEntry) {
params.push(excludeEntry);
excl = ` AND e.id <> $${params.length}`;
}
params.push(limit);
const { rows } = await pool.query(
`SELECT path FROM (
SELECT e.photo_path AS path, e.created_at AS ca
FROM entries e JOIN groups g ON g.id = e.group_id
WHERE e.student_name = $1 AND e.deleted_at IS NULL AND e.photo_path IS NOT NULL${branch}
WHERE e.student_name = $1 AND e.deleted_at IS NULL AND e.photo_path IS NOT NULL${branch}${excl}
UNION ALL
SELECT ep.photo_path AS path, e.created_at AS ca
FROM entries e JOIN groups g ON g.id = e.group_id JOIN entry_photos ep ON ep.entry_id = e.id
WHERE e.student_name = $1 AND e.deleted_at IS NULL AND ep.photo_path IS NOT NULL${branch}
WHERE e.student_name = $1 AND e.deleted_at IS NULL AND ep.photo_path IS NOT NULL${branch}${excl}
) u
GROUP BY path
ORDER BY MAX(ca) DESC NULLS LAST