async function showTournaments() { let url = 'https://dragonmaster.pl/inz/tournaments'; try { let res = await fetch(url); return await res.json(); } catch (error) { console.log(error); } } function saveIdTournament(id) { localStorage.setItem('tournamentId', id); } function checkRoleCreator() { fetch('https://dragonmaster.pl/inz/user', { headers: { Authorization: ("Bearer " + localStorage.getItem("token")) } }) .then(res => res.json()) .then(json => { let organiser = (json['id']) renderTournaments(organiser) }) } function tournamentDelete(id) { event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation(); console.log(id) fetch('https://dragonmaster.pl/inz/tournament', { method: "DELETE", headers: { 'Content-type': 'application/json', Authorization: ("Bearer " + localStorage.getItem("token")) }, body: JSON.stringify( { "id": id } ) } ) .then(res => res.json()) .then(data => console.log(data)) .catch(error => console.log(error)) } async function renderTournaments(organiserTournament) { let tournaments = await showTournaments(); let html = ''; tournaments.forEach(tournament => { // console.log(test) organiser = `${tournament.creator}`; // console.log(organiser) if (organiser == organiserTournament) { let htmlSegment = `