feat(MED-105): create audit entry on analysis results view

This commit is contained in:
2025-08-11 09:21:13 +03:00
parent 49fc75b17b
commit 83fff1ffe7
4 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { getSupabaseServerClient } from '@kit/supabase/server-client';
export const createPageViewLog = async ({
accountId,
action,
}: {
accountId: string;
action: 'VIEW_ANALYSIS_RESULTS';
}) => {
try {
const supabase = getSupabaseServerClient();
const {
data: { user },
error: userError,
} = await supabase.auth.getUser();
if (userError || !user) {
console.error('No authenticated user found; skipping audit insert');
return;
}
await supabase
.schema('audit')
.from('page_views')
.insert({
account_id: accountId,
action,
changed_by: user.id,
})
.throwOnError();
} catch (error) {
console.error('Failed to insert page view log', error);
}
}