Only count checked in teams on calendar after start Closes #1641

This commit is contained in:
Kalle
2024-02-25 11:43:51 +02:00
parent d22edc27f6
commit b52c561205

View File

@@ -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<number>().as("memberCount"))
.where("TournamentTeam.tournamentId", "=", tournamentId)
.groupBy("TournamentTeam.id")