prisma experiment

This commit is contained in:
2025-08-08 23:31:07 -04:00
parent 96df75972a
commit a7e339a8ce
2 changed files with 22 additions and 6 deletions

View File

@@ -10,31 +10,33 @@ export const GameContext = createContext<{
}>();
export default (props: { instanceId: number }) => {
const [gameState, { refetch }] = createResource(() =>
const [gameState, { refetch, mutate }] = createResource(() =>
api
.gameState({ gameId: props.instanceId.toString() })
.get()
.then((res) => res.data as GameState)
);
const setGameState = (state: GameState) =>
api
const setGameState = (state: GameState) => {
mutate(state);
return api
.gameState({ gameId: props.instanceId.toString() })
.put({
gameState: state,
})
.then(refetch);
};
return (
<GameContext.Provider value={{ gameState, setGameState }}>
<Show when={gameState() != undefined}>
<Show when={gameState.latest != undefined}>
<div
class="full column center"
style={{ "row-gap": "20px", "font-size": "32px" }}
>
<div class="full center">
<Pile
pile={gameState()!.deck}
pile={gameState.latest!.deck}
style={{ cursor: "pointer" }}
onClick={() => {
const [drawn, ...rest] = gameState()!.deck;
@@ -45,7 +47,7 @@ export default (props: { instanceId: number }) => {
}}
/>
</div>
<Hand hand={gameState()!.hand} />
<Hand hand={gameState.latest!.hand} />
</div>
</Show>
</GameContext.Provider>

View File

@@ -1,7 +1,21 @@
import { prisma } from "./db/db";
import { Elysia, t } from "elysia";
import { Prisma } from "@prisma/client";
const api = new Elysia({ prefix: "/api" })
// [wip]
.group("/prisma", (app) =>
app
.post("/game", ({ body }: { body: Prisma.GameFindManyArgs }) =>
prisma.game.findMany(body)
)
.post(
"/instance",
({ body }: { body: Prisma.InstanceFindManyArgs }) =>
prisma.instance.findMany(body)
)
)
.get("/games", () => prisma.game.findMany())
.get("/instances", ({ query: { game } }) =>