97 lines
2.8 KiB
JavaScript
97 lines
2.8 KiB
JavaScript
import pkg from "pg";
|
|
const { Pool } = pkg;
|
|
|
|
// Configuration de la base de données
|
|
const pool = new Pool({
|
|
host: "51.75.24.29",
|
|
port: 5433,
|
|
user: "postgres",
|
|
password: "postgres",
|
|
database: "thetiptop_dev",
|
|
});
|
|
|
|
async function getTickets() {
|
|
try {
|
|
console.log("🔍 Récupération des tickets...\n");
|
|
|
|
// Requête pour récupérer tous les tickets
|
|
const result = await pool.query(`
|
|
SELECT
|
|
t.id,
|
|
t.code,
|
|
t.status,
|
|
t.played_at,
|
|
t.claimed_at,
|
|
t.validated_at,
|
|
u.email as user_email,
|
|
u.first_name || ' ' || u.last_name as user_name,
|
|
p.name as prize_name,
|
|
p.type as prize_type,
|
|
v.first_name || ' ' || v.last_name as validated_by_name
|
|
FROM tickets t
|
|
JOIN users u ON t.user_id = u.id
|
|
JOIN prizes p ON t.prize_id = p.id
|
|
LEFT JOIN users v ON t.validated_by = v.id
|
|
ORDER BY t.played_at DESC
|
|
`);
|
|
|
|
console.log(`📊 Total de tickets: ${result.rows.length}\n`);
|
|
|
|
if (result.rows.length === 0) {
|
|
console.log("❌ Aucun ticket trouvé dans la base de données");
|
|
} else {
|
|
console.log("📋 Liste des tickets:\n");
|
|
console.log("─".repeat(150));
|
|
|
|
result.rows.forEach((ticket, index) => {
|
|
console.log(`\n${index + 1}. Ticket #${ticket.id}`);
|
|
console.log(` Code: ${ticket.code}`);
|
|
console.log(` Statut: ${ticket.status}`);
|
|
console.log(` Utilisateur: ${ticket.user_name} (${ticket.user_email})`);
|
|
console.log(` Prix: ${ticket.prize_name} (${ticket.prize_type})`);
|
|
console.log(` Joué le: ${ticket.played_at}`);
|
|
|
|
if (ticket.claimed_at) {
|
|
console.log(` Réclamé le: ${ticket.claimed_at}`);
|
|
}
|
|
|
|
if (ticket.validated_at) {
|
|
console.log(` Validé le: ${ticket.validated_at}`);
|
|
console.log(` Validé par: ${ticket.validated_by_name || 'N/A'}`);
|
|
}
|
|
|
|
console.log("─".repeat(150));
|
|
});
|
|
|
|
// Statistiques par statut
|
|
const stats = result.rows.reduce((acc, ticket) => {
|
|
acc[ticket.status] = (acc[ticket.status] || 0) + 1;
|
|
return acc;
|
|
}, {});
|
|
|
|
console.log("\n📊 Statistiques par statut:");
|
|
Object.entries(stats).forEach(([status, count]) => {
|
|
console.log(` ${status}: ${count}`);
|
|
});
|
|
|
|
// Statistiques par type de prix
|
|
const prizeStats = result.rows.reduce((acc, ticket) => {
|
|
acc[ticket.prize_type] = (acc[ticket.prize_type] || 0) + 1;
|
|
return acc;
|
|
}, {});
|
|
|
|
console.log("\n🎁 Statistiques par type de prix:");
|
|
Object.entries(prizeStats).forEach(([type, count]) => {
|
|
console.log(` ${type}: ${count}`);
|
|
});
|
|
}
|
|
|
|
await pool.end();
|
|
} catch (error) {
|
|
console.error("❌ Erreur:", error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
getTickets();
|