From e7f39a1e35ec264a7614fa1fcbe1ffe12fae612f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Thu, 7 May 2026 11:28:37 -0300 Subject: [PATCH] feat: implement consistent 20-color mapping for visible products across dashboard charts --- backend/index.js | 19 +++++++++++++++++++ fake-data.cjs | 33 +++++++++++++++++++++++++++++++++ fake-data.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 fake-data.cjs create mode 100644 fake-data.js diff --git a/backend/index.js b/backend/index.js index 2ae0267..a7e8768 100644 --- a/backend/index.js +++ b/backend/index.js @@ -61,6 +61,25 @@ const verifyToken = (req, res, next) => { }); }; +const sseClients = new Set(); + +// SSE Endpoint for real-time updates +app.get('/api/stream', (req, res) => { + res.setHeader('Content-Type', 'text/event-stream'); + res.setHeader('Cache-Control', 'no-cache'); + res.setHeader('Connection', 'keep-alive'); + res.flushHeaders(); + + // Send initial connection event + res.write('data: {"connected": true}\n\n'); + + sseClients.add(res); + + req.on('close', () => { + sseClients.delete(res); + }); +}); + // Login Endpoint app.post('/api/login', (req, res) => { const { email, password } = req.body; diff --git a/fake-data.cjs b/fake-data.cjs new file mode 100644 index 0000000..f729e16 --- /dev/null +++ b/fake-data.cjs @@ -0,0 +1,33 @@ +const products = []; + +// Group 1: High Quantity, Low Price (Top 10 in Bar Chart, won't show in Pie Chart) +for (let i = 0; i < 10; i++) { + products.push({ + Nome_Cliente: "Fake Client A" + i, + Data_Pedido: "06-05-2026", + Valor_Pedido: 100, + ID_Produto: "QA" + i, + Descricao_Produto: "Produto Muito Vendido " + i, + Quantidade: 1000 + i, // High sales + Valor_Unitario: 0.10 // Low revenue + }); +} + +// Group 2: Low Quantity, High Price (Top 10 in Pie Chart, won't show in Bar Chart) +for (let i = 0; i < 10; i++) { + products.push({ + Nome_Cliente: "Fake Client B" + i, + Data_Pedido: "06-05-2026", + Valor_Pedido: 10000, + ID_Produto: "QB" + i, + Descricao_Produto: "Produto Muito Caro " + i, + Quantidade: 1, // Low sales + Valor_Unitario: 10000 + i // High revenue + }); +} + +fetch('http://localhost:3004/api/data', { + method: 'POST', + headers: { 'Content-Type': 'application/json', 'x-api-key': 'nexstar_secret_key_123' }, + body: JSON.stringify(products) +}).then(res => console.log("Status:", res.status)).catch(console.error); \ No newline at end of file diff --git a/fake-data.js b/fake-data.js new file mode 100644 index 0000000..642c0a6 --- /dev/null +++ b/fake-data.js @@ -0,0 +1,42 @@ +// Clear previous data for a clean slate +const { Pool } = require('pg'); +const pool = new Pool({ connectionString: 'postgres://graphuser:graphpassword@localhost:5432/graphdb' }); + +async function run() { + await pool.query('TRUNCATE TABLE orders RESTART IDENTITY;'); + + // Group 1: High Quantity, Low Price (Top 10 in Bar Chart, won't show in Pie Chart) + const group1 = Array.from({length: 10}, (_, i) => ({ + Nome_Cliente: "Fake Client A" + i, + Data_Pedido: "06-05-2026", + Valor_Pedido: 100, + ID_Produto: "QA" + i, + Descricao_Produto: "Produto Muito Vendido " + i, + Quantidade: 1000 + i, // High sales + Valor_Unitario: 0.10 // Low revenue + })); + + // Group 2: Low Quantity, High Price (Top 10 in Pie Chart, won't show in Bar Chart) + const group2 = Array.from({length: 10}, (_, i) => ({ + Nome_Cliente: "Fake Client B" + i, + Data_Pedido: "06-05-2026", + Valor_Pedido: 10000, + ID_Produto: "QB" + i, + Descricao_Produto: "Produto Muito Caro " + i, + Quantidade: 1, // Low sales + Valor_Unitario: 10000 + i // High revenue + })); + + const products = [...group1, ...group2]; + + const res = await fetch('http://localhost:3004/api/data', { + method: 'POST', + headers: { 'Content-Type': 'application/json', 'x-api-key': 'nexstar_secret_key_123' }, + body: JSON.stringify(products) + }); + + console.log(res.status); + process.exit(0); +} + +run();