Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions convex/_model/users/_helpers/checkUserTournamentRelationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,35 @@ export const checkUserTournamentRelationship = async (
return false;
}

const userARegistrations = await ctx.db.query('tournamentRegistrations')
.withIndex('by_user', (q) => q.eq('userId', userIdA))
.collect();
const userBRegistrations = await ctx.db.query('tournamentRegistrations')
.withIndex('by_user', (q) => q.eq('userId', userIdB))
.collect();
const [
userARegistrations,
userAOrganizers,
userBRegistrations,
userBOrganizers,
] = await Promise.all([
ctx.db.query('tournamentRegistrations')
.withIndex('by_user', (q) => q.eq('userId', userIdA))
.collect(),
ctx.db.query('tournamentOrganizers')
.withIndex('by_user', (q) => q.eq('userId', userIdA))
.collect(),
ctx.db.query('tournamentRegistrations')
.withIndex('by_user', (q) => q.eq('userId', userIdB))
.collect(),
ctx.db.query('tournamentOrganizers')
.withIndex('by_user', (q) => q.eq('userId', userIdB))
.collect(),
]);

const userATournamentIds = [
...userARegistrations.map((r) => r.tournamentId),
...userAOrganizers.map((o) => o.tournamentId),
];

const userBTournamentIds = [
const userBTournamentIds = new Set<Id<'tournaments'>>([
...userBRegistrations.map((r) => r.tournamentId),
];
...userBOrganizers.map((o) => o.tournamentId),
]);

return userATournamentIds.some((id) => new Set(userBTournamentIds).has(id));
return userATournamentIds.some((id) => userBTournamentIds.has(id));
};