feat(feedback): add prev-date endpoint, resident last_date, works display, mark stripe update

This commit is contained in:
dev
2026-10-15 20:17:28 +03:00
parent d93b51e859
commit 97058673c7
5 changed files with 239 additions and 33 deletions
+30 -3
View File
@@ -3998,6 +3998,30 @@ app.get('/api/feedbacks/last', requireAuth, async (req, res) => {
}
});
app.get('/api/feedbacks/prev-date', requireAuth, async (req, res) => {
try {
const resident = typeof req.query.resident === 'string' ? req.query.resident.trim() : '';
if (!resident) return res.status(400).json({ error: 'Нужен резидент' });
const before = parseFeedbackDate(req.query.before) || await appTodayIso();
const exclude = parseInt(req.query.exclude, 10) || 0;
const bs = branchScope(req.user);
if (bs.ids && !bs.ids.length) return res.json({ date: null });
const params = [resident, before, exclude];
let cond = `f.deleted_at IS NULL AND f.sent_at IS NOT NULL
AND lower(regexp_replace(trim(f.resident), '\\s+', ' ', 'g')) = lower(regexp_replace(trim($1), '\\s+', ' ', 'g'))
AND f.feedback_date < $2 AND f.id <> $3`;
if (bs.ids) { params.push(bs.ids); cond += ` AND f.branch_id = ANY($${params.length}::int[])`; }
const { rows } = await pool.query(
`SELECT max(f.feedback_date) AS prev_date FROM feedbacks f WHERE ${cond}`,
params
);
res.json({ date: rows[0] && rows[0].prev_date || null });
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Internal error' });
}
});
app.get('/api/feedbacks', requireAuth, async (req, res) => {
try {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
@@ -7817,14 +7841,17 @@ app.get('/api/students/names', requireAuth, async (req, res) => {
app.get('/api/students/names-with-groups', requireAuth, async (req, res) => {
const bw = branchWhere(req.user, 'g');
const { rows } = await pool.query(
`SELECT DISTINCT ON (e.student_name) e.student_name AS name, e.group_id, g.name AS group_name
const params = bw.params.slice();
const q = bindTz(
`SELECT DISTINCT ON (e.student_name) e.student_name AS name, e.group_id, g.name AS group_name,
to_char(e.created_at AT TIME ZONE $TZ$, 'YYYY-MM-DD') AS last_date
FROM entries e
JOIN groups g ON g.id = e.group_id
WHERE e.student_name IS NOT NULL AND e.student_name <> '' AND e.deleted_at IS NULL${bw.where}
ORDER BY e.student_name, e.created_at DESC NULLS LAST, e.id DESC`,
bw.params
params, await appTimezone()
);
const { rows } = await pool.query(q.sql, q.params);
res.json(rows);
});