mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 22:11:24 -05:00
Fix RPC call transaction mode
This commit is contained in:
@@ -325,13 +325,34 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
|
||||
|
||||
const expiresAt = new Date(Date.now() + 15 * 60 * 1000);
|
||||
|
||||
const { data, error } = await supabase.rpc('claim_specific_submission', {
|
||||
p_submission_id: submissionId,
|
||||
p_moderator_id: user.id,
|
||||
p_lock_duration: '15 minutes',
|
||||
// Use direct fetch to force read-write transaction
|
||||
const supabaseUrl = 'https://api.thrillwiki.com';
|
||||
const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InlkdnRtbnJzenlicW5iY3FiZGN5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTgzMjYzNTYsImV4cCI6MjA3MzkwMjM1Nn0.DM3oyapd_omP5ZzIlrT0H9qBsiQBxBRgw2tYuqgXKX4';
|
||||
|
||||
const { data: sessionData } = await supabase.auth.getSession();
|
||||
const token = sessionData.session?.access_token;
|
||||
|
||||
const response = await fetch(`${supabaseUrl}/rest/v1/rpc/claim_specific_submission`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'apikey': supabaseKey,
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Prefer': 'tx=commit', // Force read-write transaction
|
||||
},
|
||||
body: JSON.stringify({
|
||||
p_submission_id: submissionId,
|
||||
p_moderator_id: user.id,
|
||||
p_lock_duration: '15 minutes',
|
||||
}),
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ message: 'Failed to claim submission' }));
|
||||
throw new Error(errorData.message || 'Failed to claim submission');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!data) {
|
||||
throw new Error('Submission is already claimed or no longer available');
|
||||
|
||||
Reference in New Issue
Block a user