feat(groups): быстрые фильтры и права тьюторов, права на отчёты о занятии

- фильтры групп по филиалу, тьютору и дню, сохранение в localStorage и сброс
- тьютор может редактировать только свои группы; филиал и тьютора меняет админ
- редактирование отчётов о занятии доступно только автору или админу
This commit is contained in:
dev
2026-10-23 10:12:44 +03:00
parent d0a17c5f62
commit 621067a880
8 changed files with 269 additions and 64 deletions
+9
View File
@@ -0,0 +1,9 @@
async function groupOwnedBy(pool, userId, groupId) {
const { rows } = await pool.query(
'SELECT 1 FROM groups WHERE id = $1 AND tutor_id = $2',
[groupId, userId]
);
return rows.length > 0;
}
module.exports = { groupOwnedBy };
+16
View File
@@ -0,0 +1,16 @@
const LESSON_REPORT_EDIT_DENIED = 'Изменять отчёт о занятии может только его автор или администратор';
function lessonReportEditable(report, user) {
if (!report || !user) return false;
if (user.role === 'admin') return true;
if (report.author_id == null) return false;
return Number(report.author_id) === Number(user.id);
}
function lessonReportWriteBlocked(res, report, user) {
if (lessonReportEditable(report, user)) return false;
res.status(403).json({ error: LESSON_REPORT_EDIT_DENIED });
return true;
}
module.exports = { LESSON_REPORT_EDIT_DENIED, lessonReportEditable, lessonReportWriteBlocked };