mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 19:11:12 -05:00
Connect to atomic rejection flow
Introduce atomic rejection for bulk submissions, remove dead moderation code, and clean exports: - Replace direct DB updates in rejectSubmissionItems with atomic process-selective-rejection edge function call - Add edge function invocation helper import - Remove obsolete moderation actions (approvePhotoSubmission, rejectSubmissionItems, performModerationAction) and prune exports - Update moderation index exports accordingly - Ensure cascade handling uses atomic pipeline and avoid updateSubmissionStatusAfterRejection calls
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { handleError, handleNonCriticalError, getErrorMessage } from './errorHandler';
|
||||
import { extractCloudflareImageId } from './cloudflareImageUtils';
|
||||
import { invokeWithTracking } from './edgeFunctionTracking';
|
||||
|
||||
// Core submission item interface with dependencies
|
||||
// NOTE: item_data and original_data use `unknown` because they contain dynamic structures
|
||||
@@ -1367,32 +1368,24 @@ export async function rejectSubmissionItems(
|
||||
}
|
||||
}
|
||||
|
||||
// Update all items to rejected status
|
||||
const updates = Array.from(itemsToReject).map(async (itemId) => {
|
||||
const { error } = await supabase
|
||||
.from('submission_items')
|
||||
.update({
|
||||
status: 'rejected' as const,
|
||||
rejection_reason: reason,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq('id', itemId);
|
||||
|
||||
if (error) {
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Reject Submission Item',
|
||||
metadata: { itemId }
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(updates);
|
||||
|
||||
// Update parent submission status
|
||||
const submissionId = items[0]?.submission_id;
|
||||
if (submissionId) {
|
||||
await updateSubmissionStatusAfterRejection(submissionId);
|
||||
if (!submissionId) {
|
||||
throw new Error('Cannot reject items: missing submission ID');
|
||||
}
|
||||
|
||||
// Use atomic edge function for rejection
|
||||
const { data, error } = await invokeWithTracking(
|
||||
'process-selective-rejection',
|
||||
{
|
||||
itemIds: Array.from(itemsToReject),
|
||||
submissionId,
|
||||
rejectionReason: reason,
|
||||
},
|
||||
userId
|
||||
);
|
||||
|
||||
if (error) {
|
||||
throw new Error(`Failed to reject items: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user