Add Tiny ERP order metadata ingestion

This commit is contained in:
Cauê Faleiros
2026-06-22 15:02:38 -03:00
parent 0874238fc6
commit 3568e48ce9
8 changed files with 283 additions and 38 deletions

View File

@@ -15,8 +15,9 @@ const upsertOrders = async (payload) => {
const insertQuery = `
INSERT INTO orders (
cliente_nome, data_pedido, data_pedido_date, valor_pedido,
produto_id, produto_descricao, quantidade, valor_unitario, pedido_id, cliente_fone
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
produto_id, produto_descricao, quantidade, valor_unitario, pedido_id, cliente_fone,
cliente_nome_fantasia, id_vendedor, nome_vendedor, marketplace, canal_venda, numero_ecommerce
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
ON CONFLICT (pedido_id, produto_id) DO UPDATE SET
cliente_nome = EXCLUDED.cliente_nome,
data_pedido = EXCLUDED.data_pedido,
@@ -26,6 +27,12 @@ const upsertOrders = async (payload) => {
quantidade = EXCLUDED.quantidade,
valor_unitario = EXCLUDED.valor_unitario,
cliente_fone = EXCLUDED.cliente_fone,
cliente_nome_fantasia = EXCLUDED.cliente_nome_fantasia,
id_vendedor = EXCLUDED.id_vendedor,
nome_vendedor = EXCLUDED.nome_vendedor,
marketplace = EXCLUDED.marketplace,
canal_venda = EXCLUDED.canal_venda,
numero_ecommerce = EXCLUDED.numero_ecommerce,
created_at = CURRENT_TIMESTAMP
`;