UNPKG

@lovebowls/leaguejs

Version:

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

48 lines (45 loc) 1.34 kB
/** * Team model representing a bowls team */ import { validateTeam } from '../utils/validators.js'; import { generateGUID } from '../utils/shared.js'; export class Team { /** * Create a new Team * @param {Object} data - Team data * @param {string} data._id - Unique identifier for the team * @param {string} [data.name] - Name of the team (defaults to _id if not provided) * @param {Date} [data.createdAt] - Creation date (defaults to current date) * @param {Date} [data.updatedAt] - Last update date (defaults to current date) */ constructor(data) { const validationResult = validateTeam(data); if (!validationResult.isValid) { throw new Error(validationResult.errors[0]); } this._id = data._id || generateGUID(); this.name = data.name || data._id; this.createdAt = data.createdAt || new Date(); this.updatedAt = data.updatedAt || new Date(); } /** * Update team details * @param {Object} updates - Updated team details */ update(updates) { Object.assign(this.details, updates); this.updatedAt = new Date(); } /** * Convert team to JSON * @returns {Object} - JSON representation of the team */ toJSON() { return { _id: this._id, name: this.name, createdAt: this.createdAt, updatedAt: this.updatedAt }; } }