fix: back buttons missing router instance mapping and fix array structure in supabase route stops fetch
This commit is contained in:
@ -42,17 +42,26 @@ export const routesService = {
|
||||
.eq('route_id', routeId)
|
||||
.order('stop_order', { ascending: true })
|
||||
|
||||
if (error) throw new Error(error.message)
|
||||
if (error) {
|
||||
console.error('getRouteStops Error:', error)
|
||||
throw new Error(error.message)
|
||||
}
|
||||
|
||||
console.log('getRouteStops raw data:', data)
|
||||
|
||||
// Map back to the expected plain array of BusStop with merged properties
|
||||
return (data || []).map((row: any) => ({
|
||||
...row.bus_stops,
|
||||
stop_order: row.stop_order,
|
||||
travel_time_minutes: row.travel_time_minutes,
|
||||
stop_delay_minutes: row.stop_delay_minutes,
|
||||
is_pickup_point: row.is_pickup_point,
|
||||
is_dropoff_point: row.is_dropoff_point
|
||||
})) as BusStop[]
|
||||
return (data || []).map((row: any) => {
|
||||
// Handle possibility of bus_stops being an array or object
|
||||
const busStopData = Array.isArray(row.bus_stops) ? row.bus_stops[0] : row.bus_stops;
|
||||
return {
|
||||
...(busStopData || {}),
|
||||
stop_order: row.stop_order,
|
||||
travel_time_minutes: row.travel_time_minutes,
|
||||
stop_delay_minutes: row.stop_delay_minutes,
|
||||
is_pickup_point: row.is_pickup_point,
|
||||
is_dropoff_point: row.is_dropoff_point
|
||||
}
|
||||
}) as BusStop[]
|
||||
},
|
||||
|
||||
/** Create a new route (Admin) */
|
||||
|
||||
Reference in New Issue
Block a user