tods-competition-factory 1.7.2 → 1.7.3

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.
@@ -2962,7 +2962,7 @@ function getRoundMatchUps({
2962
2962
  roundProfile[roundNumber].finishingRound = finishingRoundMap[roundNumber]?.finishingRound;
2963
2963
  roundProfile[roundNumber].roundName = finishingRoundMap[roundNumber]?.roundName;
2964
2964
  roundProfile[roundNumber].abbreviatedRoundName = finishingRoundMap[roundNumber]?.abbreviatedRoundName;
2965
- roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber][0].finishingPositionRange;
2965
+ roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber]?.[0]?.finishingPositionRange;
2966
2966
  if (roundNumber === 1 || !roundProfile[roundNumber - 1]) {
2967
2967
  const orderedDrawPositions = currentRoundDrawPositions.sort(numericSort);
2968
2968
  const pairedDrawPositions = chunkArray(orderedDrawPositions, 2);
@@ -19714,21 +19714,30 @@ function generateAdHocMatchUps({
19714
19714
  structureId = drawDefinition.structures?.[0]?.structureId;
19715
19715
  if (typeof structureId !== "string")
19716
19716
  return { error: MISSING_STRUCTURE_ID };
19717
- if (newRound && !matchUpsCount) {
19717
+ const structure = drawDefinition.structures?.find(
19718
+ (structure2) => structure2.structureId === structureId
19719
+ );
19720
+ if (!structure)
19721
+ return { error: STRUCTURE_NOT_FOUND };
19722
+ if (!matchUpsCount) {
19718
19723
  const selectedEntries = drawDefinition?.entries?.filter((entry) => {
19719
19724
  const entryStatus = entry.entryStatus;
19720
19725
  return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
19721
19726
  }) ?? [];
19722
- matchUpsCount = Math.floor(selectedEntries?.length / 2) || 1;
19727
+ const roundMatchUpsCount = Math.floor(selectedEntries?.length / 2) || 1;
19728
+ if (newRound) {
19729
+ matchUpsCount = roundMatchUpsCount;
19730
+ } else {
19731
+ const maxRemaining = roundMatchUpsCount - (structure.matchUps?.length || 0);
19732
+ if (maxRemaining > 0)
19733
+ matchUpsCount = maxRemaining;
19734
+ }
19723
19735
  }
19724
19736
  if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
19725
19737
  return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
19726
19738
  }
19727
- const structure = drawDefinition?.structures?.find(
19728
- (structure2) => structure2.structureId === structureId
19729
- );
19730
19739
  let structureHasRoundPositions;
19731
- const existingMatchUps = structure?.matchUps;
19740
+ const existingMatchUps = structure.matchUps ?? [];
19732
19741
  const lastRoundNumber = existingMatchUps?.reduce(
19733
19742
  (roundNumber2, matchUp) => {
19734
19743
  if (matchUp.roundPosition)
@@ -19737,12 +19746,12 @@ function generateAdHocMatchUps({
19737
19746
  },
19738
19747
  0
19739
19748
  );
19740
- if (structure?.structures || structureHasRoundPositions || structure?.finishingPosition === ROUND_OUTCOME) {
19749
+ if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
19741
19750
  return { error: INVALID_STRUCTURE };
19742
19751
  }
19743
19752
  if (roundNumber && roundNumber - 1 > (lastRoundNumber || 0))
19744
19753
  return { error: INVALID_VALUES, info: "roundNumber error" };
19745
- const nextRoundNumber = roundNumber ?? (newRound ? (lastRoundNumber ?? 0) + 1 : lastRoundNumber ?? 1);
19754
+ const nextRoundNumber = roundNumber ?? (newRound && (lastRoundNumber ?? 0) + 1 || lastRoundNumber || 1);
19746
19755
  participantIdPairings = participantIdPairings ?? generateRange(0, matchUpsCount).map(() => ({
19747
19756
  participantIds: [void 0, void 0]
19748
19757
  }));