feat: parse and display n8n order ID instead of data do pedido in client details

This commit is contained in:
Cauê Faleiros
2026-05-08 10:58:36 -03:00
parent 7959e18210
commit e66a90d583
3 changed files with 22 additions and 16 deletions

View File

@@ -124,12 +124,14 @@ app.post('/api/data', authenticateAPIKey, async (req, res) => {
const insertQuery = `
INSERT INTO orders (
cliente_nome, data_pedido, valor_pedido,
produto_id, produto_descricao, quantidade, valor_unitario
) VALUES ($1, $2, $3, $4, $5, $6, $7)
produto_id, produto_descricao, quantidade, valor_unitario, pedido_id
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
`;
for (const item of payload) {
// Handle potential missing fields gracefully
const orderId = item.id || item.ID_Pedido || (item.json && item.json.body && item.json.body.id) || '';
const values = [
item.Nome_Cliente || 'Unknown',
item.Data_Pedido || '',
@@ -137,7 +139,8 @@ app.post('/api/data', authenticateAPIKey, async (req, res) => {
item.ID_Produto || '',
item.Descricao_Produto || '',
item.Quantidade || 0,
item.Valor_Unitario || 0
item.Valor_Unitario || 0,
String(orderId)
];
await client.query(insertQuery, values);
}
@@ -155,4 +158,5 @@ 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`);
});

View File

@@ -16,7 +16,7 @@ const ClientDetails = () => {
return clientName === decodedName;
});
const groupedOrdersMap: Record<string, { date: string, orderTotal: number, items: OrderData[] }> = {};
const groupedOrdersMap: Record<string, { date: string, orderId: string, orderTotal: number, items: OrderData[] }> = {};
let totalSpent = 0;
let totalItems = 0;
@@ -24,11 +24,12 @@ const ClientDetails = () => {
totalSpent += (order.Quantidade * order.Valor_Unitario);
totalItems += order.Quantidade;
// Use date and total order value as a unique cart/order identifier
const key = `${order.Data_Pedido}_${order.Valor_Pedido}`;
// Use ID_Pedido if available, otherwise fallback to date and total order value
const key = order.ID_Pedido || `${order.Data_Pedido}_${order.Valor_Pedido}`;
if (!groupedOrdersMap[key]) {
groupedOrdersMap[key] = {
date: order.Data_Pedido,
orderId: order.ID_Pedido || key,
orderTotal: order.Valor_Pedido,
items: []
};
@@ -89,14 +90,14 @@ const ClientDetails = () => {
</div>
</div>
</div>
{/* Orders List */}
<div className="flex flex-col gap-6">
{/* Orders List */}
<div className="flex flex-col gap-6">
{groupedOrders.map((group, groupIndex) => (
<div key={groupIndex} className="bg-white dark:bg-dark-card border border-zinc-200 dark:border-dark-border rounded-2xl overflow-hidden shadow-sm">
<div className="p-4 border-b border-zinc-100 dark:border-dark-border bg-zinc-50/50 dark:bg-dark-header flex justify-between items-center">
<h2 className="text-sm font-bold uppercase tracking-wider text-zinc-500 dark:text-dark-muted">
Data do Pedido: {group.date}
<h2 className="text-sm font-bold uppercase tracking-wider text-zinc-500 dark:text-dark-muted flex items-center gap-2">
<Tag className="w-4 h-4 text-brand-primary" />
Pedido ID: {group.orderId}
</h2>
<span className="text-sm font-bold text-brand-primary">
Total do Pedido: {formatCurrency(group.orderTotal)}

View File

@@ -7,6 +7,7 @@ export interface OrderData {
Quantidade: number;
Valor_Unitario: number;
Recebido_Em?: string;
ID_Pedido?: string;
}
export interface DateRange {