mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 12:11:17 -05:00
Refactor: Update edge function for counts
This commit is contained in:
@@ -296,6 +296,19 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
||||
.eq('id', rideId);
|
||||
|
||||
if (error) throw new Error(`Failed to update ride: ${error.message}`);
|
||||
|
||||
// Update park ride counts after successful ride update
|
||||
if (data.park_id) {
|
||||
console.log(`Updating ride counts for park ${data.park_id}`);
|
||||
const { error: countError } = await supabase.rpc('update_park_ride_counts', {
|
||||
target_park_id: data.park_id
|
||||
});
|
||||
|
||||
if (countError) {
|
||||
console.error('Failed to update park counts:', countError);
|
||||
}
|
||||
}
|
||||
|
||||
return rideId;
|
||||
} else {
|
||||
console.log('Creating new ride');
|
||||
@@ -307,6 +320,19 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
||||
.single();
|
||||
|
||||
if (error) throw new Error(`Failed to create ride: ${error.message}`);
|
||||
|
||||
// Update park ride counts after successful ride creation
|
||||
if (data.park_id) {
|
||||
console.log(`Updating ride counts for park ${data.park_id}`);
|
||||
const { error: countError } = await supabase.rpc('update_park_ride_counts', {
|
||||
target_park_id: data.park_id
|
||||
});
|
||||
|
||||
if (countError) {
|
||||
console.error('Failed to update park counts:', countError);
|
||||
}
|
||||
}
|
||||
|
||||
return ride.id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user