ADD: added database connection for players data handling and started login funtion with database
This commit is contained in:
@@ -34,6 +34,63 @@ export async function updateTournament(id: string, data: any, token: string) {
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function createTournament(data: any, token: string) {
|
||||
const res = await fetch(`${API_URL}/tournaments`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!res.ok) throw new Error('Turnier-Erstellung fehlgeschlagen');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function deleteTournament(id: string, token: string) {
|
||||
const res = await fetch(`${API_URL}/tournaments/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
if (!res.ok) throw new Error('Turnier-Löschung fehlgeschlagen');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchPlayers(token: string) {
|
||||
const res = await fetch(`${API_URL}/players`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
if (!res.ok) throw new Error('Fehler beim Laden der Spieler');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function createPlayer(player: { name: string, email: string }, token: string) {
|
||||
const res = await fetch(`${API_URL}/players`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify(player),
|
||||
});
|
||||
if (!res.ok) throw new Error('Spieler-Erstellung fehlgeschlagen');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function updatePlayer(id: string, player: { name?: string, email?: string }, token: string) {
|
||||
const res = await fetch(`${API_URL}/players/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify(player),
|
||||
});
|
||||
if (!res.ok) throw new Error('Spieler-Aktualisierung fehlgeschlagen');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function deletePlayer(id: string, token: string) {
|
||||
const res = await fetch(`${API_URL}/players/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
if (!res.ok) throw new Error('Spieler-Löschung fehlgeschlagen');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
|
||||
export async function registerTeam(id: string, team: { name: string }, token: string) {
|
||||
const res = await fetch(`${API_URL}/tournaments/${id}/register`, {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user