mise a jour

This commit is contained in:
Emma781227
2026-07-01 22:06:22 +02:00
parent efd10d6754
commit 68a9650223
22 changed files with 719 additions and 167 deletions

View File

@@ -5,24 +5,30 @@ function authHeaders() {
}
}
function apiError(message, status) {
const err = new Error(message)
err.status = status
return err
}
export async function getStatsApi() {
const res = await fetch('/api/admin/stats', { headers: authHeaders() })
const data = await res.json()
if (!res.ok) throw new Error(data.message || 'Erreur stats.')
if (!res.ok) throw apiError(data.message || 'Erreur stats.', res.status)
return data
}
export async function getUsersApi() {
const res = await fetch('/api/admin/users', { headers: authHeaders() })
const data = await res.json()
if (!res.ok) throw new Error(data.message || 'Erreur utilisateurs.')
if (!res.ok) throw apiError(data.message || 'Erreur utilisateurs.', res.status)
return data
}
export async function drawWinnerApi() {
const res = await fetch('/api/admin/draw', { method: 'POST', headers: authHeaders() })
const data = await res.json()
if (!res.ok) throw new Error(data.message || 'Erreur tirage.')
if (!res.ok) throw apiError(data.message || 'Erreur tirage.', res.status)
return data
}
@@ -30,6 +36,6 @@ export async function getWinnerApi() {
const res = await fetch('/api/admin/draw', { headers: authHeaders() })
if (res.status === 404) return null
const data = await res.json()
if (!res.ok) throw new Error(data.message || 'Erreur gagnant.')
if (!res.ok) throw apiError(data.message || 'Erreur gagnant.', res.status)
return data
}