diff --git a/inventory-server/src/routes/product-editor-audit-log.js b/inventory-server/src/routes/product-editor-audit-log.js index 8473c8a..3fd188f 100644 --- a/inventory-server/src/routes/product-editor-audit-log.js +++ b/inventory-server/src/routes/product-editor-audit-log.js @@ -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] ); diff --git a/inventory/src/components/settings/AuditLog.tsx b/inventory/src/components/settings/AuditLog.tsx index dc56405..f50b24e 100644 --- a/inventory/src/components/settings/AuditLog.tsx +++ b/inventory/src/components/settings/AuditLog.tsx @@ -26,6 +26,7 @@ interface AuditEntry { errored_count?: number; // Editor-specific pid?: number; + product_name?: string | null; action?: string; } @@ -323,7 +324,7 @@ function EditorTable({ entries, onView }: { entries: AuditEntry[]; onView: (id: Time User - PID + Product Action Status Duration @@ -335,7 +336,21 @@ function EditorTable({ entries, onView }: { entries: AuditEntry[]; onView: (id: {formatDate(e.created_at)} {e.username ?? `#${e.user_id}`} - {e.pid} + +
+ + {e.pid} + + {e.product_name && ( + {e.product_name} + )} +
+
{ACTION_LABELS[e.action ?? ""] ?? e.action} @@ -413,8 +428,20 @@ function DetailView({ detail, logType }: { detail: AuditDetail; logType: LogType {logType === "editor" && ( <>
- Product ID -

{detail.pid}

+ Product +

+ + {detail.pid} + + {detail.product_name && ( + {detail.product_name} + )} +

Action