Add product name to audit log ui

This commit is contained in:
2026-03-26 11:59:53 -04:00
parent 23b94d1c48
commit e4f5e2c4dd
2 changed files with 51 additions and 22 deletions

View File

@@ -91,22 +91,22 @@ router.get('/', async (req, res) => {
let paramIndex = 1;
if (user_id) {
conditions.push(`user_id = $${paramIndex++}`);
conditions.push(`a.user_id = $${paramIndex++}`);
params.push(user_id);
}
if (pid) {
conditions.push(`pid = $${paramIndex++}`);
conditions.push(`a.pid = $${paramIndex++}`);
params.push(pid);
}
if (action) {
conditions.push(`action = $${paramIndex++}`);
conditions.push(`a.action = $${paramIndex++}`);
params.push(action);
}
if (successFilter !== undefined) {
conditions.push(`success = $${paramIndex++}`);
conditions.push(`a.success = $${paramIndex++}`);
params.push(successFilter === 'true');
}
@@ -116,7 +116,7 @@ router.get('/', async (req, res) => {
// Get total count
const countResult = await pool.query(
`SELECT COUNT(*) FROM product_editor_audit_log ${whereClause}`,
`SELECT COUNT(*) FROM product_editor_audit_log a ${whereClause}`,
params
);
@@ -124,19 +124,21 @@ router.get('/', async (req, res) => {
const dataParams = [...params, parseInt(limit, 10), parseInt(offset, 10)];
const result = await pool.query(`
SELECT
id,
user_id,
username,
pid,
action,
target_endpoint,
success,
error_message,
duration_ms,
created_at
FROM product_editor_audit_log
a.id,
a.user_id,
a.username,
a.pid,
p.title AS product_name,
a.action,
a.target_endpoint,
a.success,
a.error_message,
a.duration_ms,
a.created_at
FROM product_editor_audit_log a
LEFT JOIN products p ON p.pid = a.pid
${whereClause}
ORDER BY created_at DESC
ORDER BY a.created_at DESC
LIMIT $${paramIndex++} OFFSET $${paramIndex++}
`, dataParams);
@@ -163,7 +165,7 @@ router.get('/:id', async (req, res) => {
}
const result = await pool.query(
'SELECT * FROM product_editor_audit_log WHERE id = $1',
'SELECT a.*, p.title AS product_name FROM product_editor_audit_log a LEFT JOIN products p ON p.pid = a.pid WHERE a.id = $1',
[id]
);