Test
This commit is contained in:
49
scripts/scheduleRoundRobin.js
Normal file
49
scripts/scheduleRoundRobin.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const fetch = require('node-fetch');
|
||||
const readline = require('readline');
|
||||
|
||||
async function prompt(question) {
|
||||
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
||||
return new Promise(resolve => rl.question(question, ans => { rl.close(); resolve(ans); }));
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const username = process.env.ADMIN_USERNAME || await prompt('Admin username: ');
|
||||
const password = process.env.ADMIN_PASSWORD || await prompt('Admin password: ');
|
||||
let minTeamsPerPool = 3;
|
||||
const minTeamsInput = await prompt('Minimum teams per pool (default 3): ');
|
||||
if (minTeamsInput && !isNaN(parseInt(minTeamsInput))) {
|
||||
minTeamsPerPool = parseInt(minTeamsInput);
|
||||
}
|
||||
|
||||
// Login as admin
|
||||
const loginRes = await fetch('http://localhost:4000/api/admin/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
const loginData = await loginRes.json();
|
||||
if (!loginRes.ok || !loginData.token) {
|
||||
console.error('Admin login failed:', loginData.error || loginRes.statusText);
|
||||
process.exit(1);
|
||||
}
|
||||
const token = loginData.token;
|
||||
console.log('Admin login successful. Scheduling round robin matches...');
|
||||
|
||||
// Call schedule round robin endpoint
|
||||
const scheduleRes = await fetch('http://localhost:4000/api/admin/schedule/roundrobin', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ minTeamsPerPool })
|
||||
});
|
||||
const scheduleData = await scheduleRes.json();
|
||||
if (scheduleRes.ok) {
|
||||
console.log('Round robin scheduled:', scheduleData);
|
||||
} else {
|
||||
console.error('Failed to schedule round robin:', scheduleData.error || scheduleRes.statusText);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user