ft_transcendence/frontend/static/js/api/tournament/tournament.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-12-20 18:21:18 -05:00
import { Client } from "../client.js";
2023-12-20 13:15:47 -05:00
class Tourmanent
{
/**
* @param {Client} client
*/
2023-12-20 18:21:18 -05:00
constructor(client, name = undefined, nb_players = undefined, nb_players_by_game = undefined, level = undefined, started = undefined, finished = undefined, levels = undefined, id = undefined)
2023-12-20 13:15:47 -05:00
{
/**
* @type {Client}
*/
2023-12-20 18:21:18 -05:00
this.client = client;
2023-12-21 05:35:47 -05:00
this.name = name || `${nb_players_by_game}x1, ${nb_players} players`;
2023-12-20 18:21:18 -05:00
this.nb_players = nb_players;
this.nb_players_by_game = nb_players_by_game;
this.level = level;
this.started = started;
this.finished = finished;
this.levels = levels;
this.state = this.get_state();
this.id = id
2023-12-20 13:15:47 -05:00
}
2023-12-20 18:21:18 -05:00
get_state()
{
if (this.finished)
return "finished";
if (this.started)
return "started";
else
return "waiting";
}
async init(id)
{
let response = await this.client._get(`/api/tournaments/${id}`);
if (response.status === 404)
return 1;
2023-12-20 18:21:18 -05:00
let response_data = await response.json();
2023-12-21 05:35:47 -05:00
this.name = response_data.name || `${response_data.nb_players_by_game}x1, ${response_data.nb_players} players`;
2023-12-20 18:21:18 -05:00
this.nb_players = response_data.nb_players;
this.nb_players_by_game = response_data.nb_players_by_game;
this.level = response_data.level;
this.started = response_data.started;
this.finished = response_data.finished;
this.levels = response_data.levels;
this.id = response_data.id
}
2023-12-20 13:15:47 -05:00
}
export { Tourmanent }