From 6de9943dcaa259a5f2de8159d29c60c100a8ac1d Mon Sep 17 00:00:00 2001 From: Nathaniel Tampus Date: Sat, 4 Mar 2023 18:41:09 +0800 Subject: [PATCH] game util functions --- client/src/lib/game.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 client/src/lib/game.ts diff --git a/client/src/lib/game.ts b/client/src/lib/game.ts new file mode 100644 index 0000000..6188416 --- /dev/null +++ b/client/src/lib/game.ts @@ -0,0 +1,25 @@ +import type { Game } from "@chessu/types"; +import { API_URL } from "@/config"; + +export const createGame = async (side: string, unlisted: boolean) => { + const res = await fetch(`${API_URL}/v1/games`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ side, unlisted }) + }); + + const game: Game | undefined = await res.json(); + return game; +}; + +export const findGame = async (code: string) => { + const res = await fetch(`${API_URL}/v1/games/${code}`); + + if (res && res.status === 200) { + const game: Game = await res.json(); + return game; + } +};