SPB Git
560 B · 6 lines typescript
1import { sql } from "@/db";2export async function audit(actor: { id?: string | null; label: string; ip?: string | null }, action: string, entityType: string, entityId: string | null, before?: unknown, after?: unknown) {3  await sql`INSERT INTO audit_log (actor_id, actor_label, action, entity_type, entity_id, before, after, ip)4    VALUES (${actor.id ?? null}, ${actor.label}, ${action}, ${entityType}, ${entityId}, ${before === undefined ? null : sql.json(before as never)}, ${after === undefined ? null : sql.json(after as never)}, ${actor.ip ?? null})`;5}6
Files · main
Menu

Theme