31 lines
902 B
JavaScript
31 lines
902 B
JavaScript
function apiError(message, status) {
|
|
const err = new Error(message)
|
|
err.status = status
|
|
return err
|
|
}
|
|
|
|
export async function myGainsApi() {
|
|
const token = localStorage.getItem('token')
|
|
const res = await fetch('/api/game/my-gains', {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
})
|
|
const data = await res.json()
|
|
if (!res.ok) throw apiError(data.message || 'Erreur lors de la récupération des gains.', res.status)
|
|
return data
|
|
}
|
|
|
|
export async function participateApi(code) {
|
|
const token = localStorage.getItem('token')
|
|
const res = await fetch('/api/game/participate', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
body: JSON.stringify({ code }),
|
|
})
|
|
const data = await res.json()
|
|
if (!res.ok) throw apiError(data.message || 'Erreur lors de la participation.', res.status)
|
|
return data
|
|
}
|