wip
This commit is contained in:
@@ -53,13 +53,13 @@ export function validateLeagueWizardStep(
|
||||
|
||||
// Use LeagueName value object for validation
|
||||
const nameValidation = LeagueName.validate(form.basics.name);
|
||||
if (!nameValidation.valid) {
|
||||
if (!nameValidation.valid && nameValidation.error) {
|
||||
basicsErrors.name = nameValidation.error;
|
||||
}
|
||||
|
||||
// Use LeagueDescription value object for validation
|
||||
const descValidation = LeagueDescription.validate(form.basics.description ?? '');
|
||||
if (!descValidation.valid) {
|
||||
if (!descValidation.valid && descValidation.error) {
|
||||
basicsErrors.description = descValidation.error;
|
||||
}
|
||||
|
||||
@@ -92,8 +92,10 @@ export function validateLeagueWizardStep(
|
||||
'Max drivers must be greater than 0 for solo leagues';
|
||||
} else {
|
||||
// Validate against game constraints
|
||||
const driverValidation = gameConstraints.validateDriverCount(form.structure.maxDrivers);
|
||||
if (!driverValidation.valid) {
|
||||
const driverValidation = gameConstraints.validateDriverCount(
|
||||
form.structure.maxDrivers,
|
||||
);
|
||||
if (!driverValidation.valid && driverValidation.error) {
|
||||
structureErrors.maxDrivers = driverValidation.error;
|
||||
}
|
||||
}
|
||||
@@ -103,8 +105,10 @@ export function validateLeagueWizardStep(
|
||||
'Max teams must be greater than 0 for team leagues';
|
||||
} else {
|
||||
// Validate against game constraints
|
||||
const teamValidation = gameConstraints.validateTeamCount(form.structure.maxTeams);
|
||||
if (!teamValidation.valid) {
|
||||
const teamValidation = gameConstraints.validateTeamCount(
|
||||
form.structure.maxTeams,
|
||||
);
|
||||
if (!teamValidation.valid && teamValidation.error) {
|
||||
structureErrors.maxTeams = teamValidation.error;
|
||||
}
|
||||
}
|
||||
@@ -114,8 +118,10 @@ export function validateLeagueWizardStep(
|
||||
}
|
||||
// Validate total driver count
|
||||
if (form.structure.maxDrivers) {
|
||||
const driverValidation = gameConstraints.validateDriverCount(form.structure.maxDrivers);
|
||||
if (!driverValidation.valid) {
|
||||
const driverValidation = gameConstraints.validateDriverCount(
|
||||
form.structure.maxDrivers,
|
||||
);
|
||||
if (!driverValidation.valid && driverValidation.error) {
|
||||
structureErrors.maxDrivers = driverValidation.error;
|
||||
}
|
||||
}
|
||||
@@ -197,7 +203,7 @@ export function validateAllLeagueWizardSteps(
|
||||
|
||||
export function hasWizardErrors(errors: WizardErrors): boolean {
|
||||
return Object.keys(errors).some((key) => {
|
||||
const value = (errors as any)[key];
|
||||
const value = errors[key as keyof WizardErrors];
|
||||
if (!value) return false;
|
||||
if (typeof value === 'string') return true;
|
||||
return Object.keys(value).length > 0;
|
||||
@@ -213,27 +219,31 @@ export function buildCreateLeagueCommandFromConfig(
|
||||
ownerId: string,
|
||||
): CreateLeagueWithSeasonAndScoringCommand {
|
||||
const structure = form.structure;
|
||||
let maxDrivers: number | undefined;
|
||||
let maxTeams: number | undefined;
|
||||
let maxDrivers: number;
|
||||
let maxTeams: number;
|
||||
|
||||
if (structure.mode === 'solo') {
|
||||
maxDrivers =
|
||||
typeof structure.maxDrivers === 'number' ? structure.maxDrivers : undefined;
|
||||
maxTeams = undefined;
|
||||
typeof structure.maxDrivers === 'number' && structure.maxDrivers > 0
|
||||
? structure.maxDrivers
|
||||
: 0;
|
||||
maxTeams = 0;
|
||||
} else {
|
||||
const teams =
|
||||
typeof structure.maxTeams === 'number' ? structure.maxTeams : 0;
|
||||
typeof structure.maxTeams === 'number' && structure.maxTeams > 0
|
||||
? structure.maxTeams
|
||||
: 0;
|
||||
const perTeam =
|
||||
typeof structure.driversPerTeam === 'number'
|
||||
typeof structure.driversPerTeam === 'number' && structure.driversPerTeam > 0
|
||||
? structure.driversPerTeam
|
||||
: 0;
|
||||
maxTeams = teams > 0 ? teams : undefined;
|
||||
maxDrivers = teams > 0 && perTeam > 0 ? teams * perTeam : undefined;
|
||||
maxTeams = teams;
|
||||
maxDrivers = teams > 0 && perTeam > 0 ? teams * perTeam : 0;
|
||||
}
|
||||
|
||||
return {
|
||||
name: form.basics.name.trim(),
|
||||
description: form.basics.description?.trim() || undefined,
|
||||
description: (form.basics.description ?? '').trim(),
|
||||
visibility: form.basics.visibility,
|
||||
ownerId,
|
||||
gameId: form.basics.gameId,
|
||||
@@ -243,7 +253,7 @@ export function buildCreateLeagueCommandFromConfig(
|
||||
enableTeamChampionship: form.championships.enableTeamChampionship,
|
||||
enableNationsChampionship: form.championships.enableNationsChampionship,
|
||||
enableTrophyChampionship: form.championships.enableTrophyChampionship,
|
||||
scoringPresetId: form.scoring.patternId || undefined,
|
||||
scoringPresetId: form.scoring.patternId ?? 'custom',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -263,8 +273,8 @@ export async function createLeagueFromConfig(
|
||||
if (!currentDriver) {
|
||||
const error = new Error(
|
||||
'No driver profile found. Please create a driver profile first.',
|
||||
);
|
||||
(error as any).code = 'NO_DRIVER';
|
||||
) as Error & { code?: string };
|
||||
error.code = 'NO_DRIVER';
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -283,7 +293,9 @@ export function applyScoringPresetToConfig(
|
||||
): LeagueConfigFormModel {
|
||||
const lowerPresetId = patternId.toLowerCase();
|
||||
const timings = form.timings ?? ({} as LeagueConfigFormModel['timings']);
|
||||
let updatedTimings = { ...timings };
|
||||
let updatedTimings: NonNullable<LeagueConfigFormModel['timings']> = {
|
||||
...timings,
|
||||
};
|
||||
|
||||
if (lowerPresetId.includes('sprint') || lowerPresetId.includes('double')) {
|
||||
updatedTimings = {
|
||||
@@ -299,19 +311,19 @@ export function applyScoringPresetToConfig(
|
||||
...updatedTimings,
|
||||
practiceMinutes: 30,
|
||||
qualifyingMinutes: 30,
|
||||
sprintRaceMinutes: undefined,
|
||||
mainRaceMinutes: 90,
|
||||
sessionCount: 1,
|
||||
};
|
||||
delete (updatedTimings as { sprintRaceMinutes?: number }).sprintRaceMinutes;
|
||||
} else {
|
||||
updatedTimings = {
|
||||
...updatedTimings,
|
||||
practiceMinutes: 20,
|
||||
qualifyingMinutes: 30,
|
||||
sprintRaceMinutes: undefined,
|
||||
mainRaceMinutes: 40,
|
||||
sessionCount: 1,
|
||||
};
|
||||
delete (updatedTimings as { sprintRaceMinutes?: number }).sprintRaceMinutes;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user