Skip to main content

Constants

The Competition Factory exports groupings of constants that are used throughout the codebase for consistent naming and type safety. Constants are organized into logical categories and can be imported individually or accessed via the factoryConstants object.

Import Constants

// Import all constants
import { factoryConstants } from 'tods-competition-factory';

// Or import specific constant groups
import {
eventConstants,
genderConstants,
matchUpStatusConstants,
participantConstants,
drawDefinitionConstants,
} from 'tods-competition-factory';

Available Constant Groups

Event & Match Constants

eventConstants - Event types and category types

const { SINGLES, DOUBLES, TEAM, AGE, RATING, BOTH } = factoryConstants.eventConstants;
  • SINGLES / SINGLES_EVENT - Singles competition
  • DOUBLES / DOUBLES_EVENT - Doubles competition
  • TEAM / TEAM_EVENT - Team competition
  • AGE - Age-based category
  • RATING - Rating-based category
  • BOTH - Combined age and rating category

matchUpTypes - Match format types

const { SINGLES, DOUBLES, TEAM } = factoryConstants.matchUpTypes;

matchUpStatusConstants - MatchUp lifecycle states

const {
TO_BE_PLAYED,
IN_PROGRESS,
COMPLETED,
WALKOVER,
DEFAULTED,
RETIRED,
ABANDONED,
CANCELLED,
BYE,
SUSPENDED,
INCOMPLETE,
AWAITING_RESULT,
DEAD_RUBBER,
NOT_PLAYED,
DOUBLE_WALKOVER,
DOUBLE_DEFAULT,
} = factoryConstants.matchUpStatusConstants;

Status groupings are also exported:

  • directingMatchUpStatuses - Statuses that direct participants to next round
  • nonDirectingMatchUpStatuses - Statuses that don't advance participants
  • completedMatchUpStatuses - All terminal statuses
  • activeMatchUpStatuses - Statuses representing concluded matches
  • upcomingMatchUpStatuses - Statuses for future/ongoing matches
  • validMatchUpStatuses - All valid status values
  • particicipantsRequiredMatchUpStatuses - Statuses requiring participant assignment
  • recoveryTimeRequiredMatchUpStatuses - Statuses where recovery time applies

Draw & Structure Constants

drawDefinitionConstants - Draw types, stages, and positioning

const {
// Draw Types
SINGLE_ELIMINATION,
DOUBLE_ELIMINATION,
ROUND_ROBIN,
ROUND_ROBIN_WITH_PLAYOFF,
COMPASS,
OLYMPIC,
FEED_IN,
CURTIS_CONSOLATION,
FIRST_MATCH_LOSER_CONSOLATION,
FIRST_ROUND_LOSER_CONSOLATION,
AD_HOC,

// Stages
MAIN,
QUALIFYING,
CONSOLATION,
VOLUNTARY_CONSOLATION,
PLAY_OFF,

// Positioning
CLUSTER,
SEPARATE,
WATERFALL,
TOP_DOWN,
BOTTOM_UP,
RANDOM,

// Link Types
WINNER,
LOSER,
POSITION,
} = factoryConstants.drawDefinitionConstants;

Participant Constants

participantConstants - Participant types and states

const {
INDIVIDUAL,
PAIR,
TEAM,
GROUP,
SIGN_IN_STATUS,
SIGNED_IN,
SIGNED_OUT,
} = factoryConstants.participantConstants;

participantRoles - Roles participants can have

const {
COMPETITOR,
OFFICIAL,
ADMINISTRATOR,
OTHER,
} = factoryConstants.participantRoles;

genderConstants - Gender categories and abbreviations

const {
MALE,
FEMALE,
MIXED,
ANY,
OTHER,
MALE_ABBR, // 'M'
FEMALE_ABBR, // 'F'
MIXED_ABBR, // 'X'
ANY_ABBR, // 'A'
OTHER_ABBR, // 'O'
} = factoryConstants.genderConstants;

Entry & Status Constants

entryStatusConstants - Entry status values

const {
DIRECT_ACCEPTANCE,
ALTERNATE,
UNGROUPED,
WILDCARD,
QUALIFIER,
LUCKY_LOSER,
WITHDRAWN,
} = factoryConstants.entryStatusConstants;

ratingConstants - Rating system identifiers

const {
WTN, // World Tennis Number
UTR, // Universal Tennis Rating
NTRP, // National Tennis Rating Program
} = factoryConstants.ratingConstants;

Time & Scheduling Constants

scheduleConstants - Scheduling-related values

const {
SCHEDULE_TIMING,
START_TIME,
END_TIME,
SCHEDULED_TIME,
SCHEDULE_DATE,
COURTS,
VENUES,
} = factoryConstants.scheduleConstants;

timeItemConstants - Time item types

const {
RANKING,
RATING,
SEEDING,
PUBLISH,
SCHEDULE,
STATUS,
SCORE,
} = factoryConstants.timeItemConstants;

weekdayConstants - Day of week values

const {
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY,
} = factoryConstants.weekdayConstants;

Policy & Configuration Constants

policyConstants - Policy type identifiers

const {
POLICY_TYPE_SCORING,
POLICY_TYPE_SEEDING,
POLICY_TYPE_DRAWS,
POLICY_TYPE_SCHEDULING,
POLICY_TYPE_AVOIDANCE,
POLICY_TYPE_MATCHUP_ACTIONS,
POLICY_TYPE_ROUND_NAMING,
} = factoryConstants.policyConstants;

