mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 18:11:12 -05:00
feat: Implement comprehensive request tracking and state management
This commit is contained in:
@@ -11,6 +11,7 @@ import { createTableQuery } from '@/lib/supabaseHelpers';
|
||||
import type { ModerationItem } from '@/types/moderation';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { getErrorMessage } from '@/lib/errorHandler';
|
||||
import { invokeWithTracking, invokeBatchWithTracking } from '@/lib/edgeFunctionTracking';
|
||||
|
||||
/**
|
||||
* Type-safe update data for review moderation
|
||||
@@ -184,20 +185,32 @@ export async function approveSubmissionItems(
|
||||
itemIds: string[]
|
||||
): Promise<ModerationActionResult> {
|
||||
try {
|
||||
const { error: approvalError } = await supabase.functions.invoke(
|
||||
const { data: approvalData, error: approvalError, requestId } = await invokeWithTracking(
|
||||
'process-selective-approval',
|
||||
{
|
||||
body: {
|
||||
itemIds,
|
||||
submissionId,
|
||||
},
|
||||
itemIds,
|
||||
submissionId,
|
||||
}
|
||||
);
|
||||
|
||||
if (approvalError) {
|
||||
logger.error('Submission items approval failed via edge function', {
|
||||
action: 'approve_submission_items',
|
||||
submissionId,
|
||||
itemCount: itemIds.length,
|
||||
requestId,
|
||||
error: approvalError.message,
|
||||
});
|
||||
throw new Error(`Failed to process submission items: ${approvalError.message}`);
|
||||
}
|
||||
|
||||
logger.info('Submission items approved successfully', {
|
||||
action: 'approve_submission_items',
|
||||
submissionId,
|
||||
itemCount: itemIds.length,
|
||||
requestId,
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Successfully processed ${itemIds.length} item(s)`,
|
||||
@@ -478,24 +491,28 @@ export async function deleteSubmission(
|
||||
|
||||
// Delete photos from Cloudflare
|
||||
if (validImageIds.length > 0) {
|
||||
const deletePromises = validImageIds.map(async imageId => {
|
||||
try {
|
||||
await supabase.functions.invoke('upload-image', {
|
||||
method: 'DELETE',
|
||||
body: { imageId },
|
||||
});
|
||||
} catch (photoDeleteError: unknown) {
|
||||
const errorMessage = getErrorMessage(photoDeleteError);
|
||||
logger.error('Photo deletion failed', {
|
||||
action: 'delete_submission_photo',
|
||||
imageId,
|
||||
error: errorMessage
|
||||
});
|
||||
}
|
||||
});
|
||||
const deleteResults = await invokeBatchWithTracking(
|
||||
validImageIds.map(imageId => ({
|
||||
functionName: 'upload-image',
|
||||
payload: { action: 'delete', imageId },
|
||||
})),
|
||||
undefined
|
||||
);
|
||||
|
||||
await Promise.allSettled(deletePromises);
|
||||
deletedPhotoCount = validImageIds.length;
|
||||
// Count successful deletions
|
||||
const successfulDeletions = deleteResults.filter(r => !r.error);
|
||||
deletedPhotoCount = successfulDeletions.length;
|
||||
|
||||
// Log any failures
|
||||
const failedDeletions = deleteResults.filter(r => r.error);
|
||||
if (failedDeletions.length > 0) {
|
||||
logger.error('Some photo deletions failed', {
|
||||
action: 'delete_submission_photos',
|
||||
failureCount: failedDeletions.length,
|
||||
totalAttempted: validImageIds.length,
|
||||
failedRequestIds: failedDeletions.map(r => r.requestId),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user