24 lines
588 B
TypeScript
24 lines
588 B
TypeScript
import type { FastifyRequest } from 'fastify';
|
|
import { auditLogs } from '@source/database';
|
|
import type { Database } from '@source/database';
|
|
|
|
export async function createAuditLog(
|
|
db: Database,
|
|
request: FastifyRequest,
|
|
data: {
|
|
organizationId: string;
|
|
action: string;
|
|
serverId?: string;
|
|
metadata?: Record<string, unknown>;
|
|
},
|
|
) {
|
|
await db.insert(auditLogs).values({
|
|
organizationId: data.organizationId,
|
|
userId: request.user.sub,
|
|
serverId: data.serverId,
|
|
action: data.action,
|
|
metadata: data.metadata ?? {},
|
|
ipAddress: request.ip,
|
|
});
|
|
}
|