Compare commits
3 Commits
9e52b2e44f
...
4ce1e9aedb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ce1e9aedb | ||
|
|
fc8a5e47a0 | ||
|
|
174bb4841e |
@@ -90,7 +90,8 @@ const formatRow = (row) => ({
|
|||||||
Quantidade: row.quantidade,
|
Quantidade: row.quantidade,
|
||||||
Valor_Unitario: parseFloat(row.valor_unitario),
|
Valor_Unitario: parseFloat(row.valor_unitario),
|
||||||
Recebido_Em: row.created_at,
|
Recebido_Em: row.created_at,
|
||||||
ID_Pedido: row.pedido_id
|
ID_Pedido: row.pedido_id,
|
||||||
|
Fone_Cliente: row.cliente_fone
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET data (for the frontend)
|
// GET data (for the frontend)
|
||||||
@@ -177,11 +178,6 @@ 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`);
|
|
||||||
});;
|
|
||||||
|
|
||||||
app.listen(PORT, '0.0.0.0', () => {
|
app.listen(PORT, '0.0.0.0', () => {
|
||||||
console.log(`Nexstar Backend running at http://localhost:${PORT}`);
|
console.log(`Nexstar Backend running at http://localhost:${PORT}`);
|
||||||
console.log(`Endpoint for n8n: POST http://localhost:${PORT}/api/data`);
|
console.log(`Endpoint for n8n: POST http://localhost:${PORT}/api/data`);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useParams, Link, useOutletContext } from 'react-router-dom';
|
import { useParams, Link, useOutletContext } from 'react-router-dom';
|
||||||
import { ArrowLeft, User, Tag, Package, DollarSign, Clock } from 'lucide-react';
|
import { ArrowLeft, User, Tag, Package, DollarSign, Clock, Phone } from 'lucide-react';
|
||||||
import type { OrderData } from '../types';
|
import type { OrderData } from '../types';
|
||||||
import { parseOrderDate } from '../dataService';
|
import { parseOrderDate } from '../dataService';
|
||||||
|
|
||||||
@@ -9,18 +9,20 @@ const ClientDetails = () => {
|
|||||||
const decodedName = name ? decodeURIComponent(name) : '';
|
const decodedName = name ? decodeURIComponent(name) : '';
|
||||||
const { ordersData } = useOutletContext<{ ordersData: OrderData[] }>();
|
const { ordersData } = useOutletContext<{ ordersData: OrderData[] }>();
|
||||||
|
|
||||||
const { groupedOrders, totalSpent, totalItems } = useMemo(() => {
|
const { groupedOrders, totalSpent, totalItems, clientPhone } = useMemo(() => {
|
||||||
const orders = ordersData;
|
const orders = ordersData;
|
||||||
const clientOrders = orders.filter(order => {
|
const clientOrders = orders.filter(order => {
|
||||||
const clientName = order.Nome_Cliente || `Cliente Desconhecido (Pedido ${order.Valor_Pedido})`;
|
const clientName = order.Nome_Cliente || `Cliente Desconhecido (Pedido ${order.Valor_Pedido})`;
|
||||||
return clientName === decodedName;
|
return clientName === decodedName;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let clientPhone = '';
|
||||||
const groupedOrdersMap: Record<string, { date: string, orderId: string, orderTotal: number, items: OrderData[] }> = {};
|
const groupedOrdersMap: Record<string, { date: string, orderId: string, orderTotal: number, items: OrderData[] }> = {};
|
||||||
let totalSpent = 0;
|
let totalSpent = 0;
|
||||||
let totalItems = 0;
|
let totalItems = 0;
|
||||||
|
|
||||||
clientOrders.forEach(order => {
|
clientOrders.forEach(order => {
|
||||||
|
if (order.Fone_Cliente && !clientPhone) clientPhone = order.Fone_Cliente;
|
||||||
totalSpent += (order.Quantidade * order.Valor_Unitario);
|
totalSpent += (order.Quantidade * order.Valor_Unitario);
|
||||||
totalItems += order.Quantidade;
|
totalItems += order.Quantidade;
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ const ClientDetails = () => {
|
|||||||
return parseOrderDate(b.date).getTime() - parseOrderDate(a.date).getTime();
|
return parseOrderDate(b.date).getTime() - parseOrderDate(a.date).getTime();
|
||||||
});
|
});
|
||||||
|
|
||||||
return { groupedOrders, totalSpent, totalItems };
|
return { groupedOrders, totalSpent, totalItems, clientPhone };
|
||||||
}, [decodedName, ordersData]);
|
}, [decodedName, ordersData]);
|
||||||
|
|
||||||
const formatCurrency = (value: number) => {
|
const formatCurrency = (value: number) => {
|
||||||
@@ -74,7 +76,18 @@ const ClientDetails = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold text-zinc-900 dark:text-dark-text">{decodedName}</h1>
|
<h1 className="text-2xl font-bold text-zinc-900 dark:text-dark-text">{decodedName}</h1>
|
||||||
|
<div className="flex items-center gap-3 mt-1">
|
||||||
<p className="text-zinc-500 dark:text-dark-muted font-medium">Histórico completo de compras</p>
|
<p className="text-zinc-500 dark:text-dark-muted font-medium">Histórico completo de compras</p>
|
||||||
|
{clientPhone && (
|
||||||
|
<>
|
||||||
|
<span className="text-zinc-300 dark:text-dark-border">•</span>
|
||||||
|
<span className="flex items-center gap-1.5 text-brand-primary font-bold text-sm bg-brand-primary/10 px-2 py-1 rounded-md">
|
||||||
|
<Phone className="w-3.5 h-3.5" />
|
||||||
|
{clientPhone}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
15
test-fetch.js
Normal file
15
test-fetch.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
async function run() {
|
||||||
|
const loginRes = await fetch('http://localhost:3004/api/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ email: 'admin@admin.com', password: 'admin123' })
|
||||||
|
});
|
||||||
|
const { token } = await loginRes.json();
|
||||||
|
const dataRes = await fetch('http://localhost:3004/api/data?start=2020-01-01&end=2030-01-01', {
|
||||||
|
headers: { 'Authorization': `Bearer ${token}` }
|
||||||
|
});
|
||||||
|
const data = await dataRes.json();
|
||||||
|
const fabricio = data.find(d => d.Nome_Cliente.includes('Teste Hoje'));
|
||||||
|
console.log(fabricio);
|
||||||
|
}
|
||||||
|
run();
|
||||||
Reference in New Issue
Block a user