ADD: added database connection for players data handling and started login funtion with database

This commit is contained in:
hwinkel
2025-05-30 15:02:23 +02:00
parent 4158b87576
commit 1a2eec44a9
19 changed files with 924 additions and 58 deletions

View File

@@ -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',