From 311118bb6d1798a3ab74f9c668fa43c6a494aab2 Mon Sep 17 00:00:00 2001 From: anter1994 Date: Tue, 19 Nov 2024 10:49:48 +0100 Subject: [PATCH] fix: updated reset qualifying structure method to prevent deleting structure when scores are present --- src/mutate/drawDefinitions/resetQualifyingStructure.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mutate/drawDefinitions/resetQualifyingStructure.ts b/src/mutate/drawDefinitions/resetQualifyingStructure.ts index a576ef206..357e5e0ff 100644 --- a/src/mutate/drawDefinitions/resetQualifyingStructure.ts +++ b/src/mutate/drawDefinitions/resetQualifyingStructure.ts @@ -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; @@ -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 = [];