diff --git a/app/features/calendar/CalendarRepository.server.ts b/app/features/calendar/CalendarRepository.server.ts index f7d8c3d9b..af2f13b2c 100644 --- a/app/features/calendar/CalendarRepository.server.ts +++ b/app/features/calendar/CalendarRepository.server.ts @@ -186,7 +186,11 @@ export async function findAllBetweenTwoTimestamps({ return { ...row, participantCounts: row.tournamentId - ? await tournamentParticipantCount(row.tournamentId) + ? await tournamentParticipantCount({ + tournamentId: row.tournamentId, + checkedInOnly: + row.startTime < dateToDatabaseTimestamp(new Date()), + }) : undefined, }; }), @@ -208,7 +212,13 @@ function tagsArray(args: { return tags; } -async function tournamentParticipantCount(tournamentId: number) { +async function tournamentParticipantCount({ + tournamentId, + checkedInOnly, +}: { + tournamentId: number; + checkedInOnly: boolean; +}) { const rows = await db .selectFrom("TournamentTeam") .leftJoin( @@ -216,6 +226,17 @@ async function tournamentParticipantCount(tournamentId: number) { "TournamentTeam.id", "TournamentTeamMember.tournamentTeamId", ) + .$if(checkedInOnly, (qb) => + qb.innerJoin("TournamentTeamCheckIn", (join) => + join + .onRef( + "TournamentTeamCheckIn.tournamentTeamId", + "=", + "TournamentTeam.id", + ) + .on("TournamentTeamCheckIn.bracketIdx", "is", null), + ), + ) .select(({ fn }) => fn.countAll().as("memberCount")) .where("TournamentTeam.tournamentId", "=", tournamentId) .groupBy("TournamentTeam.id")