tods-competition-factory 1.6.11 → 1.6.13

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.
@@ -1943,7 +1943,7 @@ function validMatchUp(matchUp) {
1943
1943
  const { matchUpId, drawPositions } = matchUp;
1944
1944
  const validMatchUpId = typeof matchUpId === "string";
1945
1945
  const validDrawPositions = !drawPositions || Array.isArray(drawPositions) && drawPositions.length <= 2 && drawPositions.every(
1946
- (dp) => isConvertableInteger(dp) || dp === void 0
1946
+ (dp) => isConvertableInteger(dp) || dp === void 0 || dp === null
1947
1947
  );
1948
1948
  return validMatchUpId && validDrawPositions;
1949
1949
  }
@@ -2186,7 +2186,7 @@ function getParticipantResults({
2186
2186
  const manualGamesOverride = tieFormat && matchUp._disableAutoCalc && tieFormat.collectionDefinitions.every(({ scoreValue }) => scoreValue);
2187
2187
  const winningParticipantId = winningSide && getWinningSideId(matchUp);
2188
2188
  const losingParticipantId = winningSide && getLosingSideId(matchUp);
2189
- if (!winningParticipantId || !losingParticipantId) {
2189
+ if (!winningParticipantId && !losingParticipantId) {
2190
2190
  if (completedMatchUpStatuses.includes(matchUpStatus)) {
2191
2191
  const participantIdSide1 = getSideId(matchUp, 0);
2192
2192
  const participantIdSide2 = getSideId(matchUp, 1);
@@ -2198,53 +2198,51 @@ function getParticipantResults({
2198
2198
  checkInitializeParticipant(participantResults, participantIdSide2);
2199
2199
  participantResults[participantIdSide2].matchUpsCancelled += 1;
2200
2200
  }
2201
- } else {
2202
- if (tieMatchUps?.length) {
2203
- perPlayer = 0;
2204
- for (const tieMatchUp of tieMatchUps) {
2205
- if (tieMatchUp.winningSide) {
2206
- const tieWinningParticipantId = sides.find(
2207
- ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
2208
- )?.participantId;
2209
- const tieLosingParticipantId = sides.find(
2210
- ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
2211
- )?.participantId;
2212
- if (tieWinningParticipantId && tieLosingParticipantId) {
2213
- checkInitializeParticipant(
2214
- participantResults,
2215
- tieWinningParticipantId
2216
- );
2217
- checkInitializeParticipant(
2218
- participantResults,
2219
- tieLosingParticipantId
2220
- );
2221
- participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
2222
- participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
2223
- if (tieMatchUp.matchUpType === SINGLES) {
2224
- participantResults[tieWinningParticipantId].tieSinglesWon += 1;
2225
- participantResults[tieLosingParticipantId].tieSinglesLost += 1;
2226
- } else if (tieMatchUp.matchUpType === DOUBLES) {
2227
- participantResults[tieWinningParticipantId].tieDoublesWon += 1;
2228
- participantResults[tieLosingParticipantId].tieDoublesLost += 1;
2229
- }
2201
+ } else if (tieMatchUps?.length) {
2202
+ perPlayer = 0;
2203
+ for (const tieMatchUp of tieMatchUps) {
2204
+ if (tieMatchUp.winningSide) {
2205
+ const tieWinningParticipantId = sides.find(
2206
+ ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
2207
+ )?.participantId;
2208
+ const tieLosingParticipantId = sides.find(
2209
+ ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
2210
+ )?.participantId;
2211
+ if (tieWinningParticipantId && tieLosingParticipantId) {
2212
+ checkInitializeParticipant(
2213
+ participantResults,
2214
+ tieWinningParticipantId
2215
+ );
2216
+ checkInitializeParticipant(
2217
+ participantResults,
2218
+ tieLosingParticipantId
2219
+ );
2220
+ participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
2221
+ participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
2222
+ if (tieMatchUp.matchUpType === SINGLES) {
2223
+ participantResults[tieWinningParticipantId].tieSinglesWon += 1;
2224
+ participantResults[tieLosingParticipantId].tieSinglesLost += 1;
2225
+ } else if (tieMatchUp.matchUpType === DOUBLES) {
2226
+ participantResults[tieWinningParticipantId].tieDoublesWon += 1;
2227
+ participantResults[tieLosingParticipantId].tieDoublesLost += 1;
2230
2228
  }
2231
2229
  }
2232
- processScore({
2233
- score: tieMatchUp.score,
2234
- manualGamesOverride,
2235
- participantResults,
2236
- sides
2237
- // use sides from the TEAM matchUp
2238
- });
2239
2230
  }
2240
- } else {
2241
2231
  processScore({
2232
+ score: tieMatchUp.score,
2242
2233
  manualGamesOverride,
2243
2234
  participantResults,
2244
- score,
2245
2235
  sides
2236
+ // use sides from the TEAM matchUp
2246
2237
  });
2247
2238
  }
2239
+ } else {
2240
+ processScore({
2241
+ manualGamesOverride,
2242
+ participantResults,
2243
+ score,
2244
+ sides
2245
+ });
2248
2246
  }
2249
2247
  } else {
2250
2248
  checkInitializeParticipant(participantResults, winningParticipantId);
@@ -5005,9 +5003,10 @@ function getSourceDrawPositionRanges({
5005
5003
  structureId: sourceStructureId,
5006
5004
  matchUpsMap
5007
5005
  });
5008
- const { roundProfile } = getRoundMatchUps({
5006
+ const roundMatchUpsResult = getRoundMatchUps({
5009
5007
  matchUps: structureMatchUps2
5010
5008
  });
5009
+ const roundProfile = roundMatchUpsResult.roundProfile;
5011
5010
  return { [sourceStructureId]: roundProfile };
5012
5011
  })
5013
5012
  );
@@ -11074,9 +11073,8 @@ function modifyMatchUpScore({
11074
11073
  return { error: MATCHUP_NOT_FOUND };
11075
11074
  ({ matchUp, structure } = findResult);
11076
11075
  }
11077
- } else {
11078
- if (matchUp.matchUpId !== matchUpId)
11079
- console.log("!!!!!");
11076
+ } else if (matchUp.matchUpId !== matchUpId) {
11077
+ console.log("!!!!!");
11080
11078
  }
11081
11079
  if (matchUpStatus && [WALKOVER$1, DOUBLE_WALKOVER].includes(matchUpStatus) || removeScore) {
11082
11080
  Object.assign(matchUp, { ...toBePlayed });
@@ -11114,31 +11112,45 @@ function modifyMatchUpScore({
11114
11112
  })?.appliedPolicies;
11115
11113
  defaultedProcessCodes = appliedPolicies?.[POLICY_TYPE_SCORING]?.processCodes?.incompleteAssignmentsOnDefault;
11116
11114
  }
11117
- if (structure?.structureType === CONTAINER && !matchUp.collectionId) {
11118
- matchUpFormat = isDualMatchUp ? "SET1-S:T100" : matchUpFormat || matchUp.matchUpFormat || structure?.matchUpFormat || drawDefinition?.matchUpFormat || event?.matchUpFormat;
11119
- const itemStructure = structure.structures.find((itemStructure2) => {
11120
- return itemStructure2?.matchUps.find(
11121
- (matchUp2) => matchUp2.matchUpId === matchUpId
11122
- );
11123
- });
11124
- const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
11125
- const { matchUps } = getAllStructureMatchUps({
11126
- afterRecoveryTimes: false,
11127
- structure: itemStructure,
11128
- inContext: true,
11129
- matchUpFilters,
11130
- event
11131
- });
11132
- const result = updateAssignmentParticipantResults({
11133
- positionAssignments: itemStructure.positionAssignments,
11134
- tournamentRecord,
11135
- drawDefinition,
11136
- matchUpFormat,
11137
- matchUps,
11138
- event
11139
- });
11140
- if (result.error)
11141
- return decorateResult({ result, stack });
11115
+ if (!matchUp.collectionId) {
11116
+ const isRoundRobin = structure?.structureType === CONTAINER;
11117
+ const isAdHocStructure = isAdHoc({ drawDefinition, structure });
11118
+ if (isLucky({ drawDefinition, structure }) || isAdHocStructure || isRoundRobin) {
11119
+ const updateTally = (structure2) => {
11120
+ matchUpFormat = isDualMatchUp ? "SET1-S:T100" : matchUpFormat ?? matchUp.matchUpFormat ?? structure2?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
11121
+ const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
11122
+ const { matchUps } = getAllStructureMatchUps({
11123
+ afterRecoveryTimes: false,
11124
+ inContext: true,
11125
+ matchUpFilters,
11126
+ structure: structure2,
11127
+ event
11128
+ });
11129
+ if (isAdHocStructure) {
11130
+ structure2.positionAssignments = unique(
11131
+ matchUps.flatMap(
11132
+ (matchUp2) => (matchUp2.sides ?? []).map((side) => side.participantId)
11133
+ ).filter(Boolean)
11134
+ ).map((participantId) => ({ participantId }));
11135
+ }
11136
+ return updateAssignmentParticipantResults({
11137
+ positionAssignments: structure2.positionAssignments,
11138
+ tournamentRecord,
11139
+ drawDefinition,
11140
+ matchUpFormat,
11141
+ matchUps,
11142
+ event
11143
+ });
11144
+ };
11145
+ const itemStructure = isRoundRobin && structure.structures.find((itemStructure2) => {
11146
+ return itemStructure2?.matchUps.find(
11147
+ (matchUp2) => matchUp2.matchUpId === matchUpId
11148
+ );
11149
+ });
11150
+ const result = updateTally(itemStructure || structure);
11151
+ if (result.error)
11152
+ return decorateResult({ result, stack });
11153
+ }
11142
11154
  }
11143
11155
  if (notes) {
11144
11156
  const result = addNotes({ element: matchUp, notes });
@@ -13097,7 +13109,7 @@ function getValidSeedBlocks({
13097
13109
  });
13098
13110
  const { positionAssignments } = structureAssignedDrawPositions({ structure });
13099
13111
  const positionsCount = positionAssignments?.length;
13100
- const seedsCount = seedAssignments?.length || 0;
13112
+ const seedsCount = seedAssignments?.length ?? 0;
13101
13113
  let allDrawPositions = [];
13102
13114
  const roundNumbers = Object.keys(roundMatchUps).map((n) => parseInt(n)).sort((a, b) => a - b);
13103
13115
  const uniqueDrawPositionsByRound = roundNumbers.map((roundNumber) => {