Refactor: Update edge function for counts

This commit is contained in:
gpt-engineer-app[bot]
2025-10-02 16:40:37 +00:00
parent 3c7de96bcf
commit ae74fa5677
3 changed files with 117 additions and 0 deletions

View File

@@ -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;
}
}