fix: safely parse n8n stringified numbers and add ID_Pedido to API response
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m16s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m16s
This commit is contained in:
@@ -38,6 +38,9 @@ const initDB = async () => {
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`);
|
||||
|
||||
await pool.query(`ALTER TABLE orders ADD COLUMN IF NOT EXISTS pedido_id VARCHAR(100);`).catch(() => {});
|
||||
|
||||
console.log("Database initialized successfully.");
|
||||
} catch (err) {
|
||||
console.error("Failed to initialize database:", err);
|
||||
@@ -81,7 +84,8 @@ const formatRow = (row) => ({
|
||||
Descricao_Produto: row.produto_descricao,
|
||||
Quantidade: row.quantidade,
|
||||
Valor_Unitario: parseFloat(row.valor_unitario),
|
||||
Recebido_Em: row.created_at
|
||||
Recebido_Em: row.created_at,
|
||||
ID_Pedido: row.pedido_id
|
||||
});
|
||||
|
||||
// GET data (for the frontend)
|
||||
@@ -135,11 +139,11 @@ app.post('/api/data', authenticateAPIKey, async (req, res) => {
|
||||
const values = [
|
||||
item.Nome_Cliente || 'Unknown',
|
||||
item.Data_Pedido || '',
|
||||
item.Valor_Pedido || 0,
|
||||
parseFloat(item.Valor_Pedido) || 0,
|
||||
item.ID_Produto || '',
|
||||
item.Descricao_Produto || '',
|
||||
item.Quantidade || 0,
|
||||
item.Valor_Unitario || 0,
|
||||
parseInt(item.Quantidade) || 0,
|
||||
parseFloat(item.Valor_Unitario) || 0,
|
||||
String(orderId)
|
||||
];
|
||||
await client.query(insertQuery, values);
|
||||
@@ -158,5 +162,4 @@ app.post('/api/data', authenticateAPIKey, async (req, res) => {
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`Nexstar Backend running at http://localhost:${PORT}`);
|
||||
console.log(`Endpoint for n8n: POST http://localhost:${PORT}/api/data`);
|
||||
});ORT}/api/data`);
|
||||
});
|
||||
Reference in New Issue
Block a user