fix: API funcionando com dados reais + dotenv config
- Adiciona dotenv para carregar variáveis de ambiente - Configura DB_HOST para servidor remoto (176.9.3.158) - Cria endpoint /api/diagnostic para testes - Actualiza título: "Plan EAL" → "Dashboard Descomplicar" - Adiciona tsconfig.json para pasta /api - Fix: Carrega .env antes de inicializar MySQL pool Tarefa: #1556 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
76
api/routes/diagnostic.ts
Normal file
76
api/routes/diagnostic.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Diagnostic API Route
|
||||
* @author Descomplicar® | @link descomplicar.pt | @copyright 2026
|
||||
*/
|
||||
import { Router } from 'express'
|
||||
import type { Request, Response } from 'express'
|
||||
import * as dashboardService from '../services/dashboard.js'
|
||||
import * as calendarService from '../services/calendar.js'
|
||||
import db from '../db.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.get('/', async (req: Request, res: Response) => {
|
||||
const tests = []
|
||||
|
||||
// Test database connection
|
||||
try {
|
||||
await db.query('SELECT 1')
|
||||
tests.push({ name: 'DB Connection', status: 'OK' })
|
||||
} catch (error: any) {
|
||||
tests.push({ name: 'DB Connection', status: 'FAILED', error: error.message })
|
||||
}
|
||||
|
||||
// Test each dashboard service function
|
||||
const functions = [
|
||||
{ name: 'getUrgenteTasks', fn: dashboardService.getUrgenteTasks },
|
||||
{ name: 'getAltaTasks', fn: dashboardService.getAltaTasks },
|
||||
{ name: 'getVencidasTasks', fn: dashboardService.getVencidasTasks },
|
||||
{ name: 'getEmTestesTasks', fn: dashboardService.getEmTestesTasks },
|
||||
{ name: 'getEstaSemana', fn: dashboardService.getEstaSemana },
|
||||
{ name: 'getMondayMood', fn: dashboardService.getMondayMood },
|
||||
{ name: 'getTickets', fn: dashboardService.getTickets },
|
||||
{ name: 'getContactarLeads', fn: dashboardService.getContactarLeads },
|
||||
{ name: 'getFollowupLeads', fn: dashboardService.getFollowupLeads },
|
||||
{ name: 'getPropostaLeads', fn: dashboardService.getPropostaLeads },
|
||||
{ name: 'getProjectos', fn: dashboardService.getProjectos },
|
||||
{ name: 'getTimesheet', fn: dashboardService.getTimesheet },
|
||||
{ name: 'getBilling360', fn: dashboardService.getBilling360 },
|
||||
{ name: 'getPipeline', fn: dashboardService.getPipeline }
|
||||
]
|
||||
|
||||
for (const { name, fn } of functions) {
|
||||
try {
|
||||
await fn()
|
||||
tests.push({ name, status: 'OK' })
|
||||
} catch (error: any) {
|
||||
tests.push({ name, status: 'FAILED', error: error.message })
|
||||
}
|
||||
}
|
||||
|
||||
// Test calendar functions
|
||||
try {
|
||||
await calendarService.getTodayEvents()
|
||||
tests.push({ name: 'getTodayEvents', status: 'OK' })
|
||||
} catch (error: any) {
|
||||
tests.push({ name: 'getTodayEvents', status: 'FAILED', error: error.message })
|
||||
}
|
||||
|
||||
try {
|
||||
await calendarService.getWeekEvents()
|
||||
tests.push({ name: 'getWeekEvents', status: 'OK' })
|
||||
} catch (error: any) {
|
||||
tests.push({ name: 'getWeekEvents', status: 'FAILED', error: error.message })
|
||||
}
|
||||
|
||||
const failed = tests.filter(t => t.status === 'FAILED')
|
||||
const summary = {
|
||||
total: tests.length,
|
||||
passed: tests.filter(t => t.status === 'OK').length,
|
||||
failed: failed.length
|
||||
}
|
||||
|
||||
res.json({ summary, tests, failed })
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user