Add timer to check if game is started and its your turn and implement gameStateObject from api
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import axios, {AxiosPromise, AxiosRequestConfig, AxiosResponse} from 'axios'
|
||||
import {JoinCreateGameObject, IsStartedObject, ApiObject} from "@/objects/objects";
|
||||
import {JoinCreateGameObject, IsStartedObject, ApiObject, GameStateObject, MyTurnObject} from "@/objects/objects";
|
||||
|
||||
export default class PerudoApi {
|
||||
private static baseUrl = 'http://localhost:8000/'
|
||||
@@ -27,7 +27,7 @@ export default class PerudoApi {
|
||||
})
|
||||
}
|
||||
|
||||
public startedGame(playerId: string): Promise<IsStartedObject> {
|
||||
public gameStarted(playerId: string): Promise<IsStartedObject> {
|
||||
return this.get<IsStartedObject>(PerudoApi.baseUrl + 'game/started/' + playerId)
|
||||
.then((response: AxiosResponse<IsStartedObject>) => {
|
||||
return response.data;
|
||||
@@ -41,8 +41,16 @@ export default class PerudoApi {
|
||||
});
|
||||
}
|
||||
|
||||
public myTurn(playerId: string): Promise<MyTurnObject> {
|
||||
return this.get<MyTurnObject>(PerudoApi.baseUrl + 'player/turn/' + playerId)
|
||||
.then((response: AxiosResponse<MyTurnObject>) => {
|
||||
return response.data;
|
||||
})
|
||||
}
|
||||
|
||||
private get<T extends ApiObject>(url: string, getParameters?: Record<string, any>): AxiosPromise<T> {
|
||||
return axios.get(url).then((response: AxiosResponse<T>) => {
|
||||
// @ts-ignore
|
||||
if (response?.data?.errors?.length > 0) {
|
||||
throw response.data.errors?.join();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user