Initial commit: Vuelato - buscador de vuelos
Some checks failed
ci / ci (22, ubuntu-latest) (push) Has been cancelled
Some checks failed
ci / ci (22, ubuntu-latest) (push) Has been cancelled
Nuxt 4 + Supabase + Flightics API. Incluye búsqueda de vuelos, inspiraciones, watchlist, tracking de precios y mapa interactivo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
26
app/composables/useRouteFlights.ts
Normal file
26
app/composables/useRouteFlights.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { RouteFlightsResponse, PassengersCount, Trip } from '~/server/utils/flightics'
|
||||
|
||||
export function useRouteFlights() {
|
||||
const trips = ref<Trip[]>([])
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
async function fetchRouteFlights(from: string, to: string, passengers?: PassengersCount) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
trips.value = []
|
||||
try {
|
||||
const data = await $fetch<RouteFlightsResponse>('/api/route-flights', {
|
||||
method: 'POST',
|
||||
body: { from, to, locale: 'en', passengersCount: passengers }
|
||||
})
|
||||
trips.value = data.returnResults?.flatMap(r => r.trips) || []
|
||||
} catch (e: any) {
|
||||
error.value = e?.data?.message || e?.message || 'Error loading route flights'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { trips, loading, error, fetchRouteFlights }
|
||||
}
|
||||
Reference in New Issue
Block a user