tods-competition-factory 1.6.11 → 1.6.12

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.
package/dist/index.mjs CHANGED
@@ -329,7 +329,7 @@ const matchUpFormatCode = {
329
329
  };
330
330
 
331
331
  function factoryVersion() {
332
- return "1.6.11";
332
+ return "1.6.12";
333
333
  }
334
334
 
335
335
  function getObjectTieFormat(obj) {
@@ -3054,7 +3054,7 @@ function getParticipantResults({
3054
3054
  const manualGamesOverride = tieFormat && matchUp._disableAutoCalc && tieFormat.collectionDefinitions.every(({ scoreValue }) => scoreValue);
3055
3055
  const winningParticipantId = winningSide && getWinningSideId(matchUp);
3056
3056
  const losingParticipantId = winningSide && getLosingSideId(matchUp);
3057
- if (!winningParticipantId || !losingParticipantId) {
3057
+ if (!winningParticipantId && !losingParticipantId) {
3058
3058
  if (completedMatchUpStatuses.includes(matchUpStatus)) {
3059
3059
  const participantIdSide1 = getSideId(matchUp, 0);
3060
3060
  const participantIdSide2 = getSideId(matchUp, 1);
@@ -3066,53 +3066,51 @@ function getParticipantResults({
3066
3066
  checkInitializeParticipant(participantResults, participantIdSide2);
3067
3067
  participantResults[participantIdSide2].matchUpsCancelled += 1;
3068
3068
  }
3069
- } else {
3070
- if (tieMatchUps?.length) {
3071
- perPlayer = 0;
3072
- for (const tieMatchUp of tieMatchUps) {
3073
- if (tieMatchUp.winningSide) {
3074
- const tieWinningParticipantId = sides.find(
3075
- ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
3076
- )?.participantId;
3077
- const tieLosingParticipantId = sides.find(
3078
- ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
3079
- )?.participantId;
3080
- if (tieWinningParticipantId && tieLosingParticipantId) {
3081
- checkInitializeParticipant(
3082
- participantResults,
3083
- tieWinningParticipantId
3084
- );
3085
- checkInitializeParticipant(
3086
- participantResults,
3087
- tieLosingParticipantId
3088
- );
3089
- participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
3090
- participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
3091
- if (tieMatchUp.matchUpType === SINGLES$1) {
3092
- participantResults[tieWinningParticipantId].tieSinglesWon += 1;
3093
- participantResults[tieLosingParticipantId].tieSinglesLost += 1;
3094
- } else if (tieMatchUp.matchUpType === DOUBLES$1) {
3095
- participantResults[tieWinningParticipantId].tieDoublesWon += 1;
3096
- participantResults[tieLosingParticipantId].tieDoublesLost += 1;
3097
- }
3069
+ } else if (tieMatchUps?.length) {
3070
+ perPlayer = 0;
3071
+ for (const tieMatchUp of tieMatchUps) {
3072
+ if (tieMatchUp.winningSide) {
3073
+ const tieWinningParticipantId = sides.find(
3074
+ ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
3075
+ )?.participantId;
3076
+ const tieLosingParticipantId = sides.find(
3077
+ ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
3078
+ )?.participantId;
3079
+ if (tieWinningParticipantId && tieLosingParticipantId) {
3080
+ checkInitializeParticipant(
3081
+ participantResults,
3082
+ tieWinningParticipantId
3083
+ );
3084
+ checkInitializeParticipant(
3085
+ participantResults,
3086
+ tieLosingParticipantId
3087
+ );
3088
+ participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
3089
+ participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
3090
+ if (tieMatchUp.matchUpType === SINGLES$1) {
3091
+ participantResults[tieWinningParticipantId].tieSinglesWon += 1;
3092
+ participantResults[tieLosingParticipantId].tieSinglesLost += 1;
3093
+ } else if (tieMatchUp.matchUpType === DOUBLES$1) {
3094
+ participantResults[tieWinningParticipantId].tieDoublesWon += 1;
3095
+ participantResults[tieLosingParticipantId].tieDoublesLost += 1;
3098
3096
  }
3099
3097
  }
3100
- processScore({
3101
- score: tieMatchUp.score,
3102
- manualGamesOverride,
3103
- participantResults,
3104
- sides
3105
- // use sides from the TEAM matchUp
3106
- });
3107
3098
  }
3108
- } else {
3109
3099
  processScore({
3100
+ score: tieMatchUp.score,
3110
3101
  manualGamesOverride,
3111
3102
  participantResults,
3112
- score,
3113
3103
  sides
3104
+ // use sides from the TEAM matchUp
3114
3105
  });
3115
3106
  }
3107
+ } else {
3108
+ processScore({
3109
+ manualGamesOverride,
3110
+ participantResults,
3111
+ score,
3112
+ sides
3113
+ });
3116
3114
  }
3117
3115
  } else {
3118
3116
  checkInitializeParticipant(participantResults, winningParticipantId);
@@ -9652,9 +9650,8 @@ function modifyMatchUpScore({
9652
9650
  return { error: MATCHUP_NOT_FOUND };
9653
9651
  ({ matchUp, structure } = findResult);
9654
9652
  }
9655
- } else {
9656
- if (matchUp.matchUpId !== matchUpId)
9657
- console.log("!!!!!");
9653
+ } else if (matchUp.matchUpId !== matchUpId) {
9654
+ console.log("!!!!!");
9658
9655
  }
9659
9656
  if (matchUpStatus && [WALKOVER$2, DOUBLE_WALKOVER].includes(matchUpStatus) || removeScore) {
9660
9657
  Object.assign(matchUp, { ...toBePlayed });
@@ -9692,31 +9689,45 @@ function modifyMatchUpScore({
9692
9689
  })?.appliedPolicies;
9693
9690
  defaultedProcessCodes = appliedPolicies?.[POLICY_TYPE_SCORING]?.processCodes?.incompleteAssignmentsOnDefault;
9694
9691
  }
9695
- if (structure?.structureType === CONTAINER && !matchUp.collectionId) {
9696
- matchUpFormat = isDualMatchUp ? "SET1-S:T100" : matchUpFormat || matchUp.matchUpFormat || structure?.matchUpFormat || drawDefinition?.matchUpFormat || event?.matchUpFormat;
9697
- const itemStructure = structure.structures.find((itemStructure2) => {
9698
- return itemStructure2?.matchUps.find(
9699
- (matchUp2) => matchUp2.matchUpId === matchUpId
9700
- );
9701
- });
9702
- const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
9703
- const { matchUps } = getAllStructureMatchUps({
9704
- afterRecoveryTimes: false,
9705
- structure: itemStructure,
9706
- inContext: true,
9707
- matchUpFilters,
9708
- event
9709
- });
9710
- const result = updateAssignmentParticipantResults({
9711
- positionAssignments: itemStructure.positionAssignments,
9712
- tournamentRecord,
9713
- drawDefinition,
9714
- matchUpFormat,
9715
- matchUps,
9716
- event
9717
- });
9718
- if (result.error)
9719
- return decorateResult({ result, stack });
9692
+ if (!matchUp.collectionId) {
9693
+ const isRoundRobin = structure?.structureType === CONTAINER;
9694
+ const isAdHocStructure = isAdHoc({ drawDefinition, structure });
9695
+ if (isLucky({ drawDefinition, structure }) || isAdHocStructure || isRoundRobin) {
9696
+ const updateTally = (structure2) => {
9697
+ matchUpFormat = isDualMatchUp ? "SET1-S:T100" : matchUpFormat ?? matchUp.matchUpFormat ?? structure2?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
9698
+ const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
9699
+ const { matchUps } = getAllStructureMatchUps({
9700
+ afterRecoveryTimes: false,
9701
+ inContext: true,
9702
+ matchUpFilters,
9703
+ structure: structure2,
9704
+ event
9705
+ });
9706
+ if (isAdHocStructure) {
9707
+ structure2.positionAssignments = unique(
9708
+ matchUps.flatMap(
9709
+ (matchUp2) => (matchUp2.sides ?? []).map((side) => side.participantId)
9710
+ ).filter(Boolean)
9711
+ ).map((participantId) => ({ participantId }));
9712
+ }
9713
+ return updateAssignmentParticipantResults({
9714
+ positionAssignments: structure2.positionAssignments,
9715
+ tournamentRecord,
9716
+ drawDefinition,
9717
+ matchUpFormat,
9718
+ matchUps,
9719
+ event
9720
+ });
9721
+ };
9722
+ const itemStructure = isRoundRobin && structure.structures.find((itemStructure2) => {
9723
+ return itemStructure2?.matchUps.find(
9724
+ (matchUp2) => matchUp2.matchUpId === matchUpId
9725
+ );
9726
+ });
9727
+ const result = updateTally(itemStructure || structure);
9728
+ if (result.error)
9729
+ return decorateResult({ result, stack });
9730
+ }
9720
9731
  }
9721
9732
  if (notes) {
9722
9733
  const result = addNotes({ element: matchUp, notes });
@@ -23020,7 +23031,7 @@ function getValidSeedBlocks({
23020
23031
  });
23021
23032
  const { positionAssignments } = structureAssignedDrawPositions({ structure });
23022
23033
  const positionsCount = positionAssignments?.length;
23023
- const seedsCount = seedAssignments?.length || 0;
23034
+ const seedsCount = seedAssignments?.length ?? 0;
23024
23035
  let allDrawPositions = [];
23025
23036
  const roundNumbers = Object.keys(roundMatchUps).map((n) => parseInt(n)).sort((a, b) => a - b);
23026
23037
  const uniqueDrawPositionsByRound = roundNumbers.map((roundNumber) => {
@@ -23282,7 +23293,7 @@ function getNextSeedBlock(params) {
23282
23293
  const seedsWithoutDrawPositions = seedAssignments?.filter(
23283
23294
  (assignment) => !assignment.participantId
23284
23295
  );
23285
- const seedsLeftToAssign = unplacedSeedAssignments?.length || seedsWithoutDrawPositions?.length;
23296
+ const seedsLeftToAssign = unplacedSeedAssignments?.length && unplacedSeedAssignments.length > 0 ? unplacedSeedAssignments.length : seedsWithoutDrawPositions?.length ?? 0;
23286
23297
  const unfilled = seedsLeftToAssign && nextSeedBlock?.drawPositions.filter(
23287
23298
  (drawPosition) => !assignedDrawPositions?.includes(drawPosition)
23288
23299
  ) || [];
@@ -28483,7 +28494,7 @@ function getParticipantEntries(params) {
28483
28494
  }));
28484
28495
  }
28485
28496
  const addEventEntry = (id) => {
28486
- if (participantMap[id]?.events[eventId])
28497
+ if (participantMap[id]?.events?.[eventId])
28487
28498
  return;
28488
28499
  const participant = participantMap[id];
28489
28500
  processEventEntry({
@@ -28552,7 +28563,7 @@ function getParticipantEntries(params) {
28552
28563
  const relevantEntries = entries2.filter(
28553
28564
  ({ participantId }) => assignedParticipantIds.includes(participantId)
28554
28565
  );
28555
- const publishedSeeding2 = eventsPublishStatuses[eventId]?.publishedSeeding;
28566
+ const publishedSeeding2 = eventsPublishStatuses?.[eventId]?.publishedSeeding;
28556
28567
  const seedingPublished = !usePublishState || publishedSeeding2?.published && (publishedSeeding2?.drawIds?.length === 0 || publishedSeeding2?.drawIds?.includes(drawId));
28557
28568
  for (const entry of relevantEntries) {
28558
28569
  const { entryStatus, entryStage, entryPosition, participantId } = entry;
@@ -28562,7 +28573,7 @@ function getParticipantEntries(params) {
28562
28573
  eventType
28563
28574
  });
28564
28575
  const addDrawEntry = (id) => {
28565
- if (participantMap[id].draws[drawId])
28576
+ if (participantMap[id].draws?.[drawId])
28566
28577
  return;
28567
28578
  const includeSeeding = withSeeding && seedingPublished;
28568
28579
  const seedAssignments = includeSeeding ? {} : void 0;
@@ -28894,9 +28905,9 @@ function getParticipants$1(params) {
28894
28905
  withIOC
28895
28906
  });
28896
28907
  const entriesResult = getParticipantEntries({
28897
- withMatchUps: withMatchUps || withRankingProfile,
28898
- withEvents: withEvents || withRankingProfile,
28899
- withDraws: withDraws || withRankingProfile,
28908
+ withMatchUps: withMatchUps ?? withRankingProfile,
28909
+ withEvents: withEvents ?? withRankingProfile,
28910
+ withDraws: withDraws ?? withRankingProfile,
28900
28911
  withPotentialMatchUps,
28901
28912
  participantFilters,
28902
28913
  withRankingProfile,
@@ -28922,7 +28933,7 @@ function getParticipants$1(params) {
28922
28933
  } = entriesResult;
28923
28934
  const matchUps = entriesResult.matchUps;
28924
28935
  participantMap = entriesResult.participantMap;
28925
- const nextMatchUps = scheduleAnalysis || withPotentialMatchUps;
28936
+ const nextMatchUps = scheduleAnalysis ?? withPotentialMatchUps;
28926
28937
  const processedParticipants = Object.values(participantMap).map(
28927
28938
  ({
28928
28939
  potentialMatchUps,