This commit is contained in:
2025-07-19 12:21:46 +02:00
parent 12822dfdbf
commit 2e7957d0a0
86 changed files with 25573 additions and 0 deletions

101
scripts/resetTournament.js Normal file
View File

@@ -0,0 +1,101 @@
const { PrismaClient } = require('../generated/prisma');
const fetch = require('node-fetch');
const prisma = new PrismaClient();
// Generate SVG logo based on team name
function generateSVGLogo(teamName, size = 40) {
let hash = 0;
for (let i = 0; i < teamName.length; i++) {
hash = teamName.charCodeAt(i) + ((hash << 5) - hash);
}
const hue = Math.abs(hash) % 360;
const saturation = 60 + (Math.abs(hash) % 30);
const lightness = 40 + (Math.abs(hash) % 30);
const color = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
const secondaryHue = (hue + 180) % 360;
const secondaryColor = `hsl(${secondaryHue}, ${saturation}%, ${lightness}%)`;
const pattern = Math.abs(hash) % 4;
const initials = teamName.split(' ').map(w => w[0]).join('').toUpperCase().slice(0, 2);
let svgContent = '';
switch (pattern) {
case 0: // Circle with initials
svgContent = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><circle cx="${size/2}" cy="${size/2}" r="${size/2}" fill="${color}" stroke="${secondaryColor}" stroke-width="2"/><text x="50%" y="55%" text-anchor="middle" font-size="${size/3}" fill="white" font-family="Arial, sans-serif" font-weight="bold">${initials}</text></svg>`;
break;
case 1: // Square with diagonal
svgContent = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><rect x="2" y="2" width="${size-4}" height="${size-4}" fill="${color}" stroke="${secondaryColor}" stroke-width="2"/><line x1="0" y1="0" x2="${size}" y2="${size}" stroke="${secondaryColor}" stroke-width="3"/><text x="50%" y="55%" text-anchor="middle" font-size="${size/3}" fill="white" font-family="Arial, sans-serif" font-weight="bold">${initials}</text></svg>`;
break;
case 2: // Triangle
svgContent = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><polygon points="${size/2},5 ${size-5},${size-5} 5,${size-5}" fill="${color}" stroke="${secondaryColor}" stroke-width="2"/><text x="50%" y="60%" text-anchor="middle" font-size="${size/3}" fill="white" font-family="Arial, sans-serif" font-weight="bold">${initials}</text></svg>`;
break;
case 3: // Diamond
svgContent = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><polygon points="${size/2},5 ${size-5},${size/2} ${size/2},${size-5} 5,${size/2}" fill="${color}" stroke="${secondaryColor}" stroke-width="2"/><text x="50%" y="55%" text-anchor="middle" font-size="${size/3}" fill="white" font-family="Arial, sans-serif" font-weight="bold">${initials}</text></svg>`;
break;
}
return svgContent;
}
async function resetTournament() {
try {
console.log('🗑️ Deleting all existing data...');
// Delete all data in the correct order (due to foreign key constraints)
await prisma.result.deleteMany();
await prisma.match.deleteMany();
await prisma.tournamentStage.deleteMany();
await prisma.tournament.deleteMany();
await prisma.team.deleteMany();
console.log('✅ All existing data deleted');
// Create new tournament
console.log('🏆 Creating new tournament...');
const tournament = await prisma.tournament.create({
data: {
name: 'Championship Tournament',
date: new Date(),
location: 'Main Arena'
}
});
console.log(`✅ Tournament created: ${tournament.name}`);
// Create 15 teams
console.log('👥 Creating 15 teams...');
const teamNames = [
'Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', 'Iota', 'Kappa',
'Lambda', 'Mu', 'Nu', 'Xi', 'Omicron'
];
const teams = [];
for (let i = 0; i < 15; i++) {
const teamName = `Team ${teamNames[i]}`;
const team = await prisma.team.create({
data: {
name: teamName,
logo: generateSVGLogo(teamName)
}
});
teams.push(team);
console.log(`✅ Created ${team.name} with SVG logo`);
}
console.log(`\n🎉 Tournament reset complete!`);
console.log(`📊 Tournament: ${tournament.name}`);
console.log(`👥 Teams: ${teams.length}`);
console.log(`📅 Date: ${tournament.date.toLocaleDateString()}`);
console.log(`📍 Location: ${tournament.location}`);
} catch (err) {
console.error('❌ Error resetting tournament:', err);
} finally {
await prisma.$disconnect();
}
}
resetTournament();