import type { AuditAction } from '../../shared/utils/audit' import { auditLog } from '../db/schema' // Fehler beim Protokollieren dürfen die eigentliche Aktion nicht scheitern // lassen — die ist zu diesem Zeitpunkt bereits ausgeführt export async function logAudit( userId: number, action: AuditAction, target: { type: string, id: string | number } | null, details?: Record, ) { try { await useDb().insert(auditLog).values({ userId, action, targetType: target?.type ?? null, targetId: target ? String(target.id) : null, details: details ?? null, }) } catch (err) { console.warn('[audit] Eintrag fehlgeschlagen:', err instanceof Error ? err.message : err) } }