UNPKG

@lovebowls/leaguejs

Version:

A framework-agnostic JavaScript library for managing leagues, teams, and matches

128 lines (127 loc) 3.99 kB
export class Match { /** * Create a new Match * @param {Object} data - Match data * @param {Object} data.homeTeam - Home team object with _id property * @param {Object} data.awayTeam - Away team object with _id property * @param {Date|string|null} [data.date] - Match date (can be null for unscheduled matches) * @param {number} [data.rink] - Assigned rink number for the match * @param {Object} [data.result] - Optional match result data containing scores * @param {number} [data.result.homeScore] - Home team's score * @param {number} [data.result.awayScore] - Away team's score * @param {Array<Object>} [data.result.rinkScores] - Optional individual rink scores * @param {Date} [data.createdAt] - Creation date (defaults to current date) * @param {Date} [data.updatedAt] - Last update date (defaults to current date) */ constructor(data: { homeTeam: Object; awayTeam: Object; date?: string | Date | null | undefined; rink?: number | undefined; result?: { homeScore?: number | undefined; awayScore?: number | undefined; rinkScores?: Object[] | undefined; } | undefined; createdAt?: Date | undefined; updatedAt?: Date | undefined; }); _id: any; homeTeam: Object; awayTeam: Object; date: Date | null; rink: number | null; createdAt: Date; updatedAt: Date; result: { homeScore: number; awayScore: number; rinkScores: Object[] | null; } | null; /** * Get the home team name * @returns {string} - The name of the home team */ get homeTeamName(): string; /** * Get the away team name * @returns {string} - The name of the away team */ get awayTeamName(): string; /** * Determines the winner of the match based on scores. * @returns {string|null} - The name of the winning team, 'draw', or null if no result is set. */ getWinner(): string | null; /** * Checks if the match resulted in a draw. * @returns {boolean|null} - True if it's a draw, false otherwise, or null if no result is set. */ isDraw(): boolean | null; /** * Set rink scores for an existing match result * @param {Array} rinkScores - Array of rink scores [{homeScore, awayScore}, ...] * @returns {boolean} - True if scores were set, false if no result exists */ setRinkScores(rinkScores: any[]): boolean; /** * Get rink win/draw counts * @returns {Object|null} - Object with rink win counts or null if no rink scores */ getRinkResults(): Object | null; /** * Convert match to JSON * @returns {Object} - JSON representation of the match */ toJSON(): Object; } /** * Match model representing a bowls match between two teams */ export type MatchData = { /** * - Home team object with _id property */ homeTeam: Object; /** * - Away team object with _id property */ awayTeam: Object; /** * - Unique identifier for the match */ _id?: string | undefined; /** * - Match date (can be null for unscheduled matches) */ date?: string | Date | null | undefined; /** * - Assigned rink number for the match */ rink?: number | undefined; /** * - Optional match result data containing scores */ result?: { /** * - Home team's score */ homeScore?: number | undefined; /** * - Away team's score */ awayScore?: number | undefined; /** * - Optional individual rink scores */ rinkScores?: Object[] | undefined; } | undefined; /** * - Creation date (defaults to current date) */ createdAt?: Date | undefined; /** * - Last update date (defaults to current date) */ updatedAt?: Date | undefined; };