Ajuste em Massa - Paciente, Terapeuta, Clinica e Admin - Inicio agenda

This commit is contained in:
Leonardo
2026-02-22 17:56:01 -03:00
parent 6eff67bf22
commit 89b4ecaba1
77 changed files with 9433 additions and 1995 deletions

View File

@@ -0,0 +1,98 @@
// src/features/agenda/services/agendaRepository.js
import { supabase } from '@/lib/supabase/client'
export async function getMyAgendaSettings () {
const { data: userRes, error: userErr } = await supabase.auth.getUser()
if (userErr) throw userErr
const uid = userRes?.user?.id
if (!uid) throw new Error('Usuário não autenticado.')
const { data, error } = await supabase
.from('agenda_configuracoes')
.select('*')
.eq('owner_id', uid)
.single()
if (error) throw error
return data
}
export async function listMyAgendaEvents ({ startISO, endISO }) {
const { data: userRes, error: userErr } = await supabase.auth.getUser()
if (userErr) throw userErr
const uid = userRes?.user?.id
if (!uid) throw new Error('Usuário não autenticado.')
const { data, error } = await supabase
.from('agenda_eventos')
.select('*')
.eq('owner_id', uid)
.gte('inicio_em', startISO)
.lt('inicio_em', endISO)
.order('inicio_em', { ascending: true })
if (error) throw error
return data || []
}
export async function listClinicEvents ({ ownerIds, startISO, endISO }) {
if (!ownerIds?.length) return []
const { data, error } = await supabase
.from('agenda_eventos')
.select('*')
.in('owner_id', ownerIds)
.gte('inicio_em', startISO)
.lt('inicio_em', endISO)
.order('inicio_em', { ascending: true })
if (error) throw error
return data || []
}
export async function listTenantStaff (tenantId) {
if (!tenantId || tenantId === 'null' || tenantId === 'undefined') return []
const { data, error } = await supabase
.from('v_tenant_staff')
.select('*')
.eq('tenant_id', tenantId)
if (error) throw error
return data || []
}
export async function createAgendaEvento (payload) {
const { data, error } = await supabase
.from('agenda_eventos')
.insert(payload)
.select('*')
.single()
if (error) throw error
return data
}
export async function updateAgendaEvento (id, patch) {
const { data, error } = await supabase
.from('agenda_eventos')
.update(patch)
.eq('id', id)
.select('*')
.single()
if (error) throw error
return data
}
export async function deleteAgendaEvento (id) {
const { error } = await supabase
.from('agenda_eventos')
.delete()
.eq('id', id)
if (error) throw error
return true
}