Files
DashDescomplicar/api/routes/diagnostic.ts

77 lines
2.6 KiB
TypeScript

/**
* 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