🎨 Improve code readability by reformatting and updating function definitions and comments

This commit is contained in:
2026-01-28 18:18:55 +00:00
parent 1944b43af8
commit a24f766e37
154 changed files with 7261 additions and 117 deletions

View File

@@ -15,15 +15,15 @@
* Makes three parallel API calls (pending, in_progress, ended) and combines
* the results while deduplicating by tournament ID.
*
* @param {Object} client - Challonge API client (from createChallongeV2Client)
* @param {Object} [options] - Query options
* @param {string} [options.scopeType] - USER, COMMUNITY, or APPLICATION scope (default: USER)
* @param {string} [options.communityId] - Community ID (if using COMMUNITY scope)
* @param {number} [options.page] - Page number (default: 1)
* @param {number} [options.per_page] - Results per page (default: 25)
* @param {string[]} [options.states] - States to query (default: ['pending', 'in_progress', 'ended'])
* @param {boolean} [options.includeCommunities] - Also query community tournaments (default: false)
* @returns {Promise<any[]>} Combined and deduplicated tournament list
* @param client - Challonge API client (from createChallongeV2Client)
* @param options - Query options
* @param options.scopeType - USER, COMMUNITY, or APPLICATION scope (default: USER)
* @param options.communityId - Community ID (if using COMMUNITY scope)
* @param options.page - Page number (default: 1)
* @param options.per_page - Results per page (default: 25)
* @param options.states - States to query (default: full Challonge state list)
* @param options.includeCommunities - Also query community tournaments (default: false)
* @returns Combined and deduplicated tournament list
*
* @example
* import { queryAllTournaments } from '../utilities/tournament-query.js'
@@ -39,7 +39,17 @@ export async function queryAllTournaments(client, options = {}) {
communityId,
page = 1,
per_page = 25,
states = ['pending', 'in_progress', 'ended'],
states = [
'pending',
'checking_in',
'checked_in',
'accepting_predictions',
'group_stages_underway',
'group_stages_finalized',
'underway',
'awaiting_review',
'complete'
],
includeCommunities = false
} = options;
@@ -53,13 +63,15 @@ export async function queryAllTournaments(client, options = {}) {
// Query all states in parallel
const promises = states.map(state =>
client.tournaments.list({
...baseOptions,
state
}).catch((err) => {
console.error(`Error querying ${state} tournaments:`, err);
return [];
})
client.tournaments
.list({
...baseOptions,
state
})
.catch(err => {
console.error(`Error querying ${state} tournaments:`, err);
return [];
})
);
// Wait for all requests
@@ -69,7 +81,7 @@ export async function queryAllTournaments(client, options = {}) {
const tournamentMap = new Map();
results.forEach(tournamentArray => {
if (Array.isArray(tournamentArray)) {
tournamentArray.forEach((tournament) => {
tournamentArray.forEach(tournament => {
// Handle both v1 and v2.1 response formats
const id = tournament.id || tournament.tournament?.id;
if (id && !tournamentMap.has(id)) {
@@ -88,9 +100,9 @@ export async function queryAllTournaments(client, options = {}) {
* For the USER scope, the Challonge API returns both created and admin tournaments,
* but optionally query across all states for completeness.
*
* @param {Object} client - Challonge API client
* @param {Object} [options] - Query options (same as queryAllTournaments)
* @returns {Promise<any[]>} User's created and admin tournaments
* @param client - Challonge API client
* @param options - Query options (same as queryAllTournaments)
* @returns User's created and admin tournaments
*/
export async function queryUserTournaments(client, options = {}) {
return queryAllTournaments(client, {
@@ -102,12 +114,16 @@ export async function queryUserTournaments(client, options = {}) {
/**
* Query all tournaments in a community (all states)
*
* @param {Object} client - Challonge API client
* @param {string} communityId - Community numeric ID
* @param {Object} [options] - Query options
* @returns {Promise<any[]>} Community tournaments across all states
* @param client - Challonge API client
* @param communityId - Community numeric ID
* @param options - Query options
* @returns Community tournaments across all states
*/
export async function queryCommunityTournaments(client, communityId, options = {}) {
export async function queryCommunityTournaments(
client,
communityId,
options = {}
) {
return queryAllTournaments(client, {
...options,
scopeType: 'COMMUNITY',
@@ -121,10 +137,10 @@ export async function queryCommunityTournaments(client, communityId, options = {
* Useful if you only care about specific states or want to use
* a different set of states than the default.
*
* @param {Object} client - Challonge API client
* @param {string[]} states - States to query (e.g., ['pending', 'in_progress'])
* @param {Object} [options] - Query options
* @returns {Promise<any[]>} Tournaments matching the given states
* @param client - Challonge API client
* @param states - States to query (e.g., ['pending', 'in_progress'])
* @param options - Query options
* @returns Tournaments matching the given states
*/
export async function queryTournamentsByStates(client, states, options = {}) {
return queryAllTournaments(client, {
@@ -136,9 +152,9 @@ export async function queryTournamentsByStates(client, states, options = {}) {
/**
* Query active tournaments only (pending + in_progress)
*
* @param {Object} client - Challonge API client
* @param {Object} [options] - Query options
* @returns {Promise<any[]>} Active tournaments
* @param client - Challonge API client
* @param options - Query options
* @returns Active tournaments
*/
export async function queryActiveTournaments(client, options = {}) {
return queryTournamentsByStates(client, ['pending', 'in_progress'], options);
@@ -147,9 +163,9 @@ export async function queryActiveTournaments(client, options = {}) {
/**
* Query completed tournaments only (ended)
*
* @param {Object} client - Challonge API client
* @param {Object} [options] - Query options
* @returns {Promise<any[]>} Completed tournaments
* @param client - Challonge API client
* @param options - Query options
* @returns Completed tournaments
*/
export async function queryCompletedTournaments(client, options = {}) {
return queryTournamentsByStates(client, ['ended'], options);