generated from VLADIMIR/template_frontend
add client
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { Team } from './models'
|
||||
import type { Game, Team } from './models'
|
||||
import { UnauthorizedError } from './UnauthorizedError'
|
||||
|
||||
export const apiGetTeam = async (login: string, password: string): Promise<Team> => {
|
||||
@@ -23,6 +23,53 @@ export const apiGetTeam = async (login: string, password: string): Promise<Team>
|
||||
}
|
||||
}
|
||||
|
||||
export const apiLetsgo = async (login: string, password: string, place: string) => {
|
||||
try {
|
||||
const response = await fetch(getApiUrl("/team/actions"), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-Id": encodeUTF8ToBase64(login),
|
||||
"X-Password": password
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"place": place
|
||||
})
|
||||
})
|
||||
if (response.status === 401) {
|
||||
throw new UnauthorizedError('Ошибка авторизации')
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error(`http error status: ${response.status}`)
|
||||
}
|
||||
return await response.json()
|
||||
} catch (error) {
|
||||
console.error('[apiLetsgo] error:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const apiGetGame = async (login: string, password: string): Promise<Game> => {
|
||||
try {
|
||||
const response = await fetch(getApiUrl("/game"), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Id': encodeUTF8ToBase64(login),
|
||||
'X-Password': password,
|
||||
},
|
||||
})
|
||||
if (response.status === 401) {
|
||||
throw new UnauthorizedError('Ошибка авторизации')
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error(`http error status: ${response.status}`)
|
||||
}
|
||||
return await response.json()
|
||||
} catch (error) {
|
||||
console.error('[apiGetGame] error:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export function getApiUrl(path: string) {
|
||||
const url = 'http://' + window.location.host.split(':')[0] + ':8090' + path
|
||||
return url
|
||||
|
||||
Reference in New Issue
Block a user