feat(MED-105): create audit entry on analysis results view
This commit is contained in:
35
lib/services/audit/pageView.service.ts
Normal file
35
lib/services/audit/pageView.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user