farewell: шаблоны по всем своим прощальным, выбор прошлых отзывов тумблером, формат [дата] - тема : сообщение
This commit is contained in:
+8
-10
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user