extensionConstants - Extension name constants

const {
ALTITUDE,
APPLIED_POLICIES,
CATEGORY,
COURT_BOOKING,
ENTRIES,
FLIGHT_PROFILE,
SCHEDULE_TIMING,
SURFACE,
TALLY,
} = factoryConstants.extensionConstants;

Competition Format Constants

tieFormatConstants - Team match tie format values

const {
AGGREGATE,
TEAM_TIEBREAK,
WIN_RATIO,
} = factoryConstants.tieFormatConstants;

surfaceConstants - Court surface types

const {
CLAY,
GRASS,
HARD,
CARPET,
ARTIFICIAL_CLAY,
ARTIFICIAL_GRASS,
} = factoryConstants.surfaceConstants;

scaleConstants - Scale/ranking system types

const {
SEEDING,
RANKING,
RATING,
} = factoryConstants.scaleConstants;

Action & Modification Constants

matchUpActionConstants - Available matchUp actions

const {
REFEREE,
SCORE,
STATUS,
SCHEDULE,
START,
END,
PENALTY,
OFFICIAL,
} = factoryConstants.matchUpActionConstants;

positionActionConstants - Position assignment actions

const {
ASSIGN_BYE,
ASSIGN_PARTICIPANT,
LUCKY_PARTICIPANT,
REMOVE_ASSIGNMENT,
SWAP_PARTICIPANTS,
WITHDRAW_PARTICIPANT,
} = factoryConstants.positionActionConstants;

penaltyConstants - Penalty types

const {
BALL_ABUSE,
VERBAL_ABUSE,
PHYSICAL_ABUSE,
COACHING,
DELAY_OF_GAME,
UNSPORTSMANLIKE_CONDUCT,
} = factoryConstants.penaltyConstants;

Data & Resource Constants

auditConstants - Audit trail action types

const {
ADD,
MODIFY,
DELETE,
} = factoryConstants.auditConstants;

resultConstants - Result outcome types

const {
WIN,
LOSS,
} = factoryConstants.resultConstants;

sortingConstants - Sorting options

const {
ASCENDING,
DESCENDING,
} = factoryConstants.sortingConstants;

displayConstants - Display format options

const {
ABBREVIATED,
FULL,
} = factoryConstants.displayConstants;

Other Constants

flightConstants - Flight-related constants

const {
FLIGHT,
FLIGHT_PROFILE,
SPLIT_LEVEL_BASED,
SPLIT_WATERFALL,
} = factoryConstants.flightConstants;

tournamentConstants - Tournament identifiers

const { TOURNAMENT_RECORDS } = factoryConstants.tournamentConstants;

venueConstants - Venue-related identifiers

const { COURTS, VENUES } = factoryConstants.venueConstants;

topicConstants - Notification/subscription topic types

const {
AUDIT_TOPIC,
MODIFY_MATCHUP_TOPIC,
PUBLISH_TOPIC,
} = factoryConstants.topicConstants;

errorConditionConstants - Error codes for validation and operations

// Import the large collection of error condition constants
const { INVALID_VALUES, MISSING_VALUE, NOT_FOUND } = factoryConstants.errorConditionConstants;

requestConstants - Request parameter constants

const { REQUEST_PARAMS } = factoryConstants.requestConstants;

resourceContants - Resource type identifiers

const { MATCHUP, EVENT, PARTICIPANT } = factoryConstants.resourceContants;

Usage Examples

Event Creation

const { eventConstants, genderConstants } = factoryConstants;

const event = {
eventType: eventConstants.SINGLES,
gender: genderConstants.FEMALE,
};

MatchUp Status Checking

const { matchUpStatusConstants, completedMatchUpStatuses } = factoryConstants;

if (completedMatchUpStatuses.includes(matchUp.matchUpStatus)) {
// Handle completed match
}

// Or check specific status
if (matchUp.matchUpStatus === matchUpStatusConstants.COMPLETED) {
// Process result
}

Draw Generation

const { drawDefinitionConstants } = factoryConstants;

const drawProfile = {
drawType: drawDefinitionConstants.SINGLE_ELIMINATION,
stage: drawDefinitionConstants.MAIN,
drawSize: 32,
};

Participant Filtering

const { participantConstants } = factoryConstants;

const individuals = participants.filter(
(p) => p.participantType === participantConstants.INDIVIDUAL
);

Type Safety

All exported constants are typed and provide autocomplete support in TypeScript-enabled editors. Using these constants ensures:

  • Consistent naming across your application
  • Reduced typos and bugs
  • Better IDE autocomplete
  • Easier refactoring
  • Self-documenting code

Best Practices

  1. Import only what you need - Import specific constant groups rather than the entire factoryConstants object
  2. Use constants consistently - Always use exported constants instead of hardcoded strings
  3. Destructure for readability - Extract frequently used constants at the module level
  4. Check status arrays - Use exported status arrays (like completedMatchUpStatuses) for status checking rather than listing values manually
// Good
const { SINGLES, DOUBLES } = eventConstants;
if (event.eventType === SINGLES) { /* ... */ }

// Avoid
if (event.eventType === 'SINGLES') { /* ... */ }