diff --git a/src/controllers/admin.controller.js b/src/controllers/admin.controller.js index 5ac58b9c..d7725b4d 100644 --- a/src/controllers/admin.controller.js +++ b/src/controllers/admin.controller.js @@ -689,6 +689,22 @@ export const getAllTickets = asyncHandler(async (req, res) => { const countResult = await pool.query(countQuery, countParams); const total = parseInt(countResult.rows[0].count); + // Récupérer les stats globales (tous les tickets, sans pagination) + const statsQuery = ` + SELECT + COUNT(*) FILTER (WHERE status = 'PENDING') as pending, + COUNT(*) FILTER (WHERE status = 'CLAIMED') as claimed, + COUNT(*) FILTER (WHERE status = 'REJECTED') as rejected + FROM tickets + `; + const statsResult = await pool.query(statsQuery); + const stats = { + pending: parseInt(statsResult.rows[0].pending) || 0, + claimed: parseInt(statsResult.rows[0].claimed) || 0, + rejected: parseInt(statsResult.rows[0].rejected) || 0, + }; + console.log('📊 Stats calculées:', stats); + res.json({ success: true, data: result.rows, @@ -696,6 +712,7 @@ export const getAllTickets = asyncHandler(async (req, res) => { page: parseInt(page), limit: parseInt(limit), totalPages: Math.ceil(total / limit), + stats, }); });