feat(feedback): improve feedback workflow
This commit is contained in:
@@ -2750,8 +2750,11 @@ app.get('/api/shorts', requireAuth, async (req, res) => {
|
||||
const offset = Math.max(parseInt(req.query.offset, 10) || 0, 0);
|
||||
const showDeleted = req.query.deleted === '1' || req.query.deleted === 'true';
|
||||
const search = req.query.search ? String(req.query.search).trim() : '';
|
||||
const usedFilter = req.query.used;
|
||||
const params = [];
|
||||
let where = showDeleted ? 'WHERE sm.deleted_at IS NOT NULL' : 'WHERE sm.deleted_at IS NULL';
|
||||
if (usedFilter === '0' || usedFilter === 'false') where += ' AND sm.used = false';
|
||||
else if (usedFilter === '1' || usedFilter === 'true') where += ' AND sm.used = true';
|
||||
if (search) {
|
||||
params.push(`%${search}%`);
|
||||
where += ` AND (sm.resident ILIKE $${params.length} OR sm.topic ILIKE $${params.length} OR sm.message ILIKE $${params.length})`;
|
||||
@@ -2935,6 +2938,35 @@ function parseFeedbackDate(s) {
|
||||
return str;
|
||||
}
|
||||
|
||||
app.get('/api/feedbacks/last', 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 key = ['feedbacks:last:', scopeKey(req.user), resident.toLowerCase()].join(':');
|
||||
const payload = await cacheWrap(key, FEEDBACK_LIST_TTL_MS, async () => {
|
||||
const bs = branchScope(req.user);
|
||||
if (bs.ids && !bs.ids.length) return null;
|
||||
const params = [`%${resident}%`];
|
||||
let cond = 'f.deleted_at IS NULL AND f.resident ILIKE $1';
|
||||
if (bs.ids) { params.push(bs.ids); cond += ` AND f.branch_id = ANY($${params.length}::int[])`; }
|
||||
const { rows } = await pool.query(
|
||||
`SELECT f.id, f.feedback_date, f.group_id, f.resident, f.topic, f.past_review, f.text, f.ai_status, f.sent_at, f.branch_id, f.deleted_at, g.name AS group_name
|
||||
FROM feedbacks f
|
||||
LEFT JOIN groups g ON g.id = f.group_id
|
||||
WHERE ${cond}
|
||||
ORDER BY f.feedback_date DESC NULLS LAST, f.id DESC
|
||||
LIMIT 1`,
|
||||
params
|
||||
);
|
||||
return rows[0] || null;
|
||||
});
|
||||
res.json(payload);
|
||||
} 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);
|
||||
@@ -5690,7 +5722,7 @@ app.get('/api/students/names-with-groups', requireAuth, async (req, res) => {
|
||||
`SELECT DISTINCT ON (e.student_name) e.student_name AS name, e.group_id, g.name AS group_name
|
||||
FROM entries e
|
||||
JOIN groups g ON g.id = e.group_id
|
||||
WHERE e.student_name IS NOT NULL AND e.student_name <> ''${bw.where}
|
||||
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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user