feat: contatore tempo allocato, pagina miei ticket, unione ticket (da db)
This commit is contained in:
@@ -4,6 +4,7 @@ const pool = require('../db');
|
||||
|
||||
// GET /api/dashboard/stats — Dashboard statistics
|
||||
router.get('/stats', async (req, res) => {
|
||||
const activeAgentId = parseInt(req.headers['x-agent-id'], 10) || 1;
|
||||
try {
|
||||
// All queries in parallel for speed
|
||||
const [
|
||||
@@ -15,6 +16,7 @@ router.get('/stats', async (req, res) => {
|
||||
totalOpen,
|
||||
recentTickets,
|
||||
escalated,
|
||||
myOpenCount,
|
||||
] = await Promise.all([
|
||||
// Tickets by state (only open-ish states)
|
||||
pool.query(
|
||||
@@ -85,6 +87,16 @@ router.get('/stats', async (req, res) => {
|
||||
WHERE escalation_time > 0
|
||||
AND escalation_time < EXTRACT(EPOCH FROM NOW())`
|
||||
),
|
||||
// My open tickets count
|
||||
pool.query(
|
||||
`SELECT COUNT(*) AS count
|
||||
FROM ticket t
|
||||
JOIN ticket_state ts ON t.ticket_state_id = ts.id
|
||||
JOIN ticket_state_type tst ON ts.type_id = tst.id
|
||||
WHERE tst.name IN ('new', 'open', 'pending reminder', 'pending auto')
|
||||
AND t.user_id = $1`,
|
||||
[activeAgentId]
|
||||
),
|
||||
]);
|
||||
|
||||
res.json({
|
||||
@@ -96,6 +108,7 @@ router.get('/stats', async (req, res) => {
|
||||
total_open: parseInt(totalOpen.rows[0].count),
|
||||
recent_tickets: recentTickets.rows,
|
||||
escalated: parseInt(escalated.rows[0].count),
|
||||
total_my_open: parseInt(myOpenCount.rows[0].count),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error fetching dashboard stats:', err);
|
||||
|
||||
Reference in New Issue
Block a user