Skip to content

Commit

Permalink
fix: updated reset qualifying structure method to prevent deleting st…
Browse files Browse the repository at this point in the history
…ructure when scores are present
  • Loading branch information
anter1994 committed Nov 19, 2024
1 parent 878bb6c commit 311118b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/mutate/drawDefinitions/resetQualifyingStructure.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { deleteMatchUpsNotice, modifyDrawNotice } from '@Mutate/notifications/drawNotifications';

// Constants
import { MISSING_DRAW_DEFINITION, STRUCTURE_NOT_FOUND } from '@Constants/errorConditionConstants';
import { MISSING_DRAW_DEFINITION, SCORES_PRESENT, STRUCTURE_NOT_FOUND } from '@Constants/errorConditionConstants';
import { DrawDefinition, Event, Tournament } from '@Types/tournamentTypes';
import { QUALIFYING } from '@Constants/drawDefinitionConstants';
import { SUCCESS } from '@Constants/resultConstants';
import { completedMatchUpStatuses } from '@Constants/matchUpStatusConstants';

interface ResetQualifyingStructureArgs {
tournamentRecord?: Tournament;
Expand All @@ -27,6 +28,12 @@ export function resetQualifyingStructure({

if (!structure) return { error: STRUCTURE_NOT_FOUND };

const completedMatchUps = structure.matchUps?.filter((matchUp) =>
completedMatchUpStatuses.includes(matchUp.matchUpStatus),
);

if (completedMatchUps?.length) return { error: SCORES_PRESENT };

const removedMatchUpIds = structure.matchUps?.map(({ matchUpId }) => matchUpId) || [];

structure.positionAssignments = [];
Expand Down

0 comments on commit 311118b

Please sign in to comment.