LasTres/js-src/pj.ts

37 lines
891 B
TypeScript

export interface PJ {
full_name?: string
short_name?: string
nick: string
health: number
mana: number
max_mana: number
max_health: number
race: string
uuid: string
image?: string
experience_to_next_level_complete?: number
experience_to_next_level_current?: number
level: number
}
export async function fetchMyPjs (setError: (set: string | null) => void): Promise<PJ[]> {
const response = await fetch('/my/pjs', {
method: 'GET',
mode: 'same-origin',
cache: 'no-cache'
}).catch((error) => {
console.log(error)
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
}