mise a jour
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user