2023-06-08 09:02:32 +02:00
|
|
|
export interface PJ {
|
2023-06-27 07:10:56 +02:00
|
|
|
full_name?: string
|
|
|
|
short_name?: string
|
2023-06-08 09:02:32 +02:00
|
|
|
nick: string
|
2023-06-13 02:43:52 +02:00
|
|
|
health: number
|
|
|
|
mana: number
|
2023-06-08 09:02:32 +02:00
|
|
|
max_mana: number
|
2023-06-13 02:43:52 +02:00
|
|
|
max_health: number
|
2023-06-08 09:02:32 +02:00
|
|
|
race: string
|
|
|
|
uuid: string
|
2023-06-13 02:43:52 +02:00
|
|
|
image?: string
|
2023-06-27 07:10:56 +02:00
|
|
|
experience_to_next_level_complete?: number
|
|
|
|
experience_to_next_level_current?: number
|
2023-06-23 21:30:04 +02:00
|
|
|
level: number
|
2023-06-08 09:02:32 +02:00
|
|
|
}
|
|
|
|
|
2023-06-13 02:43:52 +02:00
|
|
|
export async function fetchMyPjs (setError: (set: string | null) => void): Promise<PJ[]> {
|
2023-06-08 09:02:32 +02:00
|
|
|
const response = await fetch('/my/pjs', {
|
|
|
|
method: 'GET',
|
|
|
|
mode: 'same-origin',
|
|
|
|
cache: 'no-cache'
|
|
|
|
}).catch((error) => {
|
2023-06-13 02:43:52 +02:00
|
|
|
console.log(error)
|
2023-06-08 09:02:32 +02:00
|
|
|
setError('Error recuperando tus pjs')
|
|
|
|
})
|
|
|
|
if (response === undefined) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
const statusCode = response.status
|
|
|
|
const data = await response.json()
|
|
|
|
if (statusCode !== 200) {
|
|
|
|
setError(data.error)
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|