feat: add TallyNote local reimbursement ledger
TallyNote release / linux-x64 (push) Failing after 2m41s
TallyNote release / linux-x64 (push) Failing after 2m41s
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import type Database from "better-sqlite3";
|
||||
|
||||
export type AuditInput = {
|
||||
requestId: string;
|
||||
actorAdminId?: string | null;
|
||||
actorUsername?: string | null;
|
||||
action: string;
|
||||
targetType: string;
|
||||
targetId?: string | null;
|
||||
outcome?: "success" | "denied" | "failure";
|
||||
before?: unknown;
|
||||
after?: unknown;
|
||||
metadata?: unknown;
|
||||
};
|
||||
|
||||
function json(value: unknown): string | null {
|
||||
return value === undefined ? null : JSON.stringify(value);
|
||||
}
|
||||
|
||||
export function writeAudit(sqlite: Database.Database, input: AuditInput): void {
|
||||
sqlite.prepare(`
|
||||
INSERT INTO audit_events (
|
||||
occurred_at, request_id, actor_admin_id, actor_username, action,
|
||||
target_type, target_id, outcome, before_json, after_json, metadata_json
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(
|
||||
Date.now(),
|
||||
input.requestId,
|
||||
input.actorAdminId ?? null,
|
||||
input.actorUsername ?? null,
|
||||
input.action,
|
||||
input.targetType,
|
||||
input.targetId ?? null,
|
||||
input.outcome ?? "success",
|
||||
json(input.before),
|
||||
json(input.after),
|
||||
json(input.metadata),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user