ft_transcendence/frontend/static/js/api/tournament/tournaments.js
2023-12-20 19:15:47 +01:00

33 lines
655 B
JavaScript

import { Client } from "./client.js";
class Tourmanents
{
/**
* @param {Client} client
*/
constructor(client)
{
/**
* @type {Client}
*/
this.client = client
}
async createTournament(nb_players, online)
{
if (online)
return "offline";
let response = await this.client._post("/api/tournaments/", {numbers_of_players: nb_players});
let response_data = await response.json();
if (JSON.stringify(response_data) === JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
{
this.client._update_logged(false);
return null;
}
return response_data.tournament_id;
}
}
export { Tourmanents }