Skip to content

Commit

Permalink
fix: 🐛 either incomplete scores present or completed matchUpStatus ex…
Browse files Browse the repository at this point in the history
…its resetQualifyingStructure
  • Loading branch information
CourtHive committed Nov 28, 2024
1 parent 7829e28 commit cf897ac
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/mutate/drawDefinitions/resetQualifyingStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { deleteMatchUpsNotice, modifyDrawNotice } from '@Mutate/notifications/dr

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

interface ResetQualifyingStructureArgs {
tournamentRecord?: Tournament;
drawDefinition: DrawDefinition;
event?: Event;
structureId: string;
event?: Event;
}

export function resetQualifyingStructure({
Expand All @@ -28,11 +29,10 @@ export function resetQualifyingStructure({

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

const completedMatchUps = structure.matchUps?.filter((matchUp) =>
completedMatchUpStatuses.includes(matchUp.matchUpStatus),
const scoresPresent = structure.matchUps?.some(
({ matchUpStatus, score }) => checkScoreHasValue({ score }) ?? completedMatchUpStatuses.includes(matchUpStatus),
);

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

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

Expand Down

0 comments on commit cf897ac

Please sign in to comment.