Merge pull request #7 from pacnpal/main

Main
This commit is contained in:
pacnpal
2025-11-07 22:49:49 -05:00
committed by GitHub
4 changed files with 70 additions and 34 deletions

View File

@@ -72,7 +72,13 @@ export async function fetchSubmissionItems(submissionId: string): Promise<Submis
.eq('submission_id', submissionId)
.order('order_index', { ascending: true });
if (error) throw error;
if (error) {
handleError(error, {
action: 'Fetch Submission Items',
metadata: { submissionId }
});
throw error;
}
// Transform data to include relational data as item_data
return await Promise.all((data || []).map(async item => {
@@ -84,12 +90,21 @@ export async function fetchSubmissionItems(submissionId: string): Promise<Submis
// Fetch location from park_submission_locations if available
let locationData: any = null;
if (parkSub?.id) {
const { data } = await supabase
const { data, error: locationError } = await supabase
.from('park_submission_locations')
.select('*')
.eq('park_submission_id', parkSub.id)
.maybeSingle();
locationData = data;
if (locationError) {
handleNonCriticalError(locationError, {
action: 'Fetch Park Submission Location',
metadata: { parkSubmissionId: parkSub.id, submissionId }
});
// Continue without location data - non-critical
} else {
locationData = data;
}
}
item_data = {

View File

@@ -213,7 +213,7 @@ serve(async (req) => {
);
// Log notification in notification_logs with idempotency key
await supabase.from('notification_logs').insert({
const { error: logError } = await supabase.from('notification_logs').insert({
user_id: '00000000-0000-0000-0000-000000000000', // Topic-based
notification_type: 'moderation_submission',
idempotency_key: idempotencyKey,
@@ -225,6 +225,16 @@ serve(async (req) => {
}
});
if (logError) {
// Non-blocking - notification was sent successfully, log failure shouldn't fail the request
edgeLogger.warn('Failed to log notification in notification_logs', {
action: 'notify_moderators',
requestId: tracking.requestId,
error: logError.message,
submissionId: submission_id
});
}
const duration = endRequest(tracking);
edgeLogger.info('Successfully notified all moderators via topic', {
action: 'notify_moderators',

View File

@@ -213,14 +213,19 @@ const handler = async (req: Request) => {
console.error(`[${requestId}] Approval transaction failed:`, rpcError);
// Update idempotency key to failed
await supabase
.from('submission_idempotency_keys')
.update({
status: 'failed',
error_message: rpcError.message,
completed_at: new Date().toISOString()
})
.eq('idempotency_key', idempotencyKey);
try {
await supabase
.from('submission_idempotency_keys')
.update({
status: 'failed',
error_message: rpcError.message,
completed_at: new Date().toISOString()
})
.eq('idempotency_key', idempotencyKey);
} catch (updateError) {
console.error(`[${requestId}] Failed to update idempotency key to failed:`, updateError);
// Non-blocking - continue with error response even if idempotency update fails
}
return new Response(
JSON.stringify({
@@ -242,14 +247,19 @@ const handler = async (req: Request) => {
console.log(`[${requestId}] Transaction completed successfully:`, result);
// STEP 8: Success - update idempotency key
await supabase
.from('submission_idempotency_keys')
.update({
status: 'completed',
result_data: result,
completed_at: new Date().toISOString()
})
.eq('idempotency_key', idempotencyKey);
try {
await supabase
.from('submission_idempotency_keys')
.update({
status: 'completed',
result_data: result,
completed_at: new Date().toISOString()
})
.eq('idempotency_key', idempotencyKey);
} catch (updateError) {
console.error(`[${requestId}] Failed to update idempotency key to completed:`, updateError);
// Non-blocking - transaction succeeded, so continue with success response
}
return new Response(
JSON.stringify(result),

View File

@@ -108,7 +108,7 @@ serve(withRateLimit(async (req) => {
const requestOrigin = req.headers.get('origin');
const allowedOrigin = getAllowedOrigin(requestOrigin);
// Check if this is a CORS request with a disallowed origin
// Check if this is a CORS request with a disallowed origin
if (requestOrigin && !allowedOrigin) {
edgeLogger.warn('CORS request rejected', { action: 'cors_validation', origin: requestOrigin, requestId: tracking.requestId });
return new Response(
@@ -123,6 +123,7 @@ serve(withRateLimit(async (req) => {
);
}
// Define CORS headers at function scope so they're available in catch block
const corsHeaders = getCorsHeaders(allowedOrigin);
// Handle CORS preflight requests