32909/backend/src/routes/publicDashboard.js
2025-07-19 16:34:24 +00:00

39 lines
1.2 KiB
JavaScript

const express = require('express');
const router = express.Router();
const publicDashboardService = require('../services/publicDashboard');
// GET KPIs: total open incidents, overdue actions, inspections completed this month
router.get('/kpis', async (req, res) => {
try {
const kpis = await publicDashboardService.getKPIs();
res.json(kpis);
} catch (error) {
console.error('Error fetching public KPIs:', error);
res.status(500).json({ error: 'Error fetching public KPIs' });
}
});
// GET chart data: incidents by branch
router.get('/charts/incidents-by-branch', async (req, res) => {
try {
const data = await publicDashboardService.getIncidentsByBranch();
res.json(data);
} catch (error) {
console.error('Error fetching incidents by branch:', error);
res.status(500).json({ error: 'Error fetching incidents by branch' });
}
});
// GET chart data: actions status breakdown
router.get('/charts/actions-status', async (req, res) => {
try {
const data = await publicDashboardService.getActionsStatus();
res.json(data);
} catch (error) {
console.error('Error fetching actions status:', error);
res.status(500).json({ error: 'Error fetching actions status' });
}
});
module.exports = router;