81 lines
2.2 KiB
JavaScript
81 lines
2.2 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 createSimpleTicket() {
|
|
try {
|
|
console.log("🎟️ Création d'un ticket de test avec code simple...\n");
|
|
|
|
// Récupérer un client et un prix
|
|
const clientResult = await pool.query(
|
|
"SELECT id FROM users WHERE email = 'client1@example.com'"
|
|
);
|
|
|
|
if (clientResult.rows.length === 0) {
|
|
console.log("❌ Client non trouvé");
|
|
return;
|
|
}
|
|
|
|
const prizeResult = await pool.query(
|
|
"SELECT id, name FROM prizes WHERE type = 'THE_GRATUIT'"
|
|
);
|
|
|
|
if (prizeResult.rows.length === 0) {
|
|
console.log("❌ Prix non trouvé");
|
|
return;
|
|
}
|
|
|
|
const clientId = clientResult.rows[0].id;
|
|
const prizeId = prizeResult.rows[0].id;
|
|
const prizeName = prizeResult.rows[0].name;
|
|
|
|
// Générer un code simple de 10 chiffres
|
|
const simpleCode = Math.floor(1000000000 + Math.random() * 9000000000).toString();
|
|
|
|
// Vérifier si le code existe déjà
|
|
const existingTicket = await pool.query(
|
|
"SELECT id FROM tickets WHERE code = $1",
|
|
[simpleCode]
|
|
);
|
|
|
|
if (existingTicket.rows.length > 0) {
|
|
console.log("⚠️ Ce code existe déjà, réessayez");
|
|
return;
|
|
}
|
|
|
|
// Créer le ticket
|
|
const result = await pool.query(
|
|
`INSERT INTO tickets (code, user_id, prize_id, status, played_at)
|
|
VALUES ($1, $2, $3, 'PENDING', NOW())
|
|
RETURNING id, code`,
|
|
[simpleCode, clientId, prizeId]
|
|
);
|
|
|
|
console.log("✅ Ticket de test créé avec succès!\n");
|
|
console.log("📋 Informations du ticket:");
|
|
console.log(` Code: ${result.rows[0].code}`);
|
|
console.log(` ID: ${result.rows[0].id}`);
|
|
console.log(` Prix: ${prizeName}`);
|
|
console.log(` Utilisateur: client1@example.com`);
|
|
console.log(` Statut: PENDING`);
|
|
console.log("\n🔐 Pour tester:");
|
|
console.log(" Email: client1@example.com");
|
|
console.log(" Password: Client123!");
|
|
|
|
await pool.end();
|
|
} catch (error) {
|
|
console.error("❌ Erreur:", error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
createSimpleTicket();
|