LasTres/js-src/pj.ts

37 lines
891 B
TypeScript
Raw Normal View History

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
health: number
mana: number
2023-06-08 09:02:32 +02:00
max_mana: number
max_health: number
2023-06-08 09:02:32 +02:00
race: string
uuid: string
image?: string
2023-06-27 07:10:56 +02:00
experience_to_next_level_complete?: number
experience_to_next_level_current?: number
level: number
2023-06-08 09:02:32 +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) => {
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
}