Run SQL for webhook trigger
Applies the SQL script to create the webhook trigger.
This commit is contained in:
parent
4c744e5314
commit
0c6978b710
@ -204,6 +204,7 @@ export type Database = {
|
|||||||
Row: {
|
Row: {
|
||||||
ativo: boolean
|
ativo: boolean
|
||||||
created_at: string
|
created_at: string
|
||||||
|
data_pagamento: string | null
|
||||||
descricao: string | null
|
descricao: string | null
|
||||||
dia_vencimento: number
|
dia_vencimento: number
|
||||||
dias_antecedencia: number
|
dias_antecedencia: number
|
||||||
@ -211,14 +212,17 @@ export type Database = {
|
|||||||
hora_aviso: string
|
hora_aviso: string
|
||||||
id: string
|
id: string
|
||||||
nome_conta: string
|
nome_conta: string
|
||||||
|
status: string | null
|
||||||
updated_at: string
|
updated_at: string
|
||||||
user_id: string
|
user_id: string
|
||||||
valor: number | null
|
valor: number | null
|
||||||
|
valor_pago: number | null
|
||||||
whatsapp_usuario: string | null
|
whatsapp_usuario: string | null
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
ativo?: boolean
|
ativo?: boolean
|
||||||
created_at?: string
|
created_at?: string
|
||||||
|
data_pagamento?: string | null
|
||||||
descricao?: string | null
|
descricao?: string | null
|
||||||
dia_vencimento: number
|
dia_vencimento: number
|
||||||
dias_antecedencia?: number
|
dias_antecedencia?: number
|
||||||
@ -226,14 +230,17 @@ export type Database = {
|
|||||||
hora_aviso?: string
|
hora_aviso?: string
|
||||||
id?: string
|
id?: string
|
||||||
nome_conta: string
|
nome_conta: string
|
||||||
|
status?: string | null
|
||||||
updated_at?: string
|
updated_at?: string
|
||||||
user_id: string
|
user_id: string
|
||||||
valor?: number | null
|
valor?: number | null
|
||||||
|
valor_pago?: number | null
|
||||||
whatsapp_usuario?: string | null
|
whatsapp_usuario?: string | null
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
ativo?: boolean
|
ativo?: boolean
|
||||||
created_at?: string
|
created_at?: string
|
||||||
|
data_pagamento?: string | null
|
||||||
descricao?: string | null
|
descricao?: string | null
|
||||||
dia_vencimento?: number
|
dia_vencimento?: number
|
||||||
dias_antecedencia?: number
|
dias_antecedencia?: number
|
||||||
@ -241,9 +248,11 @@ export type Database = {
|
|||||||
hora_aviso?: string
|
hora_aviso?: string
|
||||||
id?: string
|
id?: string
|
||||||
nome_conta?: string
|
nome_conta?: string
|
||||||
|
status?: string | null
|
||||||
updated_at?: string
|
updated_at?: string
|
||||||
user_id?: string
|
user_id?: string
|
||||||
valor?: number | null
|
valor?: number | null
|
||||||
|
valor_pago?: number | null
|
||||||
whatsapp_usuario?: string | null
|
whatsapp_usuario?: string | null
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
|
|||||||
@ -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();
|
||||||
Loading…
Reference in New Issue
Block a user