fix: include inactive users in draw eligible participants

Users who deleted their account (is_active=false) should still be
eligible for the grand prize draw if they have validated tickets.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
soufiane 2025-11-28 15:06:44 +01:00
parent 9d836eeaac
commit c31480886c

View File

@ -13,6 +13,7 @@ export const getEligibleParticipants = asyncHandler(async (req, res) => {
// Requête pour obtenir les utilisateurs éligibles
// Pour le tirage au sort du gros lot, tous les participants ont une chance égale
// Note: Les utilisateurs inactifs (compte supprimé) sont inclus s'ils ont des tickets validés
const query = `
SELECT
u.id,
@ -20,6 +21,7 @@ export const getEligibleParticipants = asyncHandler(async (req, res) => {
u.first_name,
u.last_name,
u.is_verified,
u.is_active,
u.created_at,
COALESCE(COUNT(DISTINCT t.id), 0) as tickets_played,
COALESCE(COUNT(DISTINCT CASE WHEN t.status = 'CLAIMED' THEN t.id END), 0) as prizes_won
@ -27,7 +29,7 @@ export const getEligibleParticipants = asyncHandler(async (req, res) => {
LEFT JOIN tickets t ON u.id = t.user_id AND t.played_at IS NOT NULL
WHERE u.role = 'CLIENT'
${verified === 'true' ? 'AND u.is_verified = TRUE' : ''}
GROUP BY u.id, u.email, u.first_name, u.last_name, u.is_verified, u.created_at
GROUP BY u.id, u.email, u.first_name, u.last_name, u.is_verified, u.is_active, u.created_at
${parseInt(minTickets) > 0 ? 'HAVING COUNT(DISTINCT t.id) >= $1' : ''}
ORDER BY u.created_at ASC
`;