mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 05:11:13 -05:00
Fix: Use RPC for submission claims
This commit is contained in:
@@ -324,20 +324,19 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
|
||||
.single();
|
||||
|
||||
const expiresAt = new Date(Date.now() + 15 * 60 * 1000);
|
||||
const now = new Date().toISOString();
|
||||
|
||||
const { error } = await supabase
|
||||
.from('content_submissions')
|
||||
.update({
|
||||
assigned_to: user.id,
|
||||
assigned_at: new Date().toISOString(),
|
||||
locked_until: expiresAt.toISOString(),
|
||||
})
|
||||
.eq('id', submissionId)
|
||||
.or(`assigned_to.is.null,locked_until.lt."${now}"`); // Only if unclaimed or lock expired
|
||||
const { data, error } = await supabase.rpc('claim_specific_submission', {
|
||||
p_submission_id: submissionId,
|
||||
p_moderator_id: user.id,
|
||||
p_lock_duration: '15 minutes',
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
if (!data) {
|
||||
throw new Error('Submission is already claimed or no longer available');
|
||||
}
|
||||
|
||||
setCurrentLock({
|
||||
submissionId,
|
||||
expiresAt,
|
||||
|
||||
@@ -5403,6 +5403,14 @@ export type Database = {
|
||||
waiting_time: unknown
|
||||
}[]
|
||||
}
|
||||
claim_specific_submission: {
|
||||
Args: {
|
||||
p_lock_duration?: unknown
|
||||
p_moderator_id: string
|
||||
p_submission_id: string
|
||||
}
|
||||
Returns: boolean
|
||||
}
|
||||
cleanup_expired_sessions: { Args: never; Returns: undefined }
|
||||
cleanup_old_page_views: { Args: never; Returns: undefined }
|
||||
cleanup_old_request_metadata: { Args: never; Returns: undefined }
|
||||
|
||||
Reference in New Issue
Block a user