feat: add global ticket stats to getAllTickets endpoint

Returns pending, claimed, rejected counts for all tickets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
soufiane 2025-12-03 19:35:25 +01:00
parent 6da53c3058
commit 4ab63ad068

View File

@ -689,6 +689,22 @@ export const getAllTickets = asyncHandler(async (req, res) => {
const countResult = await pool.query(countQuery, countParams); const countResult = await pool.query(countQuery, countParams);
const total = parseInt(countResult.rows[0].count); 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({ res.json({
success: true, success: true,
data: result.rows, data: result.rows,
@ -696,6 +712,7 @@ export const getAllTickets = asyncHandler(async (req, res) => {
page: parseInt(page), page: parseInt(page),
limit: parseInt(limit), limit: parseInt(limit),
totalPages: Math.ceil(total / limit), totalPages: Math.ceil(total / limit),
stats,
}); });
}); });