feat(report-card): decorative waves + exclude current entry from student works
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user