mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 19:11:12 -05:00
Refactor: Implement type safety and error handling
This commit is contained in:
@@ -31,6 +31,7 @@ import OperatorDetail from "./pages/OperatorDetail";
|
||||
import OperatorParks from "./pages/OperatorParks";
|
||||
import Auth from "./pages/Auth";
|
||||
import Profile from "./pages/Profile";
|
||||
import ParkRides from "./pages/ParkRides";
|
||||
import UserSettings from "./pages/UserSettings";
|
||||
import Search from "./pages/Search";
|
||||
import NotFound from "./pages/NotFound";
|
||||
@@ -77,6 +78,7 @@ function AppContent() {
|
||||
<Route path="/" element={<Index />} />
|
||||
<Route path="/parks" element={<Parks />} />
|
||||
<Route path="/parks/:slug" element={<ParkDetail />} />
|
||||
<Route path="/parks/:parkSlug/rides" element={<ParkRides />} />
|
||||
<Route path="/parks/:parkSlug/rides/:rideSlug" element={<RideDetail />} />
|
||||
<Route path="/rides" element={<Rides />} />
|
||||
<Route path="/search" element={<Search />} />
|
||||
|
||||
@@ -2,6 +2,7 @@ import { supabase } from '@/integrations/supabase/client';
|
||||
import type { Json } from '@/integrations/supabase/types';
|
||||
import { ImageAssignments } from '@/components/upload/EntityMultiImageUploader';
|
||||
import { uploadPendingImages } from './imageUploadHelper';
|
||||
import type { ProcessedImage } from './supabaseHelpers';
|
||||
|
||||
/**
|
||||
* ═══════════════════════════════════════════════════════════════════
|
||||
@@ -302,7 +303,7 @@ export async function submitParkUpdate(
|
||||
item_data: {
|
||||
...data,
|
||||
park_id: parkId,
|
||||
images: processedImages as any
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingPark)),
|
||||
status: 'pending',
|
||||
@@ -465,7 +466,7 @@ export async function submitRideUpdate(
|
||||
item_data: {
|
||||
...data,
|
||||
ride_id: rideId,
|
||||
images: processedImages as any
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingRide)),
|
||||
status: 'pending',
|
||||
@@ -724,7 +725,7 @@ export async function submitManufacturerUpdate(
|
||||
...data,
|
||||
company_id: companyId,
|
||||
company_type: 'manufacturer',
|
||||
images: processedImages as any
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
status: 'pending',
|
||||
@@ -832,7 +833,7 @@ export async function submitDesignerUpdate(
|
||||
...data,
|
||||
company_id: companyId,
|
||||
company_type: 'designer',
|
||||
images: processedImages as any
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
status: 'pending',
|
||||
@@ -940,7 +941,7 @@ export async function submitOperatorUpdate(
|
||||
...data,
|
||||
company_id: companyId,
|
||||
company_type: 'operator',
|
||||
images: processedImages as any
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
status: 'pending',
|
||||
@@ -1048,7 +1049,7 @@ export async function submitPropertyOwnerUpdate(
|
||||
...data,
|
||||
company_id: companyId,
|
||||
company_type: 'property_owner',
|
||||
images: processedImages as any
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
status: 'pending',
|
||||
|
||||
55
src/lib/supabaseHelpers.ts
Normal file
55
src/lib/supabaseHelpers.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Type-safe Supabase query helpers
|
||||
*
|
||||
* Provides type-safe table query builders to eliminate `as any` assertions.
|
||||
*/
|
||||
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import type { Database } from '@/integrations/supabase/types';
|
||||
|
||||
// Define valid table names from the database schema
|
||||
export type TableName = keyof Database['public']['Tables'];
|
||||
|
||||
/**
|
||||
* Create a type-safe query builder for a specific table
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const query = createTableQuery('parks').select('*').eq('slug', 'disneyland');
|
||||
* const query2 = createTableQuery('rides').select('id, name').eq('status', 'operating');
|
||||
* ```
|
||||
*/
|
||||
export function createTableQuery<T extends TableName>(tableName: T) {
|
||||
return supabase.from(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically query a table by name with type safety
|
||||
*
|
||||
* Use this when the table name is determined at runtime (e.g., version tables).
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const versions = await queryTable('park_versions', (q) =>
|
||||
* q.select('*').eq('park_id', parkId)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export async function queryTable<T extends TableName>(
|
||||
tableName: T,
|
||||
queryBuilder: (query: ReturnType<typeof createTableQuery<T>>) => any
|
||||
) {
|
||||
const query = createTableQuery(tableName);
|
||||
return queryBuilder(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe interface for processed uploaded images
|
||||
*/
|
||||
export interface ProcessedImage {
|
||||
url: string;
|
||||
cloudflare_id: string;
|
||||
order: number;
|
||||
title?: string;
|
||||
caption?: string;
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import type { EntityType } from '@/types/versioning';
|
||||
import { createTableQuery } from './supabaseHelpers';
|
||||
|
||||
/**
|
||||
* Manually trigger cleanup of old versions for a specific entity type
|
||||
|
||||
Reference in New Issue
Block a user