14 lines
795 B
TypeScript
14 lines
795 B
TypeScript
import { requireAdmin } from '../../utils/auth'
|
|
import { useDatabase } from '../../utils/db'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
await requireAdmin(event)
|
|
const rows = useDatabase().prepare(`
|
|
SELECT audit_logs.id, audit_logs.action, audit_logs.entity_type, audit_logs.entity_key,
|
|
audit_logs.ip_address, audit_logs.created_at, admin_users.display_name
|
|
FROM audit_logs LEFT JOIN admin_users ON admin_users.id = audit_logs.operator_id
|
|
ORDER BY audit_logs.id DESC LIMIT 50
|
|
`).all() as Array<Record<string, string | number | null>>
|
|
return { data: rows.map(row => ({ id: row.id, action: row.action, entityType: row.entity_type, entityKey: row.entity_key, ipAddress: row.ip_address, createdAt: row.created_at, operator: row.display_name || '系统' })) }
|
|
})
|