LasTres/js-src/pj.ts

37 lines
887 B
TypeScript
Raw Normal View History

2023-06-08 09:02:32 +02:00
export interface PJ {
full_name: string
short_name: string
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
level: number
experience_to_next_level_complete: number
experience_to_next_level_current: 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
}