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:
36
server/api/tracking/index.post.ts
Normal file
36
server/api/tracking/index.post.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { serverSupabaseServiceRole, serverSupabaseClient } from '#supabase/server'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const client = await serverSupabaseClient(event)
|
||||
const { data: { user } } = await client.auth.getUser()
|
||||
if (!user) throw createError({ statusCode: 401, message: 'No autenticado' })
|
||||
|
||||
const body = await readBody(event)
|
||||
const { name, searchParams, routeSummary, intervalHours, expiresAt } = body
|
||||
|
||||
if (!name || !searchParams || !routeSummary) {
|
||||
throw createError({ statusCode: 400, message: 'Faltan campos obligatorios: name, searchParams, routeSummary' })
|
||||
}
|
||||
|
||||
const interval = Math.min(Math.max(intervalHours || 24, 6), 168)
|
||||
|
||||
const supabase = serverSupabaseServiceRole(event)
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('tracked_searches')
|
||||
.insert({
|
||||
user_id: user.id,
|
||||
name,
|
||||
search_params: searchParams,
|
||||
route_summary: routeSummary,
|
||||
interval_hours: interval,
|
||||
next_run_at: new Date().toISOString(),
|
||||
expires_at: expiresAt || null
|
||||
} as never)
|
||||
.select()
|
||||
.single()
|
||||
|
||||
if (error) throw createError({ statusCode: 500, message: error.message })
|
||||
|
||||
return data
|
||||
})
|
||||
Reference in New Issue
Block a user