57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
const fetch = require('node-fetch');
|
|
|
|
async function startTournament() {
|
|
try {
|
|
// 1. Login as admin with .env credentials
|
|
console.log('Logging in as admin...');
|
|
const loginRes = await fetch('http://localhost:4000/api/admin/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
username: 'admin',
|
|
password: '0000'
|
|
})
|
|
});
|
|
|
|
if (!loginRes.ok) {
|
|
const error = await loginRes.json();
|
|
console.error('Login failed:', error);
|
|
return;
|
|
}
|
|
|
|
const { token } = await loginRes.json();
|
|
console.log('✅ Login successful!');
|
|
|
|
// 2. Start round robin
|
|
console.log('Starting round robin...');
|
|
const scheduleRes = await fetch('http://localhost:4000/api/admin/schedule/roundrobin', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (scheduleRes.ok) {
|
|
const data = await scheduleRes.json();
|
|
console.log('✅ Round robin started successfully!');
|
|
console.log('Pools created:', data.pools);
|
|
console.log('Matches created:', data.matchesCreated);
|
|
|
|
// 3. Check the created matches
|
|
console.log('Checking created matches...');
|
|
const matchesRes = await fetch('http://localhost:4000/api/matches');
|
|
if (matchesRes.ok) {
|
|
const matches = await matchesRes.json();
|
|
console.log(`✅ Found ${matches.length} matches created`);
|
|
}
|
|
} else {
|
|
const error = await scheduleRes.json();
|
|
console.error('❌ Failed to start round robin:', error);
|
|
}
|
|
} catch (err) {
|
|
console.error('Error:', err.message);
|
|
}
|
|
}
|
|
|
|
startTournament();
|