This commit is contained in:
Emma781227
2026-06-26 11:26:45 +02:00
parent 1cf2a24ede
commit 2d25c91c55
14 changed files with 540 additions and 165 deletions

View File

@@ -0,0 +1,35 @@
function authHeaders() {
return {
'Content-Type': 'application/json',
Authorization: `Bearer ${localStorage.getItem('token')}`,
}
}
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.')
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.')
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.')
return data
}
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.')
return data
}