23 lines
647 B
TypeScript

import { auditLog, type DB, type NewAuditLogEntry } from "@cmbot/db";
export type AuditInput = {
operatorId: string | null;
source: "web" | "telegram" | "system";
action: string;
targetType?: string | null;
targetId?: string | null;
payload?: Record<string, unknown>;
};
export async function writeAuditLog(db: DB, input: AuditInput): Promise<void> {
const row: NewAuditLogEntry = {
operatorId: input.operatorId,
source: input.source,
action: input.action,
targetType: input.targetType ?? null,
targetId: input.targetId ?? null,
payload: input.payload ?? {},
};
await db.insert(auditLog).values(row);
}