mancala/src/store/GameStore.ts

25 lines
784 B
TypeScript
Raw Normal View History

2022-07-30 16:32:13 +03:00
import { CommonMancalaGame, MancalaGame } from "mancala.js";
import { HttpService } from "../service/HttpService";
export interface GameStore {
get(id: string): Promise<MancalaGame | undefined>;
}
export class GameStoreImpl implements GameStore {
httpService: HttpService;
constructor(props: { httpService: HttpService }) {
this.httpService = props.httpService;
}
async get(id: string): Promise<MancalaGame | undefined> {
try {
const response = await this.httpService.get(`/game/${id}`);
const json = await response.json();
return MancalaGame.createFromMancalaGame(json as CommonMancalaGame);
} catch (error) {
// todo check error
Promise.resolve(undefined);
}
}
}