Прощальные сообщения: отправленные только при статусе «Отправлено»
This commit is contained in:
+2
-2
@@ -81,8 +81,8 @@
|
|||||||
|
|
||||||
## Контракты API (для фронта и внешних интеграций)
|
## Контракты API (для фронта и внешних интеграций)
|
||||||
|
|
||||||
- `GET /api/farewells?limit=&offset=&resident=` → `{ items, total }`
|
- `GET /api/farewells?limit=&offset=&resident=&deleted=&sent=` → `{ items, total }`
|
||||||
(item: все поля строки; админ — все, не-admin — свои).
|
(item: все поля строки; админ — все, не-admin — свои; `sent=1|0` — только отправленные/неотправленные).
|
||||||
- `GET /api/farewells/templates?resident=` → `{ items: [{ id, created_at, text }] }` —
|
- `GET /api/farewells/templates?resident=` → `{ items: [{ id, created_at, text }] }` —
|
||||||
последние 5 `done`-записей по резиденту (ILIKE), для кнопок-шаблонов.
|
последние 5 `done`-записей по резиденту (ILIKE), для кнопок-шаблонов.
|
||||||
- `POST /api/farewells` `{ resident, topic?, source_feedback_ids[], template_id?, prompt?, ai_profile? }`
|
- `POST /api/farewells` `{ resident, topic?, source_feedback_ids[], template_id?, prompt?, ai_profile? }`
|
||||||
|
|||||||
+3
-1
@@ -125,7 +125,7 @@ async function createFarewell(pool, data) {
|
|||||||
return ins.rows[0];
|
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 lim = Math.min(Math.max(parseInt(limit, 10) || 20, 1), 100);
|
||||||
const off = Math.max(parseInt(offset, 10) || 0, 0);
|
const off = Math.max(parseInt(offset, 10) || 0, 0);
|
||||||
const params = [];
|
const params = [];
|
||||||
@@ -134,6 +134,8 @@ async function listFarewells(pool, { isAdmin, userId, limit, offset, resident, d
|
|||||||
const res = String(resident || '').trim();
|
const res = String(resident || '').trim();
|
||||||
if (res) { params.push('%' + res + '%'); cond.push(`f.resident ILIKE $${params.length}`); }
|
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');
|
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 where = 'WHERE ' + cond.join(' AND ');
|
||||||
const total = await pool.query(`SELECT count(*)::int AS n FROM farewell_messages f ${where}`, params);
|
const total = await pool.query(`SELECT count(*)::int AS n FROM farewell_messages f ${where}`, params);
|
||||||
params.push(lim, off);
|
params.push(lim, off);
|
||||||
|
|||||||
@@ -1450,7 +1450,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
['fbSearch','fbGroupFilter','fbStatusFilter','fbDateFrom','fbDateTo','fbDeletedToggle'].forEach(id => {
|
['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 (id === 'fbSearch') document.getElementById(id).addEventListener('input', () => { clearTimeout(searchTimer); searchTimer = setTimeout(() => { page = 1; loadFeedbacks(); }, 350); });
|
||||||
});
|
});
|
||||||
if (window.lucide) lucide.createIcons();
|
if (window.lucide) lucide.createIcons();
|
||||||
@@ -1806,6 +1806,8 @@
|
|||||||
if (!el) return;
|
if (!el) return;
|
||||||
const q = new URLSearchParams({ limit: '10' });
|
const q = new URLSearchParams({ limit: '10' });
|
||||||
const dt = document.getElementById('fwDeletedToggle');
|
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');
|
if (dt && dt.checked) q.set('deleted', '1');
|
||||||
try {
|
try {
|
||||||
const r = await fetch(`${API}/api/farewells?${q}`, { headers: hdr() });
|
const r = await fetch(`${API}/api/farewells?${q}`, { headers: hdr() });
|
||||||
|
|||||||
@@ -6407,6 +6407,7 @@ app.get('/api/farewells', requireAuth, async (req, res) => {
|
|||||||
offset: req.query.offset,
|
offset: req.query.offset,
|
||||||
resident: req.query.resident,
|
resident: req.query.resident,
|
||||||
deleted: req.query.deleted === '1' || req.query.deleted === 'true',
|
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 });
|
res.json({ items, total });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user