40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
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: ');
|
|
|
|
// 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 single elimination bracket...');
|
|
|
|
// Call schedule single elimination endpoint
|
|
const scheduleRes = await fetch('http://localhost:4000/api/admin/schedule/singleelim', {
|
|
method: 'POST',
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
});
|
|
const scheduleData = await scheduleRes.json();
|
|
if (scheduleRes.ok) {
|
|
console.log('Single elimination scheduled:', scheduleData);
|
|
} else {
|
|
console.error('Failed to schedule single elimination:', scheduleData.error || scheduleRes.statusText);
|
|
}
|
|
}
|
|
|
|
main();
|