Files
2026-04-20 15:49:01 -05:00

30 lines
766 B
TypeScript

import { prisma } from "@/lib/prisma";
export interface AuditInput {
actorId?: string | null;
action: string;
entity: string;
entityId?: string | null;
before?: unknown;
after?: unknown;
ipAddress?: string | null;
}
export async function audit(input: AuditInput): Promise<void> {
try {
await prisma.auditLog.create({
data: {
actorId: input.actorId ?? null,
action: input.action,
entity: input.entity,
entityId: input.entityId ?? null,
before: input.before ? JSON.stringify(input.before) : null,
after: input.after ? JSON.stringify(input.after) : null,
ipAddress: input.ipAddress ?? null,
},
});
} catch (err) {
console.error("[audit] failed to record:", err);
}
}