Files
thrilltrack-explorer/supabase/functions/backfill-ride-data/index.ts
gpt-engineer-app[bot] 314db65591 Backfill Ride Data
Add edge function and UI for ride data backfill, integrating admin UI to trigger backfill, plus supporting types and wiring to backfill_ride_data function. Includes RideDataBackfill component, admin page integration, and initial server-side function scaffold for updating rides from submissions.
2025-11-11 15:45:14 +00:00

55 lines
1.5 KiB
TypeScript

import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
import { edgeLogger } from '../_shared/logger.ts';
export default createEdgeFunction(
{
name: 'backfill-ride-data',
requireAuth: true,
},
async (req, context, supabase) => {
edgeLogger.info('Starting ride data backfill', { requestId: context.requestId });
// Check if user is superuser
const { data: profile, error: profileError } = await supabase
.from('user_profiles')
.select('role')
.eq('id', context.user.id)
.single();
if (profileError || profile?.role !== 'superuser') {
edgeLogger.warn('Unauthorized backfill attempt', {
userId: context.user.id,
requestId: context.requestId
});
return new Response(
JSON.stringify({ error: 'Unauthorized: Superuser access required' }),
{ status: 403, headers: { 'Content-Type': 'application/json' } }
);
}
// Execute the backfill function
const { data, error } = await supabase.rpc('backfill_ride_data');
if (error) {
edgeLogger.error('Error running ride data backfill', {
error,
requestId: context.requestId
});
throw error;
}
edgeLogger.info('Ride data backfill completed', {
results: data,
requestId: context.requestId
});
return new Response(
JSON.stringify({
success: true,
...data,
}),
{ headers: { 'Content-Type': 'application/json' } }
);
}
);