Files
vuelato/server/api/profile.patch.ts
Alejandro Martinez b8906efc80
Some checks failed
ci / ci (22, ubuntu-latest) (push) Has been cancelled
Initial commit: Vuelato - buscador de vuelos
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>
2026-04-10 23:37:06 +02:00

29 lines
940 B
TypeScript

import { 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 allowed = ['home_airports', 'default_adults', 'default_children', 'default_infants', 'locale', 'show_origin_time']
const patch: Record<string, unknown> = {}
for (const key of allowed) {
if (body[key] !== undefined) patch[key] = body[key]
}
if (Object.keys(patch).length === 0) {
throw createError({ statusCode: 400, message: 'Nada que actualizar' })
}
const { data, error } = await client
.from('profiles')
.update(patch)
.eq('id', user.id)
.select()
.single()
if (error) throw createError({ statusCode: 500, message: error.message })
return data
})