From 9ab3b139481030ce9206d2083ca0836bdd76c726 Mon Sep 17 00:00:00 2001 From: Rodribm10 Date: Mon, 13 Apr 2026 23:54:46 -0300 Subject: [PATCH] feat: catalogoService com queries do reserva_hotel --- src/services/catalogoService.ts | 73 +++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/services/catalogoService.ts diff --git a/src/services/catalogoService.ts b/src/services/catalogoService.ts new file mode 100644 index 0000000..de784fd --- /dev/null +++ b/src/services/catalogoService.ts @@ -0,0 +1,73 @@ +import { supabase } from '@/lib/supabase' +import type { Database } from '@/types/database' + +type Marca = Database['reserva_hotel']['Tables']['marcas']['Row'] +type Unidade = Database['reserva_hotel']['Tables']['unidades']['Row'] +type Preco = Database['reserva_hotel']['Tables']['precos']['Row'] +type Foto = Database['reserva_hotel']['Tables']['fotos_categoria']['Row'] +type Extra = Database['reserva_hotel']['Tables']['extras']['Row'] + +export const catalogoService = { + async listMarcas(): Promise { + const { data, error } = await supabase + .from('marcas') + .select('*') + .eq('ativa', true) + .order('nome') + if (error) throw new Error(error.message) + return data ?? [] + }, + + async listUnidades(marcaId: string): Promise { + const { data, error } = await supabase + .from('unidades') + .select('*') + .eq('id_marca', marcaId) + .eq('ativa', true) + .order('nome') + if (error) throw new Error(error.message) + return data ?? [] + }, + + async findPreco( + marcaId: string, + categoria: string, + permanencia: string, + periodo = 'default' + ): Promise { + const { data, error } = await supabase + .from('precos') + .select('*') + .eq('id_marca', marcaId) + .eq('categoria', categoria) + .eq('permanencia', permanencia) + .eq('periodo_semana', periodo) + .eq('ativo', true) + .maybeSingle() + if (error) throw new Error(error.message) + return data + }, + + async listFotos(unidadeId: string, categoria: string): Promise { + const { data, error } = await supabase + .from('fotos_categoria') + .select('*') + .eq('id_unidade', unidadeId) + .eq('categoria', categoria) + .eq('ativa', true) + .order('ordem') + if (error) throw new Error(error.message) + return data ?? [] + }, + + async listExtras(marcaId: string): Promise { + const { data, error } = await supabase + .from('extras') + .select('*') + .eq('id_marca', marcaId) + .eq('ativo', true) + .order('ordem') + if (error) throw new Error(error.message) + return data ?? [] + }, +}