changes
This commit is contained in:
35
frontend/src/services/admin.js
Normal file
35
frontend/src/services/admin.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user