mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-02 16:20:36 -05:00
Only count checked in teams on calendar after start Closes #1641
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user