-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IDA-503: migrate max players update to server action
- Add server action for updating room capacity - Create Zod schema for input validation - Migrate lobby component from direct DB queries - Add error handling with toast notifications
- Loading branch information
Showing
4 changed files
with
71 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use server"; | ||
|
||
import { actionClient } from "../safe-action"; | ||
import { updateMaxPlayersSchema } from "../schemas/update-max-players-schema"; | ||
import { db } from "@/db"; | ||
import { rooms } from "@drizzle/schema"; | ||
import { eq } from "drizzle-orm"; | ||
|
||
export const updateRoomMaxPlayers = actionClient | ||
.schema(updateMaxPlayersSchema) | ||
.action(async ({ parsedInput: { maxPlayers, roomCode } }) => { | ||
const updated = await db | ||
.update(rooms) | ||
.set({ maxPlayers }) | ||
.where(eq(rooms.code, roomCode)) | ||
.returning({ maxPlayers: rooms.maxPlayers }); | ||
|
||
if (!updated[0]) throw new Error("Failed to update room capacity"); | ||
|
||
return { maxPlayers: updated[0].maxPlayers }; | ||
}); |
7 changes: 7 additions & 0 deletions
7
apps/dashboard/src/app/actions/schemas/update-max-players-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { z } from "zod"; | ||
import {roomSchema} from "@/app/api/v1/schemas" | ||
|
||
export const updateMaxPlayersSchema = z.object({ | ||
maxPlayers: z.number().min(2).max(10), | ||
roomCode: roomSchema.shape.roomCode, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.