🚀 Feat(Core): Migración oficial y total B a Supabase (Auth, DB, APIs) + Eliminación de Backend Python y Fixes Firebase + Soporte Vite Vercel

This commit is contained in:
2026-02-25 21:01:18 -05:00
parent 87752d8214
commit 7cd97365f2
17 changed files with 868 additions and 241 deletions

View File

@ -1,24 +1,32 @@
/** Service for bus stop-related API calls */
import { apiClient } from './apiClient'
import { supabase } from '@/supabase'
import type { BusStop, Route } from '@/types'
export const busStopsService = {
/** Get all bus stops */
async getAllBusStops(): Promise<BusStop[]> {
const response = await apiClient.get<BusStop[]>('/api/bus-stops')
return response.data
const { data, error } = await supabase.from('bus_stops').select('*')
if (error) throw new Error(error.message)
return data as BusStop[]
},
/** Get a single bus stop by ID */
async getBusStopById(id: string): Promise<BusStop> {
const response = await apiClient.get<BusStop>(`/api/bus-stops/${id}`)
return response.data
const { data, error } = await supabase.from('bus_stops').select('*').eq('id', id).single()
if (error) throw new Error(error.message)
return data as BusStop
},
/** Get all routes passing through a bus stop */
async getBusStopRoutes(stopId: string): Promise<Route[]> {
const response = await apiClient.get<Route[]>(`/api/bus-stops/${stopId}/routes`)
return response.data
const { data, error } = await supabase
.from('route_stops')
.select('routes(*)')
.eq('stop_id', stopId)
if (error) throw new Error(error.message)
// Extract the nested strictly typed route object automatically connected by Supabase relationships
return (data || []).map((row: any) => row.routes) as Route[]
},
/** Get estimated next bus arrivals (Mock Data) */
@ -38,20 +46,33 @@ export const busStopsService = {
},
/** Create a new bus stop (Admin) */
async createBusStop(data: import('@/types').BusStopCreate): Promise<BusStop> {
const response = await apiClient.post<BusStop>('/api/bus-stops', data)
return response.data
async createBusStop(currentData: import('@/types').BusStopCreate): Promise<BusStop> {
const { data, error } = await supabase
.from('bus_stops')
.insert([currentData])
.select()
.single()
if (error) throw new Error(error.message)
return data as BusStop
},
/** Update a bus stop (Admin) */
async updateBusStop(id: string, data: import('@/types').BusStopUpdate): Promise<BusStop> {
const response = await apiClient.put<BusStop>(`/api/bus-stops/${id}`, data)
return response.data
async updateBusStop(id: string, currentData: import('@/types').BusStopUpdate): Promise<BusStop> {
const { data, error } = await supabase
.from('bus_stops')
.update(currentData)
.eq('id', id)
.select()
.single()
if (error) throw new Error(error.message)
return data as BusStop
},
/** Delete a bus stop (Admin) */
async deleteBusStop(id: string): Promise<void> {
await apiClient.delete(`/api/bus-stops/${id}`)
const { error } = await supabase.from('bus_stops').delete().eq('id', id)
if (error) throw new Error(error.message)
}
}