diff --git a/leaky-ships/components/Lobby/LobbyFrame.tsx b/leaky-ships/components/Lobby/LobbyFrame.tsx index 56af2ef..a763f61 100644 --- a/leaky-ships/components/Lobby/LobbyFrame.tsx +++ b/leaky-ships/components/Lobby/LobbyFrame.tsx @@ -7,18 +7,20 @@ function LobbyFrame({ openSettings }: { openSettings: () => void }) { const { gameProps } = useGameState() const [dots, setDots] = useState(1) + const { gamePin, player1, player2 } = gameProps.payload + useEffect(() => { - if (gameProps.enemy) return + if (player2) return const interval = setInterval(() => setDots((e) => (e % 3) + 1), 1000) return () => clearInterval(interval) - }, [gameProps.enemy]) + }, [player2]) return (
Chat

- Game-PIN: {gameProps.pin} + Game-PIN: {gamePin?.pin}

Settings @@ -27,16 +29,13 @@ function LobbyFrame({ openSettings }: { openSettings: () => void }) {

VS

- {gameProps.enemy ? ( - + {player2 ? ( + ) : (

Warte auf Spieler 2 {Array.from(Array(dots), () => ".").join("")} diff --git a/leaky-ships/lib/backend/getPinFromBody.ts b/leaky-ships/lib/backend/getPinFromBody.ts index 495da97..fdb6722 100644 --- a/leaky-ships/lib/backend/getPinFromBody.ts +++ b/leaky-ships/lib/backend/getPinFromBody.ts @@ -1,23 +1,24 @@ import sendError from "./sendError" import { NextApiRequest, NextApiResponse } from "next" +import { z } from "zod" + +const pinBodySchema = z.object({ + pin: z.string(), +}) async function getPinFromBody(req: NextApiRequest, res: NextApiResponse) { - const body = JSON.parse(req.body) - if ( - typeof body !== "object" || - !body || - !("pin" in body) || - typeof body.pin !== "string" - ) - throw sendError(req, res, { + try { + const body = JSON.parse(req.body) + const { pin } = pinBodySchema.parse(body) + return pin + } catch (err: any) { + sendError(req, res, { message: "No pin in request body!", statusCode: 401, solved: true, type: ["warn"], }) - const { pin } = body - - return pin + } } export default getPinFromBody diff --git a/leaky-ships/lib/hooks/useGameEvent.tsx b/leaky-ships/lib/hooks/useGameEvent.tsx index 72ccbab..5942119 100644 --- a/leaky-ships/lib/hooks/useGameEvent.tsx +++ b/leaky-ships/lib/hooks/useGameEvent.tsx @@ -10,7 +10,6 @@ import { Target, Position, } from "../../interfaces/frontend" -import { gameContext } from "../../pages/_app" import { hitReducer, initlialLastLeftTile, @@ -18,7 +17,7 @@ import { initlialTargetPreview, initlialMouseCursor, } from "../utils/helpers" -import { useCallback, useContext, useEffect, useReducer, useState } from "react" +import { useCallback, useEffect, useReducer, useState } from "react" const modes: Mode[] = [ { @@ -40,7 +39,6 @@ const modes: Mode[] = [ ] function useGameEvent(count: number) { - const [gameProps, setGameProps] = useContext(gameContext) const [lastLeftTile, setLastLeftTile] = useState(initlialLastLeftTile) const [target, setTarget] = useState(initlialTarget) diff --git a/leaky-ships/lib/hooks/useGameState.tsx b/leaky-ships/lib/hooks/useGameState.tsx index c011b77..d2fc2ce 100644 --- a/leaky-ships/lib/hooks/useGameState.tsx +++ b/leaky-ships/lib/hooks/useGameState.tsx @@ -1,10 +1,12 @@ -import { gameContext } from "../../pages/_app" +import { GamePropsSchema } from "@lib/zodSchemas" import { useSession } from "next-auth/react" -import { useContext, useEffect } from "react" +import { useEffect, useState } from "react" import { toast } from "react-toastify" -function useGameState() { - const [gameProps, setGameProps] = useContext(gameContext) +function useGameState(initial?: GamePropsSchema) { + const [gameProps, setGameProps] = useState( + initial ?? { payload: {}, hash: "" } + ) const { data: session, status } = useSession() useEffect(() => { @@ -22,10 +24,11 @@ function useGameState() { profile picture ) : undefined, }) - }, [session]) + }, [session, status]) return { gameProps, diff --git a/leaky-ships/lib/zodSchemas.ts b/leaky-ships/lib/zodSchemas.ts index 311072b..e90d5a7 100644 --- a/leaky-ships/lib/zodSchemas.ts +++ b/leaky-ships/lib/zodSchemas.ts @@ -1,19 +1,29 @@ -import { GameSchema } from "../prisma/generated/zod" +import { + GameSchema, + GamepinSchema, + User_GameSchema, +} from "../prisma/generated/zod" import { z } from "zod" -export const CreateSchema = z.object({ - game: GameSchema.strict(), - pin: z.string().optional(), - player: z.object({ - id: z.string(), - name: z.string().optional(), - isOwner: z.boolean().optional(), - }), - enemy: z - .object({ - id: z.string(), - username: z.string().optional(), - isOwner: z.boolean().optional(), - }) - .optional(), +export const PlayerSchema = z + .object({ + email: z.string().nullable(), + name: z.string().nullable(), + }) + .and(User_GameSchema) + +export const CreateSchema = z + .object({ + game: GameSchema.nullish(), + gamePin: GamepinSchema.nullish(), + player1: PlayerSchema.nullish(), + player2: PlayerSchema.nullish(), + }) + .strict() + +export const GamePropsSchema = z.object({ + payload: CreateSchema, + hash: z.string(), }) + +export type GamePropsSchema = z.infer diff --git a/leaky-ships/pages/_app.tsx b/leaky-ships/pages/_app.tsx index f5b430e..2973dc4 100644 --- a/leaky-ships/pages/_app.tsx +++ b/leaky-ships/pages/_app.tsx @@ -2,43 +2,20 @@ import "../styles/App.scss" import "../styles/globals.scss" import "../styles/grid2.scss" import "../styles/grid.scss" +import { CreateSchema } from "@lib/zodSchemas" import { SessionProvider } from "next-auth/react" import type { AppProps } from "next/app" -import { Dispatch, SetStateAction, createContext, useState } from "react" import { ToastContainer } from "react-toastify" import "react-toastify/dist/ReactToastify.css" -interface gameContext { - pin?: string - game?: { - id: string - } - player?: { - id: string - name?: string - isOwner?: boolean - } - enemy?: { - id: string - name?: string - } -} - -export const gameContext = createContext< - [gameContext, Dispatch>] ->([{}, () => {}]) - export default function App({ Component, pageProps: { session, ...pageProps }, }: AppProps) { - const gameProps = useState({}) return ( - - - - + + ) } diff --git a/leaky-ships/pages/api/game/create.ts b/leaky-ships/pages/api/game/create.ts index 853711e..bbcdd14 100644 --- a/leaky-ships/pages/api/game/create.ts +++ b/leaky-ships/pages/api/game/create.ts @@ -1,25 +1,22 @@ import { authOptions } from "../auth/[...nextauth]" -import { getAnyRunningGame } from "./running" +import { composeBody, gameIncludes, getAnyRunningGame } from "./running" import sendResponse from "@backend/sendResponse" import { rejectionErrors } from "@lib/backend/errors" import prisma from "@lib/prisma" -import { CreateSchema } from "@lib/zodSchemas" +import { GamePropsSchema } from "@lib/zodSchemas" import type { NextApiRequest, NextApiResponse } from "next" import { getServerSession } from "next-auth" -import { z } from "zod" - -type Data = z.infer export default async function create( req: NextApiRequest, - res: NextApiResponse + res: NextApiResponse ) { const session = await getServerSession(req, res, authOptions) if (!session?.user) { return sendResponse(req, res, rejectionErrors.unauthorized) } - const { email, id, name } = session.user + const { email, id } = session.user // Generate a random 4-digit code const pin = Math.floor(Math.random() * 10000) @@ -28,10 +25,10 @@ export default async function create( let created = false - let gameDB = await getAnyRunningGame(id) - if (!gameDB) { + let game = await getAnyRunningGame(id) + if (!game) { created = true - gameDB = await prisma.game.create({ + game = await prisma.game.create({ data: { gamePin: { create: { @@ -40,32 +37,21 @@ export default async function create( }, users: { create: { - isOwner: true, userId: id, + index: "player1", }, }, }, - include: { - gamePin: true, - users: true, - }, + ...gameIncludes, }) } - const { users, gamePin, ...game } = gameDB + const body = composeBody(game) return sendResponse(req, res, { message: `User <${email}> created game: ${game.id}`, statusCode: created ? 201 : 200, - body: { - game, - pin: gamePin?.pin, - player: { - id, - name: name ?? undefined, - isOwner: true, - }, - }, + body, type: ["debug", "infoCyan"], }) } diff --git a/leaky-ships/pages/api/game/join.ts b/leaky-ships/pages/api/game/join.ts index 989ec64..3ff005f 100644 --- a/leaky-ships/pages/api/game/join.ts +++ b/leaky-ships/pages/api/game/join.ts @@ -1,20 +1,17 @@ import { authOptions } from "../auth/[...nextauth]" +import { composeBody, gameIncludes } from "./running" import sendError from "@backend/sendError" import sendResponse from "@backend/sendResponse" import { rejectionErrors } from "@lib/backend/errors" import getPinFromBody from "@lib/backend/getPinFromBody" import prisma from "@lib/prisma" -import type { Game } from "@prisma/client" +import { GamePropsSchema } from "@lib/zodSchemas" import type { NextApiRequest, NextApiResponse } from "next" import { getServerSession } from "next-auth" -interface Data { - game: Game -} - export default async function join( req: NextApiRequest, - res: NextApiResponse + res: NextApiResponse ) { const session = await getServerSession(req, res, authOptions) const pin = await getPinFromBody(req, res) @@ -23,7 +20,7 @@ export default async function join( return sendResponse(req, res, rejectionErrors.unauthorized) } - const { name, email, id } = session.user + const { email, id } = session.user try { const game = await prisma.game.findFirst({ @@ -32,13 +29,6 @@ export default async function join( pin, }, }, - include: { - users: { - include: { - user: true, - }, - }, - }, }) if (!game) { return sendResponse(req, res, { @@ -48,35 +38,22 @@ export default async function join( }) } - const player = game.users.find(({ user }) => user.id === id)?.user - const enemy = game.users.find(({ user }) => user.id !== id)?.user + const user_Game = await prisma.user_Game.create({ + data: { + gameId: game.id, + userId: id, + index: "player2", + }, + include: { + game: gameIncludes, + }, + }) - if (!player) { - await prisma.user_Game.create({ - data: { - isOwner: false, - gameId: game.id, - userId: id, - }, - }) - } + const body = composeBody(user_Game.game) return sendResponse(req, res, { message: `User <${email}> joined game: ${game.id}`, - body: { - game, - pin, - player: { - id, - name, - isOwner: true, - }, - enemy: { - id: enemy?.id, - name: enemy?.name, - isOwner: false, - }, - }, + body, type: ["debug", "infoCyan"], }) } catch (err: any) { diff --git a/leaky-ships/pages/api/game/running.ts b/leaky-ships/pages/api/game/running.ts index b5282a6..2476cfc 100644 --- a/leaky-ships/pages/api/game/running.ts +++ b/leaky-ships/pages/api/game/running.ts @@ -1,15 +1,30 @@ import { authOptions } from "../auth/[...nextauth]" import sendResponse from "@backend/sendResponse" import { rejectionErrors } from "@lib/backend/errors" +import { getObjectChecksum } from "@lib/getObjectChecksum" import prisma from "@lib/prisma" -import { Game } from "@prisma/client" +import { GamePropsSchema } from "@lib/zodSchemas" import type { NextApiRequest, NextApiResponse } from "next" import { getServerSession } from "next-auth" -type Data = { game: Game } +export const gameIncludes = { + include: { + gamePin: true, + users: { + include: { + user: { + select: { + name: true, + email: true, + }, + }, + }, + }, + }, +} -export const getAnyRunningGame = (id: string) => - prisma.game.findFirst({ +export const getAnyRunningGame = (id: string) => { + const game = prisma.game.findFirst({ where: { NOT: { state: "ended", @@ -20,15 +35,34 @@ export const getAnyRunningGame = (id: string) => }, }, }, - include: { - gamePin: true, - users: true, - }, + ...gameIncludes, }) + return game +} + +export function composeBody( + gameDB: NonNullable>> +) { + const { gamePin, ...game } = gameDB + const users = gameDB.users.map(({ user, ...props }) => ({ + ...props, + ...user, + })) + const player1 = users.find((user) => user.index === "player1") + const player2 = users.find((user) => user.index === "player2") + const payload = { + game, + gamePin, + player1, + player2, + } + const hash = getObjectChecksum(payload) + return { payload, hash } +} export default async function create( req: NextApiRequest, - res: NextApiResponse + res: NextApiResponse ) { const session = await getServerSession(req, res, authOptions) @@ -38,23 +72,21 @@ export default async function create( const { email, id } = session.user - const gameDB = await getAnyRunningGame(id) + const game = await getAnyRunningGame(id) - if (!gameDB) + if (!game) return sendResponse(req, res, { message: `User <${email}> is in no game.`, statusCode: 204, type: ["debug", "infoCyan"], }) - const { users, gamePin, ...game } = gameDB + const body = composeBody(game) return sendResponse(req, res, { message: `User <${email}> asked for game: ${game.id}`, statusCode: 200, - body: { - game, - }, + body, type: ["debug", "infoCyan"], }) } diff --git a/leaky-ships/pages/game/index.tsx b/leaky-ships/pages/game/index.tsx index 86869a1..dcba50e 100644 --- a/leaky-ships/pages/game/index.tsx +++ b/leaky-ships/pages/game/index.tsx @@ -53,7 +53,7 @@ export const getServerSideProps: GetServerSideProps = async ( let gameId = "" if (session?.user.id) { const game = await getAnyRunningGame(session?.user.id) - if (game && game.id) gameId = game?.id + if (game && game.state === "running") gameId = game?.id } return { props: { gameId, session } } diff --git a/leaky-ships/pages/lobby.tsx b/leaky-ships/pages/lobby.tsx deleted file mode 100644 index 2ae786d..0000000 --- a/leaky-ships/pages/lobby.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import BurgerMenu from "../components/BurgerMenu" -import LobbyFrame from "../components/Lobby/LobbyFrame" -import Settings from "../components/Lobby/SettingsFrame/Settings" -import Logo from "../components/Logo" -import classNames from "classnames" -import Head from "next/head" -import { useState } from "react" - -export default function Home() { - const [settings, setSettings] = useState(false) - return ( -

- - Create Next App - - - - -
- - setSettings(true)} /> -
- - {settings ? setSettings(false)} /> : <>} -
- ) -} diff --git a/leaky-ships/pages/lobby/[gameId].tsx b/leaky-ships/pages/lobby/[gameId].tsx new file mode 100644 index 0000000..9cf9a36 --- /dev/null +++ b/leaky-ships/pages/lobby/[gameId].tsx @@ -0,0 +1,54 @@ +import BurgerMenu from "../../components/BurgerMenu" +import LobbyFrame from "../../components/Lobby/LobbyFrame" +import Settings from "../../components/Lobby/SettingsFrame/Settings" +import Logo from "../../components/Logo" +import { Data, composeBody, getAnyRunningGame } from "../api/game/running" +import useGameState from "@lib/hooks/useGameState" +import classNames from "classnames" +import { GetServerSideProps } from "next" +import Head from "next/head" +import { useState } from "react" + +export default function Home(props: Data) { + const [settings, setSettings] = useState(false) + const { gameProps, setGameProps } = useGameState(props) + + return ( +
+ + Lobby + + + + +
+ + setSettings(true)} /> +
+ + {settings ? setSettings(false)} /> : <>} +
+ ) +} + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { gameId } = context.query + + const gameIdString = Array.isArray(gameId) ? gameId[0] : gameId + const game = await getAnyRunningGame(gameIdString ?? "") + if (!game) + return { + redirect: { + destination: "/start", + permanent: false, + }, + } + const body = composeBody(game) + + return { props: body } +} diff --git a/leaky-ships/pages/lobby/index.tsx b/leaky-ships/pages/lobby/index.tsx new file mode 100644 index 0000000..29fe8b7 --- /dev/null +++ b/leaky-ships/pages/lobby/index.tsx @@ -0,0 +1,60 @@ +import { authOptions } from "../api/auth/[...nextauth]" +import { getAnyRunningGame } from "../api/game/running" +import { GetServerSideProps } from "next" +import { Session, getServerSession } from "next-auth" +import { useRouter } from "next/router" +import React, { useEffect } from "react" +import { toast } from "react-toastify" + +interface Props { + gameId: string + session: Session | null +} + +export default function Lobby({ gameId, session }: Props) { + const router = useRouter() + + useEffect(() => { + const path = gameId ? "/lobby/" + gameId : "/start" + toast.promise(router.push(path), { + pending: { + render: "Wird weitergeleitet...", + toastId: "redirect", + }, + success: { + render: gameId + ? "Spiel gefunden!" + : session?.user + ? "Kein laufendes Spiel." + : "Kein laufendes Spiel. Bitte anmelden.", + toastId: session?.user ? "postRedirect" : "user", + theme: session?.user ? "dark" : undefined, + type: gameId ? "success" : "info", + }, + error: { + render: "Es ist ein Fehler aufgetreten 🤯", + type: "error", + theme: "colored", + }, + }) + }) + + return ( +
+
+
+ ) +} + +export const getServerSideProps: GetServerSideProps = async ( + context +) => { + const session = await getServerSession(context.req, context.res, authOptions) + let gameId = "" + if (session?.user.id) { + const game = await getAnyRunningGame(session?.user.id) + if (game && game.state === "launching") gameId = game?.id + } + + return { props: { gameId, session } } +} diff --git a/leaky-ships/pages/start.tsx b/leaky-ships/pages/start.tsx index c7eeb61..c19ce9c 100644 --- a/leaky-ships/pages/start.tsx +++ b/leaky-ships/pages/start.tsx @@ -5,7 +5,7 @@ import { faEye, faLeftLong } from "@fortawesome/pro-regular-svg-icons" import { faPlus, faUserPlus } from "@fortawesome/pro-solid-svg-icons" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import useGameState from "@lib/hooks/useGameState" -import { CreateSchema } from "@lib/zodSchemas" +import { GamePropsSchema } from "@lib/zodSchemas" import status from "http-status" import { GetServerSideProps } from "next" import { useRouter } from "next/router" @@ -16,6 +16,7 @@ import { toast } from "react-toastify" interface Props { q: string | string[] | undefined } + function isInputOnlyNumbers(input: string) { return /^\d+$/.test(input) } @@ -32,7 +33,6 @@ export function isAuthenticated(res: Response) { type: "error", theme: "colored", }) - return Promise.reject() } const handleConfirmation = () => { @@ -48,7 +48,7 @@ const handleConfirmation = () => { ) } -export default function Home({ q }: Props) { +export default function Start({ q }: Props) { const [otp, setOtp] = useState("") const { gameProps, setGameProps } = useGameState() const router = useRouter() @@ -61,7 +61,7 @@ export default function Home({ q }: Props) { body: JSON.stringify({ pin }), }) .then(isAuthenticated) - .then((game) => CreateSchema.parse(game)) + .then((game) => GamePropsSchema.parse(game)) const res = await toast.promise(gamePromise, { pending: { @@ -170,5 +170,5 @@ export const getServerSideProps: GetServerSideProps = async ( ) => { const { q } = context.query - return { props: { q: q ? q : "" } } + return { props: { q } } } diff --git a/leaky-ships/prisma/generated/zod/index.ts b/leaky-ships/prisma/generated/zod/index.ts index a9ee6ed..0a8aaf5 100644 --- a/leaky-ships/prisma/generated/zod/index.ts +++ b/leaky-ships/prisma/generated/zod/index.ts @@ -28,7 +28,7 @@ export const TransactionIsolationLevelSchema = z.enum(['ReadUncommitted','ReadCo export const UserScalarFieldEnumSchema = z.enum(['id','name','email','emailVerified','image','createdAt','updatedAt']); -export const User_GameScalarFieldEnumSchema = z.enum(['id','createdAt','gameId','userId','isOwner']); +export const User_GameScalarFieldEnumSchema = z.enum(['id','createdAt','gameId','userId','index']); export const VerificationTokenScalarFieldEnumSchema = z.enum(['identifier','token','expires']); @@ -36,6 +36,10 @@ export const GameStateSchema = z.enum(['launching','running','ended']); export type GameStateType = `${z.infer}` +export const PlayerNSchema = z.enum(['player1','player2']); + +export type PlayerNType = `${z.infer}` + ///////////////////////////////////////// // MODELS ///////////////////////////////////////// @@ -136,11 +140,11 @@ export type Gamepin = z.infer ///////////////////////////////////////// export const User_GameSchema = z.object({ + index: PlayerNSchema, id: z.string().cuid(), createdAt: z.coerce.date(), gameId: z.string(), userId: z.string(), - isOwner: z.boolean(), }) export type User_Game = z.infer @@ -357,7 +361,7 @@ export const User_GameSelectSchema: z.ZodType = z.object createdAt: z.boolean().optional(), gameId: z.boolean().optional(), userId: z.boolean().optional(), - isOwner: z.boolean().optional(), + index: z.boolean().optional(), moves: z.union([z.boolean(),z.lazy(() => MoveFindManyArgsSchema)]).optional(), chats: z.union([z.boolean(),z.lazy(() => ChatFindManyArgsSchema)]).optional(), game: z.union([z.boolean(),z.lazy(() => GameArgsSchema)]).optional(), @@ -741,7 +745,7 @@ export const User_GameWhereInputSchema: z.ZodType = createdAt: z.union([ z.lazy(() => DateTimeFilterSchema),z.coerce.date() ]).optional(), gameId: z.union([ z.lazy(() => StringFilterSchema),z.string() ]).optional(), userId: z.union([ z.lazy(() => StringFilterSchema),z.string() ]).optional(), - isOwner: z.union([ z.lazy(() => BoolFilterSchema),z.boolean() ]).optional(), + index: z.union([ z.lazy(() => EnumPlayerNFilterSchema),z.lazy(() => PlayerNSchema) ]).optional(), moves: z.lazy(() => MoveListRelationFilterSchema).optional(), chats: z.lazy(() => ChatListRelationFilterSchema).optional(), game: z.union([ z.lazy(() => GameRelationFilterSchema),z.lazy(() => GameWhereInputSchema) ]).optional(), @@ -753,7 +757,7 @@ export const User_GameOrderByWithRelationInputSchema: z.ZodType SortOrderSchema).optional(), gameId: z.lazy(() => SortOrderSchema).optional(), userId: z.lazy(() => SortOrderSchema).optional(), - isOwner: z.lazy(() => SortOrderSchema).optional(), + index: z.lazy(() => SortOrderSchema).optional(), moves: z.lazy(() => MoveOrderByRelationAggregateInputSchema).optional(), chats: z.lazy(() => ChatOrderByRelationAggregateInputSchema).optional(), game: z.lazy(() => GameOrderByWithRelationInputSchema).optional(), @@ -762,6 +766,7 @@ export const User_GameOrderByWithRelationInputSchema: z.ZodType = z.object({ id: z.string().cuid().optional(), + gameId_index: z.lazy(() => User_GameGameIdIndexCompoundUniqueInputSchema).optional(), gameId_userId: z.lazy(() => User_GameGameIdUserIdCompoundUniqueInputSchema).optional() }).strict(); @@ -770,7 +775,7 @@ export const User_GameOrderByWithAggregationInputSchema: z.ZodType SortOrderSchema).optional(), gameId: z.lazy(() => SortOrderSchema).optional(), userId: z.lazy(() => SortOrderSchema).optional(), - isOwner: z.lazy(() => SortOrderSchema).optional(), + index: z.lazy(() => SortOrderSchema).optional(), _count: z.lazy(() => User_GameCountOrderByAggregateInputSchema).optional(), _max: z.lazy(() => User_GameMaxOrderByAggregateInputSchema).optional(), _min: z.lazy(() => User_GameMinOrderByAggregateInputSchema).optional() @@ -784,7 +789,7 @@ export const User_GameScalarWhereWithAggregatesInputSchema: z.ZodType DateTimeWithAggregatesFilterSchema),z.coerce.date() ]).optional(), gameId: z.union([ z.lazy(() => StringWithAggregatesFilterSchema),z.string() ]).optional(), userId: z.union([ z.lazy(() => StringWithAggregatesFilterSchema),z.string() ]).optional(), - isOwner: z.union([ z.lazy(() => BoolWithAggregatesFilterSchema),z.boolean() ]).optional(), + index: z.union([ z.lazy(() => EnumPlayerNWithAggregatesFilterSchema),z.lazy(() => PlayerNSchema) ]).optional(), }).strict(); export const MoveWhereInputSchema: z.ZodType = z.object({ @@ -807,7 +812,8 @@ export const MoveOrderByWithRelationInputSchema: z.ZodType = z.object({ - id: z.string().cuid().optional() + id: z.string().cuid().optional(), + user_game_id_index: z.lazy(() => MoveUser_game_idIndexCompoundUniqueInputSchema).optional() }).strict(); export const MoveOrderByWithAggregationInputSchema: z.ZodType = z.object({ @@ -1284,7 +1290,7 @@ export const GamepinUncheckedUpdateManyInputSchema: z.ZodType = z.object({ id: z.string().cuid().optional(), createdAt: z.coerce.date().optional(), - isOwner: z.boolean(), + index: z.lazy(() => PlayerNSchema), moves: z.lazy(() => MoveCreateNestedManyWithoutUser_gameInputSchema).optional(), chats: z.lazy(() => ChatCreateNestedManyWithoutUser_gameInputSchema).optional(), game: z.lazy(() => GameCreateNestedOneWithoutUsersInputSchema), @@ -1296,7 +1302,7 @@ export const User_GameUncheckedCreateInputSchema: z.ZodType PlayerNSchema), moves: z.lazy(() => MoveUncheckedCreateNestedManyWithoutUser_gameInputSchema).optional(), chats: z.lazy(() => ChatUncheckedCreateNestedManyWithoutUser_gameInputSchema).optional() }).strict(); @@ -1304,7 +1310,7 @@ export const User_GameUncheckedCreateInputSchema: z.ZodType = z.object({ id: z.union([ z.string().cuid(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), moves: z.lazy(() => MoveUpdateManyWithoutUser_gameNestedInputSchema).optional(), chats: z.lazy(() => ChatUpdateManyWithoutUser_gameNestedInputSchema).optional(), game: z.lazy(() => GameUpdateOneRequiredWithoutUsersNestedInputSchema).optional(), @@ -1316,7 +1322,7 @@ export const User_GameUncheckedUpdateInputSchema: z.ZodType DateTimeFieldUpdateOperationsInputSchema) ]).optional(), gameId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), userId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), moves: z.lazy(() => MoveUncheckedUpdateManyWithoutUser_gameNestedInputSchema).optional(), chats: z.lazy(() => ChatUncheckedUpdateManyWithoutUser_gameNestedInputSchema).optional() }).strict(); @@ -1326,13 +1332,13 @@ export const User_GameCreateManyInputSchema: z.ZodType PlayerNSchema) }).strict(); export const User_GameUpdateManyMutationInputSchema: z.ZodType = z.object({ id: z.union([ z.string().cuid(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), }).strict(); export const User_GameUncheckedUpdateManyInputSchema: z.ZodType = z.object({ @@ -1340,7 +1346,7 @@ export const User_GameUncheckedUpdateManyInputSchema: z.ZodType DateTimeFieldUpdateOperationsInputSchema) ]).optional(), gameId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), userId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), }).strict(); export const MoveCreateInputSchema: z.ZodType = z.object({ @@ -1832,9 +1838,11 @@ export const GamepinMinOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional() }).strict(); -export const BoolFilterSchema: z.ZodType = z.object({ - equals: z.boolean().optional(), - not: z.union([ z.boolean(),z.lazy(() => NestedBoolFilterSchema) ]).optional(), +export const EnumPlayerNFilterSchema: z.ZodType = z.object({ + equals: z.lazy(() => PlayerNSchema).optional(), + in: z.lazy(() => PlayerNSchema).array().optional(), + notIn: z.lazy(() => PlayerNSchema).array().optional(), + not: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => NestedEnumPlayerNFilterSchema) ]).optional(), }).strict(); export const MoveListRelationFilterSchema: z.ZodType = z.object({ @@ -1857,6 +1865,11 @@ export const ChatOrderByRelationAggregateInputSchema: z.ZodType SortOrderSchema).optional() }).strict(); +export const User_GameGameIdIndexCompoundUniqueInputSchema: z.ZodType = z.object({ + gameId: z.string(), + index: z.lazy(() => PlayerNSchema) +}).strict(); + export const User_GameGameIdUserIdCompoundUniqueInputSchema: z.ZodType = z.object({ gameId: z.string(), userId: z.string() @@ -1867,7 +1880,7 @@ export const User_GameCountOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), gameId: z.lazy(() => SortOrderSchema).optional(), userId: z.lazy(() => SortOrderSchema).optional(), - isOwner: z.lazy(() => SortOrderSchema).optional() + index: z.lazy(() => SortOrderSchema).optional() }).strict(); export const User_GameMaxOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -1875,7 +1888,7 @@ export const User_GameMaxOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), gameId: z.lazy(() => SortOrderSchema).optional(), userId: z.lazy(() => SortOrderSchema).optional(), - isOwner: z.lazy(() => SortOrderSchema).optional() + index: z.lazy(() => SortOrderSchema).optional() }).strict(); export const User_GameMinOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -1883,15 +1896,17 @@ export const User_GameMinOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), gameId: z.lazy(() => SortOrderSchema).optional(), userId: z.lazy(() => SortOrderSchema).optional(), - isOwner: z.lazy(() => SortOrderSchema).optional() + index: z.lazy(() => SortOrderSchema).optional() }).strict(); -export const BoolWithAggregatesFilterSchema: z.ZodType = z.object({ - equals: z.boolean().optional(), - not: z.union([ z.boolean(),z.lazy(() => NestedBoolWithAggregatesFilterSchema) ]).optional(), +export const EnumPlayerNWithAggregatesFilterSchema: z.ZodType = z.object({ + equals: z.lazy(() => PlayerNSchema).optional(), + in: z.lazy(() => PlayerNSchema).array().optional(), + notIn: z.lazy(() => PlayerNSchema).array().optional(), + not: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => NestedEnumPlayerNWithAggregatesFilterSchema) ]).optional(), _count: z.lazy(() => NestedIntFilterSchema).optional(), - _min: z.lazy(() => NestedBoolFilterSchema).optional(), - _max: z.lazy(() => NestedBoolFilterSchema).optional() + _min: z.lazy(() => NestedEnumPlayerNFilterSchema).optional(), + _max: z.lazy(() => NestedEnumPlayerNFilterSchema).optional() }).strict(); export const IntFilterSchema: z.ZodType = z.object({ @@ -1910,6 +1925,11 @@ export const User_GameRelationFilterSchema: z.ZodType User_GameWhereInputSchema).optional() }).strict(); +export const MoveUser_game_idIndexCompoundUniqueInputSchema: z.ZodType = z.object({ + user_game_id: z.string(), + index: z.number() +}).strict(); + export const MoveCountOrderByAggregateInputSchema: z.ZodType = z.object({ id: z.lazy(() => SortOrderSchema).optional(), createdAt: z.lazy(() => SortOrderSchema).optional(), @@ -2289,8 +2309,8 @@ export const ChatUncheckedCreateNestedManyWithoutUser_gameInputSchema: z.ZodType connect: z.union([ z.lazy(() => ChatWhereUniqueInputSchema),z.lazy(() => ChatWhereUniqueInputSchema).array() ]).optional(), }).strict(); -export const BoolFieldUpdateOperationsInputSchema: z.ZodType = z.object({ - set: z.boolean().optional() +export const EnumPlayerNFieldUpdateOperationsInputSchema: z.ZodType = z.object({ + set: z.lazy(() => PlayerNSchema).optional() }).strict(); export const MoveUpdateManyWithoutUser_gameNestedInputSchema: z.ZodType = z.object({ @@ -2579,17 +2599,21 @@ export const NestedEnumGameStateWithAggregatesFilterSchema: z.ZodType NestedEnumGameStateFilterSchema).optional() }).strict(); -export const NestedBoolFilterSchema: z.ZodType = z.object({ - equals: z.boolean().optional(), - not: z.union([ z.boolean(),z.lazy(() => NestedBoolFilterSchema) ]).optional(), +export const NestedEnumPlayerNFilterSchema: z.ZodType = z.object({ + equals: z.lazy(() => PlayerNSchema).optional(), + in: z.lazy(() => PlayerNSchema).array().optional(), + notIn: z.lazy(() => PlayerNSchema).array().optional(), + not: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => NestedEnumPlayerNFilterSchema) ]).optional(), }).strict(); -export const NestedBoolWithAggregatesFilterSchema: z.ZodType = z.object({ - equals: z.boolean().optional(), - not: z.union([ z.boolean(),z.lazy(() => NestedBoolWithAggregatesFilterSchema) ]).optional(), +export const NestedEnumPlayerNWithAggregatesFilterSchema: z.ZodType = z.object({ + equals: z.lazy(() => PlayerNSchema).optional(), + in: z.lazy(() => PlayerNSchema).array().optional(), + notIn: z.lazy(() => PlayerNSchema).array().optional(), + not: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => NestedEnumPlayerNWithAggregatesFilterSchema) ]).optional(), _count: z.lazy(() => NestedIntFilterSchema).optional(), - _min: z.lazy(() => NestedBoolFilterSchema).optional(), - _max: z.lazy(() => NestedBoolFilterSchema).optional() + _min: z.lazy(() => NestedEnumPlayerNFilterSchema).optional(), + _max: z.lazy(() => NestedEnumPlayerNFilterSchema).optional() }).strict(); export const NestedIntWithAggregatesFilterSchema: z.ZodType = z.object({ @@ -2738,7 +2762,7 @@ export const UserUncheckedUpdateWithoutSessionsInputSchema: z.ZodType = z.object({ id: z.string().optional(), createdAt: z.coerce.date().optional(), - isOwner: z.boolean(), + index: z.lazy(() => PlayerNSchema), moves: z.lazy(() => MoveCreateNestedManyWithoutUser_gameInputSchema).optional(), chats: z.lazy(() => ChatCreateNestedManyWithoutUser_gameInputSchema).optional(), game: z.lazy(() => GameCreateNestedOneWithoutUsersInputSchema) @@ -2748,7 +2772,7 @@ export const User_GameUncheckedCreateWithoutUserInputSchema: z.ZodType PlayerNSchema), moves: z.lazy(() => MoveUncheckedCreateNestedManyWithoutUser_gameInputSchema).optional(), chats: z.lazy(() => ChatUncheckedCreateNestedManyWithoutUser_gameInputSchema).optional() }).strict(); @@ -2853,7 +2877,7 @@ export const User_GameScalarWhereInputSchema: z.ZodType DateTimeFilterSchema),z.coerce.date() ]).optional(), gameId: z.union([ z.lazy(() => StringFilterSchema),z.string() ]).optional(), userId: z.union([ z.lazy(() => StringFilterSchema),z.string() ]).optional(), - isOwner: z.union([ z.lazy(() => BoolFilterSchema),z.boolean() ]).optional(), + index: z.union([ z.lazy(() => EnumPlayerNFilterSchema),z.lazy(() => PlayerNSchema) ]).optional(), }).strict(); export const AccountUpsertWithWhereUniqueWithoutUserInputSchema: z.ZodType = z.object({ @@ -2939,7 +2963,7 @@ export const GamepinCreateOrConnectWithoutGameInputSchema: z.ZodType = z.object({ id: z.string().optional(), createdAt: z.coerce.date().optional(), - isOwner: z.boolean(), + index: z.lazy(() => PlayerNSchema), moves: z.lazy(() => MoveCreateNestedManyWithoutUser_gameInputSchema).optional(), chats: z.lazy(() => ChatCreateNestedManyWithoutUser_gameInputSchema).optional(), user: z.lazy(() => UserCreateNestedOneWithoutGamesInputSchema) @@ -2949,7 +2973,7 @@ export const User_GameUncheckedCreateWithoutGameInputSchema: z.ZodType PlayerNSchema), moves: z.lazy(() => MoveUncheckedCreateNestedManyWithoutUser_gameInputSchema).optional(), chats: z.lazy(() => ChatUncheckedCreateNestedManyWithoutUser_gameInputSchema).optional() }).strict(); @@ -3241,7 +3265,7 @@ export const UserUncheckedUpdateWithoutGamesInputSchema: z.ZodType = z.object({ id: z.string().optional(), createdAt: z.coerce.date().optional(), - isOwner: z.boolean(), + index: z.lazy(() => PlayerNSchema), chats: z.lazy(() => ChatCreateNestedManyWithoutUser_gameInputSchema).optional(), game: z.lazy(() => GameCreateNestedOneWithoutUsersInputSchema), user: z.lazy(() => UserCreateNestedOneWithoutGamesInputSchema) @@ -3252,7 +3276,7 @@ export const User_GameUncheckedCreateWithoutMovesInputSchema: z.ZodType PlayerNSchema), chats: z.lazy(() => ChatUncheckedCreateNestedManyWithoutUser_gameInputSchema).optional() }).strict(); @@ -3269,7 +3293,7 @@ export const User_GameUpsertWithoutMovesInputSchema: z.ZodType = z.object({ id: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), chats: z.lazy(() => ChatUpdateManyWithoutUser_gameNestedInputSchema).optional(), game: z.lazy(() => GameUpdateOneRequiredWithoutUsersNestedInputSchema).optional(), user: z.lazy(() => UserUpdateOneRequiredWithoutGamesNestedInputSchema).optional() @@ -3280,14 +3304,14 @@ export const User_GameUncheckedUpdateWithoutMovesInputSchema: z.ZodType DateTimeFieldUpdateOperationsInputSchema) ]).optional(), gameId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), userId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), chats: z.lazy(() => ChatUncheckedUpdateManyWithoutUser_gameNestedInputSchema).optional() }).strict(); export const User_GameCreateWithoutChatsInputSchema: z.ZodType = z.object({ id: z.string().optional(), createdAt: z.coerce.date().optional(), - isOwner: z.boolean(), + index: z.lazy(() => PlayerNSchema), moves: z.lazy(() => MoveCreateNestedManyWithoutUser_gameInputSchema).optional(), game: z.lazy(() => GameCreateNestedOneWithoutUsersInputSchema), user: z.lazy(() => UserCreateNestedOneWithoutGamesInputSchema) @@ -3298,7 +3322,7 @@ export const User_GameUncheckedCreateWithoutChatsInputSchema: z.ZodType PlayerNSchema), moves: z.lazy(() => MoveUncheckedCreateNestedManyWithoutUser_gameInputSchema).optional() }).strict(); @@ -3315,7 +3339,7 @@ export const User_GameUpsertWithoutChatsInputSchema: z.ZodType = z.object({ id: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), moves: z.lazy(() => MoveUpdateManyWithoutUser_gameNestedInputSchema).optional(), game: z.lazy(() => GameUpdateOneRequiredWithoutUsersNestedInputSchema).optional(), user: z.lazy(() => UserUpdateOneRequiredWithoutGamesNestedInputSchema).optional() @@ -3326,7 +3350,7 @@ export const User_GameUncheckedUpdateWithoutChatsInputSchema: z.ZodType DateTimeFieldUpdateOperationsInputSchema) ]).optional(), gameId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), userId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), moves: z.lazy(() => MoveUncheckedUpdateManyWithoutUser_gameNestedInputSchema).optional() }).strict(); @@ -3334,7 +3358,7 @@ export const User_GameCreateManyUserInputSchema: z.ZodType PlayerNSchema) }).strict(); export const AccountCreateManyUserInputSchema: z.ZodType = z.object({ @@ -3363,7 +3387,7 @@ export const SessionCreateManyUserInputSchema: z.ZodType = z.object({ id: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), moves: z.lazy(() => MoveUpdateManyWithoutUser_gameNestedInputSchema).optional(), chats: z.lazy(() => ChatUpdateManyWithoutUser_gameNestedInputSchema).optional(), game: z.lazy(() => GameUpdateOneRequiredWithoutUsersNestedInputSchema).optional() @@ -3373,7 +3397,7 @@ export const User_GameUncheckedUpdateWithoutUserInputSchema: z.ZodType StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), gameId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), moves: z.lazy(() => MoveUncheckedUpdateManyWithoutUser_gameNestedInputSchema).optional(), chats: z.lazy(() => ChatUncheckedUpdateManyWithoutUser_gameNestedInputSchema).optional() }).strict(); @@ -3382,7 +3406,7 @@ export const User_GameUncheckedUpdateManyWithoutGamesInputSchema: z.ZodType StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), gameId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), }).strict(); export const AccountUpdateWithoutUserInputSchema: z.ZodType = z.object({ @@ -3458,13 +3482,13 @@ export const User_GameCreateManyGameInputSchema: z.ZodType PlayerNSchema) }).strict(); export const User_GameUpdateWithoutGameInputSchema: z.ZodType = z.object({ id: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), moves: z.lazy(() => MoveUpdateManyWithoutUser_gameNestedInputSchema).optional(), chats: z.lazy(() => ChatUpdateManyWithoutUser_gameNestedInputSchema).optional(), user: z.lazy(() => UserUpdateOneRequiredWithoutGamesNestedInputSchema).optional() @@ -3474,7 +3498,7 @@ export const User_GameUncheckedUpdateWithoutGameInputSchema: z.ZodType StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), userId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), moves: z.lazy(() => MoveUncheckedUpdateManyWithoutUser_gameNestedInputSchema).optional(), chats: z.lazy(() => ChatUncheckedUpdateManyWithoutUser_gameNestedInputSchema).optional() }).strict(); @@ -3483,7 +3507,7 @@ export const User_GameUncheckedUpdateManyWithoutUsersInputSchema: z.ZodType StringFieldUpdateOperationsInputSchema) ]).optional(), createdAt: z.union([ z.coerce.date(),z.lazy(() => DateTimeFieldUpdateOperationsInputSchema) ]).optional(), userId: z.union([ z.string(),z.lazy(() => StringFieldUpdateOperationsInputSchema) ]).optional(), - isOwner: z.union([ z.boolean(),z.lazy(() => BoolFieldUpdateOperationsInputSchema) ]).optional(), + index: z.union([ z.lazy(() => PlayerNSchema),z.lazy(() => EnumPlayerNFieldUpdateOperationsInputSchema) ]).optional(), }).strict(); export const MoveCreateManyUser_gameInputSchema: z.ZodType = z.object({ diff --git a/leaky-ships/prisma/schema.prisma b/leaky-ships/prisma/schema.prisma index 91266f0..9c87ba9 100644 --- a/leaky-ships/prisma/schema.prisma +++ b/leaky-ships/prisma/schema.prisma @@ -91,17 +91,23 @@ model Gamepin { game Game @relation(fields: [gameId], references: [id], onDelete: Cascade) } +enum PlayerN { + player1 + player2 +} + model User_Game { id String @id @default(cuid()) createdAt DateTime @default(now()) gameId String userId String - isOwner Boolean + index PlayerN moves Move[] chats Chat[] game Game @relation(fields: [gameId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id]) + @@unique([gameId, index]) @@unique([gameId, userId]) } @@ -111,6 +117,8 @@ model Move { index Int user_game_id String user_game User_Game @relation(fields: [user_game_id], references: [id], onDelete: Cascade) + + @@unique([user_game_id, index]) } model Chat {