mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-08-04 03:27:05 -04:00
21 lines
808 B
TypeScript
21 lines
808 B
TypeScript
import SQL from 'sql-template-strings';
|
|
import { ulid } from 'ulid';
|
|
import * as Sentry from '@sentry/node';
|
|
import type { Database } from './db.ts';
|
|
import type { UserRow } from './routes/user.ts';
|
|
|
|
export default async (
|
|
req: { db: Database, user?: Pick<UserRow, 'id' | 'username'> | null, rawUser?: Pick<UserRow, 'id' | 'username'> | undefined },
|
|
event: string,
|
|
payload: object | null = null,
|
|
): Promise<void> => {
|
|
try {
|
|
const user = req.user || req.rawUser || { id: null, username: null };
|
|
await req.db.get(SQL`INSERT INTO audit_log (id, userId, username, event, payload) VALUES (
|
|
${ulid()}, ${user.id}, ${user.username}, ${event}, ${payload ? JSON.stringify(payload) : null}
|
|
)`);
|
|
} catch (error) {
|
|
Sentry.captureException(error);
|
|
}
|
|
};
|