fix(backend): correct lowercase column names in dashboard stats query (datavencimento, dentistaid); fix notificacoes routes to use PG syntax; exclude base/ from .gitignore
This commit is contained in:
@@ -3,3 +3,11 @@ gcal_key.json
|
||||
ssh_alerts_config.json
|
||||
*.log
|
||||
.DS_Store
|
||||
|
||||
# Diretório BASE: ambiente de laboratório separado, NÃO deve ir a produção
|
||||
base/
|
||||
|
||||
# Scripts de diagnóstico temporários
|
||||
backend/test-db-users.js
|
||||
backend/test-db-users.cjs
|
||||
backend/pg-convert.js
|
||||
|
||||
+9
-9
@@ -502,20 +502,20 @@ app.get('/api/dashboard/stats', async (req, res) => {
|
||||
// Growth data (last 6 months)
|
||||
const { rows: growth } = await pool.query(`
|
||||
SELECT
|
||||
TO_CHAR("dataVencimento", 'YYYY-MM') as mes,
|
||||
TO_CHAR(datavencimento, 'YYYY-MM') as mes,
|
||||
SUM(CASE WHEN tipo = 'RECEITA' OR tipo IS NULL THEN valor ELSE 0 END) as receita,
|
||||
SUM(CASE WHEN tipo = 'DESPESA' THEN valor ELSE 0 END) as despesa
|
||||
FROM financeiro
|
||||
WHERE "dataVencimento" >= CURRENT_DATE - INTERVAL '6 months'
|
||||
GROUP BY TO_CHAR("dataVencimento", 'YYYY-MM')
|
||||
WHERE datavencimento >= CURRENT_DATE - INTERVAL '6 months'
|
||||
GROUP BY TO_CHAR(datavencimento, 'YYYY-MM')
|
||||
ORDER BY mes ASC
|
||||
`);
|
||||
|
||||
// Recent appointments with patient and dentist names
|
||||
const { rows: recent } = await pool.query(`
|
||||
SELECT a.*, d.nome as "dentistaNome"
|
||||
SELECT a.*, d.nome as dentistanome
|
||||
FROM agendamentos a
|
||||
LEFT JOIN dentistas d ON a."dentistaId" = d.id
|
||||
LEFT JOIN dentistas d ON a.dentistaid = d.id
|
||||
ORDER BY a.start_time DESC
|
||||
LIMIT 5
|
||||
`);
|
||||
@@ -544,28 +544,28 @@ app.get('/api/dashboard/stats', async (req, res) => {
|
||||
// --- NOTIFICACOES ---
|
||||
app.get('/api/notificacoes', async (req, res) => {
|
||||
try {
|
||||
const [rows] = await pool.query('SELECT * FROM notificacoes ORDER BY data DESC LIMIT 100');
|
||||
const { rows } = await pool.query('SELECT * FROM notificacoes ORDER BY data DESC LIMIT 100');
|
||||
res.json(rows.map(n => ({ ...n, lida: !!n.lida })));
|
||||
} catch (err) { res.status(500).json({ error: err.message }); }
|
||||
});
|
||||
|
||||
app.post('/api/notificacoes/read-all', async (req, res) => {
|
||||
try {
|
||||
await pool.query('UPDATE notificacoes SET lida = 1 WHERE lida = 0');
|
||||
await pool.query('UPDATE notificacoes SET lida = true WHERE lida = false');
|
||||
res.json({ success: true });
|
||||
} catch (err) { res.status(500).json({ error: err.message }); }
|
||||
});
|
||||
|
||||
app.delete('/api/notificacoes/:id', async (req, res) => {
|
||||
try {
|
||||
await pool.query('DELETE FROM notificacoes WHERE id = ?', [req.params.id]);
|
||||
await pool.query('DELETE FROM notificacoes WHERE id = $1', [req.params.id]);
|
||||
res.json({ success: true });
|
||||
} catch (err) { res.status(500).json({ error: err.message }); }
|
||||
});
|
||||
|
||||
app.put('/api/notificacoes/:id/read', async (req, res) => {
|
||||
try {
|
||||
await pool.query('UPDATE notificacoes SET lida = 1 WHERE id = ?', [req.params.id]);
|
||||
await pool.query('UPDATE notificacoes SET lida = true WHERE id = $1', [req.params.id]);
|
||||
res.json({ success: true });
|
||||
} catch (err) { res.status(500).json({ error: err.message }); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user