Прощальные сообщения: отправленные только при статусе «Отправлено»

This commit is contained in:
dev
2026-11-28 15:15:09 +03:00
parent 84ed0adc74
commit bd02cf6493
4 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -81,8 +81,8 @@
## Контракты API (для фронта и внешних интеграций)
- `GET /api/farewells?limit=&offset=&resident=` → `{ items, total }`
(item: все поля строки; админ — все, не-admin — свои).
- `GET /api/farewells?limit=&offset=&resident=&deleted=&sent=` → `{ items, total }`
(item: все поля строки; админ — все, не-admin — свои; `sent=1|0` — только отправленные/неотправленные).
- `GET /api/farewells/templates?resident=` → `{ items: [{ id, created_at, text }] }` —
последние 5 `done`-записей по резиденту (ILIKE), для кнопок-шаблонов.
- `POST /api/farewells` `{ resident, topic?, source_feedback_ids[], template_id?, prompt?, ai_profile? }`
+3 -1
View File
@@ -125,7 +125,7 @@ async function createFarewell(pool, data) {
return ins.rows[0];
}
async function listFarewells(pool, { isAdmin, userId, limit, offset, resident, deleted }) {
async function listFarewells(pool, { isAdmin, userId, limit, offset, resident, deleted, sent }) {
const lim = Math.min(Math.max(parseInt(limit, 10) || 20, 1), 100);
const off = Math.max(parseInt(offset, 10) || 0, 0);
const params = [];
@@ -134,6 +134,8 @@ async function listFarewells(pool, { isAdmin, userId, limit, offset, resident, d
const res = String(resident || '').trim();
if (res) { params.push('%' + res + '%'); cond.push(`f.resident ILIKE $${params.length}`); }
cond.push(deleted ? 'f.deleted_at IS NOT NULL' : 'f.deleted_at IS NULL');
if (sent === true) cond.push('f.sent_at IS NOT NULL');
else if (sent === false) cond.push('f.sent_at IS NULL');
const where = 'WHERE ' + cond.join(' AND ');
const total = await pool.query(`SELECT count(*)::int AS n FROM farewell_messages f ${where}`, params);
params.push(lim, off);
+3 -1
View File
@@ -1450,7 +1450,7 @@
}
});
['fbSearch','fbGroupFilter','fbStatusFilter','fbDateFrom','fbDateTo','fbDeletedToggle'].forEach(id => {
document.getElementById(id).addEventListener('change', () => { page = 1; loadFeedbacks(); });
document.getElementById(id).addEventListener('change', () => { page = 1; loadFeedbacks(); if (id === 'fbStatusFilter') loadFarewells(); });
if (id === 'fbSearch') document.getElementById(id).addEventListener('input', () => { clearTimeout(searchTimer); searchTimer = setTimeout(() => { page = 1; loadFeedbacks(); }, 350); });
});
if (window.lucide) lucide.createIcons();
@@ -1806,6 +1806,8 @@
if (!el) return;
const q = new URLSearchParams({ limit: '10' });
const dt = document.getElementById('fwDeletedToggle');
const st = document.getElementById('fbStatusFilter');
q.set('sent', st && st.value === 'sent' ? '1' : '0');
if (dt && dt.checked) q.set('deleted', '1');
try {
const r = await fetch(`${API}/api/farewells?${q}`, { headers: hdr() });
+1
View File
@@ -6407,6 +6407,7 @@ app.get('/api/farewells', requireAuth, async (req, res) => {
offset: req.query.offset,
resident: req.query.resident,
deleted: req.query.deleted === '1' || req.query.deleted === 'true',
sent: req.query.sent === '1' || req.query.sent === 'true' ? true : (req.query.sent === '0' || req.query.sent === 'false' ? false : null),
});
res.json({ items, total });
} catch (err) {