farewell: шаблоны по всем своим прощальным, выбор прошлых отзывов тумблером, формат [дата] - тема : сообщение

This commit is contained in:
dev
2026-11-12 14:49:08 +03:00
parent 7e88247ced
commit 117aa578b8
5 changed files with 93 additions and 32 deletions
+8 -10
View File
@@ -148,16 +148,14 @@ async function listFarewells(pool, { isAdmin, userId, limit, offset, resident, d
return { items: rows.rows, total: total.rows[0].n };
}
async function listFarewellTemplates(pool, { isAdmin, userId, resident, limit }) {
const lim = Math.min(Math.max(parseInt(limit, 10) || 5, 1), 5);
const res = String(resident || '').trim();
if (!res) return [];
const params = ['%' + res + '%'];
let sql = `SELECT id, resident, topic, created_at, text FROM farewell_messages WHERE resident ILIKE $1 AND ai_status = 'done' AND COALESCE(text, '') <> '' AND deleted_at IS NULL`;
if (!isAdmin) { params.push(userId); sql += ` AND author_id = $${params.length}`; }
params.push(lim);
sql += ` ORDER BY id DESC LIMIT $${params.length}`;
const r = await pool.query(sql, params);
async function listFarewellTemplates(pool, { userId, limit }) {
const lim = Math.min(Math.max(parseInt(limit, 10) || 10, 1), 20);
const r = await pool.query(
`SELECT id, resident, topic, created_at, text FROM farewell_messages
WHERE author_id = $1 AND ai_status = 'done' AND COALESCE(text, '') <> '' AND deleted_at IS NULL
ORDER BY id DESC LIMIT $2`,
[userId, lim]
);
return r.rows;
}