This commit is contained in:
2025-12-07 00:18:02 +01:00
parent 70d5f5689e
commit 5ca2454853
20 changed files with 4461 additions and 790 deletions

View File

@@ -1,5 +1,17 @@
import type { LeagueVisibilityType } from '../../domain/value-objects/LeagueVisibility';
export type LeagueStructureMode = 'solo' | 'fixedTeams';
/**
* League visibility determines public visibility and ranking status.
* - 'ranked': Public, competitive, affects driver ratings. Requires min 10 drivers.
* - 'unranked': Private, casual with friends. No rating impact. Any number of drivers.
*
* For backward compatibility, 'public'/'private' are also supported in the form,
* but the domain uses 'ranked'/'unranked'.
*/
export type LeagueVisibilityFormValue = LeagueVisibilityType | 'public' | 'private';
export interface LeagueStructureFormDTO {
mode: LeagueStructureMode;
maxDrivers: number;
@@ -50,12 +62,40 @@ export interface LeagueConfigFormModel {
basics: {
name: string;
description?: string;
visibility: 'public' | 'private';
/**
* League visibility/ranking mode.
* - 'ranked' (or legacy 'public'): Competitive, public, affects ratings. Min 10 drivers.
* - 'unranked' (or legacy 'private'): Casual with friends, no rating impact.
*/
visibility: LeagueVisibilityFormValue;
gameId: string;
/**
* League logo as base64 data URL (optional).
* Format: data:image/png;base64,... or data:image/jpeg;base64,...
*/
logoDataUrl?: string;
};
structure: LeagueStructureFormDTO;
championships: LeagueChampionshipsFormDTO;
scoring: LeagueScoringFormDTO;
dropPolicy: LeagueDropPolicyFormDTO;
timings: LeagueTimingsFormDTO;
}
/**
* Helper to normalize visibility values to new terminology.
* Maps 'public' -> 'ranked' and 'private' -> 'unranked'.
*/
export function normalizeVisibility(value: LeagueVisibilityFormValue): LeagueVisibilityType {
if (value === 'public' || value === 'ranked') return 'ranked';
return 'unranked';
}
/**
* Helper to convert new terminology to legacy for backward compatibility.
* Maps 'ranked' -> 'public' and 'unranked' -> 'private'.
*/
export function toLegacyVisibility(value: LeagueVisibilityFormValue): 'public' | 'private' {
if (value === 'ranked' || value === 'public') return 'public';
return 'private';
}

View File

@@ -8,11 +8,27 @@ import type {
LeagueScoringPresetProvider,
LeagueScoringPresetDTO,
} from '../ports/LeagueScoringPresetProvider';
import {
LeagueVisibility,
MIN_RANKED_LEAGUE_DRIVERS,
} from '../../domain/value-objects/LeagueVisibility';
/**
* League visibility/ranking mode.
* - 'ranked' (or legacy 'public'): Competitive, public, affects driver ratings. Min 10 drivers.
* - 'unranked' (or legacy 'private'): Casual with friends, no rating impact.
*/
export type LeagueVisibilityInput = 'ranked' | 'unranked' | 'public' | 'private';
export interface CreateLeagueWithSeasonAndScoringCommand {
name: string;
description?: string;
visibility: 'public' | 'private';
/**
* League visibility/ranking mode.
* - 'ranked' (or legacy 'public'): Competitive, public, affects ratings. Requires min 10 drivers.
* - 'unranked' (or legacy 'private'): Casual with friends, no rating impact.
*/
visibility: LeagueVisibilityInput;
ownerId: string;
gameId: string;
maxDrivers?: number;
@@ -137,5 +153,20 @@ export class CreateLeagueWithSeasonAndScoringUseCase {
if (command.maxDrivers !== undefined && command.maxDrivers <= 0) {
throw new Error('maxDrivers must be greater than 0 when provided');
}
// Validate visibility-specific constraints
const visibility = LeagueVisibility.fromString(command.visibility);
if (visibility.isRanked()) {
// Ranked (public) leagues require minimum 10 drivers for competitive integrity
const driverCount = command.maxDrivers ?? 0;
if (driverCount < MIN_RANKED_LEAGUE_DRIVERS) {
throw new Error(
`Ranked leagues require at least ${MIN_RANKED_LEAGUE_DRIVERS} drivers. ` +
`Current setting: ${driverCount}. ` +
`For smaller groups, consider creating an Unranked (Friends) league instead.`
);
}
}
}
}