tods-competition-factory 1.7.10 → 1.7.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19695,6 +19695,16 @@ function generateAdHocMatchUps({
19695
19695
  );
19696
19696
  if (!structure)
19697
19697
  return { error: STRUCTURE_NOT_FOUND };
19698
+ let structureHasRoundPositions;
19699
+ const existingMatchUps = structure.matchUps ?? [];
19700
+ const lastRoundNumber = existingMatchUps?.reduce(
19701
+ (roundNumber2, matchUp) => {
19702
+ if (matchUp.roundPosition)
19703
+ structureHasRoundPositions = true;
19704
+ return (matchUp?.roundNumber || 0) > roundNumber2 ? matchUp.roundNumber : roundNumber2;
19705
+ },
19706
+ 0
19707
+ );
19698
19708
  if (!matchUpsCount) {
19699
19709
  const selectedEntries = drawDefinition?.entries?.filter((entry) => {
19700
19710
  const entryStatus = entry.entryStatus;
@@ -19704,7 +19714,11 @@ function generateAdHocMatchUps({
19704
19714
  if (newRound) {
19705
19715
  matchUpsCount = roundMatchUpsCount;
19706
19716
  } else {
19707
- const maxRemaining = roundMatchUpsCount - (structure.matchUps?.length || 0);
19717
+ const targetRoundNumber = roundNumber || lastRoundNumber || 1;
19718
+ const existingRoundMatchUps = structure.matchUps?.filter(
19719
+ (matchUp) => matchUp.roundNumber === targetRoundNumber
19720
+ )?.length || 0;
19721
+ const maxRemaining = roundMatchUpsCount - existingRoundMatchUps;
19708
19722
  if (maxRemaining > 0)
19709
19723
  matchUpsCount = maxRemaining;
19710
19724
  }
@@ -19712,16 +19726,6 @@ function generateAdHocMatchUps({
19712
19726
  if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
19713
19727
  return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
19714
19728
  }
19715
- let structureHasRoundPositions;
19716
- const existingMatchUps = structure.matchUps ?? [];
19717
- const lastRoundNumber = existingMatchUps?.reduce(
19718
- (roundNumber2, matchUp) => {
19719
- if (matchUp.roundPosition)
19720
- structureHasRoundPositions = true;
19721
- return (matchUp?.roundNumber || 0) > roundNumber2 ? matchUp.roundNumber : roundNumber2;
19722
- },
19723
- 0
19724
- );
19725
19729
  if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
19726
19730
  return { error: INVALID_STRUCTURE };
19727
19731
  }