Skip to content

Commit

Permalink
fix: add limits to server action functions and remove server-only for…
Browse files Browse the repository at this point in the history
… testing
  • Loading branch information
agrattan0820 committed Jun 28, 2024
1 parent 30699d8 commit c0e3b4c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/client/src/utils/server-actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "server-only";
import type { Session } from "next-auth";
import { db, games, usersToRooms, usersToGames, rooms } from "database";
import { sql, eq, and, isNull, desc, gt } from "drizzle-orm";
Expand All @@ -17,7 +16,8 @@ export async function getRunningGame({ session }: { session: Session }) {
)
.orderBy(desc(games.createdAt))
.groupBy(games.id)
.having(({ playerCount }) => gt(playerCount, 0));
.having(({ playerCount }) => gt(playerCount, 0))
.limit(1);

return runningGame[0];
}
Expand All @@ -33,7 +33,8 @@ export async function isUserInGame({
.select()
.from(games)
.innerJoin(usersToGames, eq(games.id, usersToGames.gameId))
.where(and(eq(usersToGames.userId, session.user.id), eq(games.id, gameId)));
.where(and(eq(usersToGames.userId, session.user.id), eq(games.id, gameId)))
.limit(1);

return userInGame[0];
}
Expand All @@ -51,7 +52,8 @@ export async function isUserInRoom({
.innerJoin(usersToRooms, eq(rooms.code, usersToRooms.roomCode))
.where(
and(eq(usersToRooms.userId, session.user.id), eq(rooms.code, roomCode)),
);
)
.limit(1);

return userInRoom[0];
}

0 comments on commit c0e3b4c

Please sign in to comment.