first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
// src/services/agendaSlotsBloqueadosService.js
|
||||
import { supabase } from '@/lib/supabase/client'
|
||||
|
||||
export async function fetchSlotsBloqueados(ownerId, diaSemana) {
|
||||
const { data, error } = await supabase
|
||||
.from('agenda_slots_bloqueados_semanais')
|
||||
.select('*')
|
||||
.eq('owner_id', ownerId)
|
||||
.eq('dia_semana', diaSemana)
|
||||
.eq('ativo', true)
|
||||
.order('hora_inicio', { ascending: true })
|
||||
|
||||
if (error) throw error
|
||||
return data || []
|
||||
}
|
||||
|
||||
export async function setSlotBloqueado(ownerId, diaSemana, horaInicio, isBloqueado, motivo = null) {
|
||||
if (isBloqueado) {
|
||||
const { error } = await supabase
|
||||
.from('agenda_slots_bloqueados_semanais')
|
||||
.upsert(
|
||||
{
|
||||
owner_id: ownerId,
|
||||
dia_semana: diaSemana,
|
||||
hora_inicio: horaInicio,
|
||||
motivo: motivo || null,
|
||||
ativo: true
|
||||
},
|
||||
{ onConflict: 'owner_id,dia_semana,hora_inicio' }
|
||||
)
|
||||
if (error) throw error
|
||||
return true
|
||||
}
|
||||
|
||||
// “desbloquear”: deletar (ou marcar ativo=false; aqui vou deletar por simplicidade)
|
||||
const { error } = await supabase
|
||||
.from('agenda_slots_bloqueados_semanais')
|
||||
.delete()
|
||||
.eq('owner_id', ownerId)
|
||||
.eq('dia_semana', diaSemana)
|
||||
.eq('hora_inicio', horaInicio)
|
||||
|
||||
if (error) throw error
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user