Agenda, Agendador, Configurações

This commit is contained in:
Leonardo
2026-03-12 08:58:36 -03:00
parent f733db8436
commit f4b185ae17
197 changed files with 33405 additions and 6507 deletions

View File

@@ -0,0 +1,36 @@
-- ═══════════════════════════════════════════════════════════════════════════
-- agendador_check_email
-- Verifica se um e-mail já possui solicitação anterior para este agendador
-- SECURITY DEFINER → anon pode chamar sem burlar RLS diretamente
-- Execute no Supabase SQL Editor
-- ═══════════════════════════════════════════════════════════════════════════
CREATE OR REPLACE FUNCTION public.agendador_check_email(
p_slug text,
p_email text
)
RETURNS boolean
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
DECLARE
v_owner_id uuid;
BEGIN
SELECT c.owner_id INTO v_owner_id
FROM public.agendador_configuracoes c
WHERE c.link_slug = p_slug AND c.ativo = true
LIMIT 1;
IF v_owner_id IS NULL THEN RETURN false; END IF;
RETURN EXISTS (
SELECT 1 FROM public.agendador_solicitacoes s
WHERE s.owner_id = v_owner_id
AND lower(s.paciente_email) = lower(trim(p_email))
LIMIT 1
);
END;
$$;
GRANT EXECUTE ON FUNCTION public.agendador_check_email(text, text) TO anon, authenticated;