Run SQL for webhook trigger

Applies the SQL script to create the webhook trigger.
This commit is contained in:
gpt-engineer-app[bot] 2025-06-26 11:51:33 +00:00
parent 4c744e5314
commit 0c6978b710
2 changed files with 42 additions and 0 deletions

View File

@ -204,6 +204,7 @@ export type Database = {
Row: {
ativo: boolean
created_at: string
data_pagamento: string | null
descricao: string | null
dia_vencimento: number
dias_antecedencia: number
@ -211,14 +212,17 @@ export type Database = {
hora_aviso: string
id: string
nome_conta: string
status: string | null
updated_at: string
user_id: string
valor: number | null
valor_pago: number | null
whatsapp_usuario: string | null
}
Insert: {
ativo?: boolean
created_at?: string
data_pagamento?: string | null
descricao?: string | null
dia_vencimento: number
dias_antecedencia?: number
@ -226,14 +230,17 @@ export type Database = {
hora_aviso?: string
id?: string
nome_conta: string
status?: string | null
updated_at?: string
user_id: string
valor?: number | null
valor_pago?: number | null
whatsapp_usuario?: string | null
}
Update: {
ativo?: boolean
created_at?: string
data_pagamento?: string | null
descricao?: string | null
dia_vencimento?: number
dias_antecedencia?: number
@ -241,9 +248,11 @@ export type Database = {
hora_aviso?: string
id?: string
nome_conta?: string
status?: string | null
updated_at?: string
user_id?: string
valor?: number | null
valor_pago?: number | null
whatsapp_usuario?: string | null
}
Relationships: []

View File

@ -0,0 +1,33 @@
-- Criar função que será chamada pelo trigger
CREATE OR REPLACE FUNCTION notify_new_transaction()
RETURNS trigger AS $$
BEGIN
-- Fazer a requisição HTTP para o webhook
PERFORM net.http_post(
url := 'https://webhookn8n.innova1001.com.br/webhook/baixacontas',
headers := '{"Content-Type": "application/json"}'::jsonb,
body := jsonb_build_object(
'id', NEW.id,
'created_at', NEW.created_at,
'user', NEW.user,
'quando', NEW.quando,
'estabelecimento', NEW.estabelecimento,
'valor', NEW.valor,
'detalhes', NEW.detalhes,
'tipo', NEW.tipo,
'categoria', NEW.categoria,
'login', NEW.login,
'grupo_id', NEW.grupo_id
)
);
RETURN NEW;
END;
$$ language plpgsql;
-- Criar trigger que chama a função sempre que uma nova transação for inserida
CREATE TRIGGER trigger_new_transaction_webhook
AFTER INSERT ON public.transacoes
FOR EACH ROW
EXECUTE FUNCTION notify_new_transaction();