import { pool } from '../db.js'; const createTestPendingTicket = async () => { try { console.log('๐ŸŽซ Crรฉation d\'un ticket test en attente de validation...\n'); // Trouver un utilisateur client const clientResult = await pool.query(` SELECT id, first_name, last_name, email FROM users WHERE role = 'CLIENT' LIMIT 1 `); if (clientResult.rows.length === 0) { console.log('โŒ Aucun client trouvรฉ dans la base. Crรฉation d\'un client test...\n'); // Crรฉer un client test const newClient = await pool.query(` INSERT INTO users (email, password, first_name, last_name, phone, role, is_verified) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id, first_name, last_name, email `, [ 'test.client@example.com', '$2a$10$abcdefghijklmnopqrstuvwxyz', // dummy hash 'Jean', 'Dupont', '0612345678', 'CLIENT', true ]); const client = newClient.rows[0]; console.log(`โœ… Client crรฉรฉ: ${client.first_name} ${client.last_name} (${client.email})\n`); } // Re-sรฉlectionner le client const client = clientResult.rows.length > 0 ? clientResult.rows[0] : (await pool.query('SELECT id, first_name, last_name, email FROM users WHERE role = $1 LIMIT 1', ['CLIENT'])).rows[0]; // Trouver un ticket disponible (status NULL) const ticketResult = await pool.query(` SELECT t.id, t.code, p.name as prize_name, p.type as prize_type FROM tickets t JOIN prizes p ON t.prize_id = p.id WHERE t.user_id IS NULL AND t.status IS NULL LIMIT 1 `); if (ticketResult.rows.length === 0) { console.log('โŒ Aucun ticket disponible trouvรฉ'); await pool.end(); process.exit(1); } const ticket = ticketResult.rows[0]; // Simuler qu'un client a jouรฉ ce ticket await pool.query(` UPDATE tickets SET user_id = $1, status = 'PENDING', played_at = NOW() WHERE id = $2 `, [client.id, ticket.id]); console.log('โœ… Ticket test crรฉรฉ avec succรจs!\n'); console.log('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•'); console.log('๐Ÿ“‹ Dร‰TAILS DU TICKET TEST:'); console.log('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•'); console.log(`๐ŸŽซ Code ticket: ${ticket.code}`); console.log(`๐Ÿ‘ค Client: ${client.first_name} ${client.last_name}`); console.log(`๐Ÿ“ง Email: ${client.email}`); console.log(`๐ŸŽ Lot gagnรฉ: ${ticket.prize_name}`); console.log(`๐Ÿ“Š Statut: PENDING (en attente de validation)`); console.log('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n'); console.log('๐Ÿ’ก Ce ticket devrait maintenant apparaรฎtre dans l\'interface employรฉ\n'); await pool.end(); process.exit(0); } catch (error) { console.error('โŒ Erreur:', error.message); await pool.end(); process.exit(1); } }; createTestPendingTicket();