tods-competition-factory 2.1.16 → 2.1.18

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.
@@ -2711,12 +2711,13 @@ declare function qualifierDrawPositionAssignment(params: any): ResultType | {
2711
2711
  };
2712
2712
  };
2713
2713
 
2714
- declare function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, }: {
2714
+ declare function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, event, }: {
2715
2715
  alternateParticipantId: any;
2716
2716
  tournamentRecord: any;
2717
2717
  drawDefinition: any;
2718
2718
  drawPosition: any;
2719
2719
  structureId: any;
2720
+ event: any;
2720
2721
  }): ResultType | {
2721
2722
  error: {
2722
2723
  message: string;
@@ -4200,13 +4201,13 @@ type ModifyEventEntriesArgs = {
4200
4201
  };
4201
4202
  declare function modifyEventEntries({ entryStatus, unpairedParticipantIds, participantIdPairs, entryStage, tournamentRecord, event, }: ModifyEventEntriesArgs): any;
4202
4203
 
4203
- declare function addDrawEntries({ suppressDuplicateEntries, autoEntryPositions, entryStageSequence, ignoreStageSpace, drawDefinition, participantIds, entryStatus, roundTarget, entryStage, extension, drawId, event, }: {
4204
+ declare function addDrawEntries({ suppressDuplicateEntries, autoEntryPositions, entryStageSequence, ignoreStageSpace, participantIds, drawDefinition, entryStatus, roundTarget, entryStage, extension, drawId, event, }: {
4204
4205
  suppressDuplicateEntries?: boolean | undefined;
4205
4206
  autoEntryPositions?: boolean | undefined;
4206
4207
  entryStageSequence: any;
4207
4208
  ignoreStageSpace: any;
4208
- drawDefinition: any;
4209
4209
  participantIds: any;
4210
+ drawDefinition: any;
4210
4211
  entryStatus: any;
4211
4212
  roundTarget: any;
4212
4213
  entryStage: any;
@@ -4451,15 +4452,7 @@ declare function refreshEventDrawOrder({ tournamentRecord, event }: {
4451
4452
  info?: undefined;
4452
4453
  };
4453
4454
 
4454
- declare function modifyPairAssignment({ replacementIndividualParticipantId, existingIndividualParticipantId, tournamentRecord, drawDefinition, participantId, event, uuids, }: {
4455
- replacementIndividualParticipantId: any;
4456
- existingIndividualParticipantId: any;
4457
- tournamentRecord: any;
4458
- drawDefinition: any;
4459
- participantId: any;
4460
- event: any;
4461
- uuids: any;
4462
- }): any;
4455
+ declare function modifyPairAssignment(params: any): any;
4463
4456
 
4464
4457
  declare function updateDrawIdsOrder({ event, orderedDrawIdsMap }: {
4465
4458
  event: any;
@@ -6593,7 +6586,12 @@ declare function modifyPenalty(params: any): {
6593
6586
  };
6594
6587
  };
6595
6588
 
6596
- declare function deleteParticipants(params: any): {
6589
+ type DeleteParticipantsArgs = {
6590
+ addIndividualParticipantsToEvents?: boolean;
6591
+ tournamentRecord: Tournament;
6592
+ participantIds: string[];
6593
+ };
6594
+ declare function deleteParticipants(params: DeleteParticipantsArgs): {
6597
6595
  participantsRemovedCount?: number;
6598
6596
  success?: boolean;
6599
6597
  error?: ErrorType;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.1.16';
6
+ return '2.1.18';
7
7
  }
8
8
 
9
9
  const SINGLES_MATCHUP = 'SINGLES';
@@ -4442,6 +4442,7 @@ const ONE_OF = '_oneOf';
4442
4442
  const validators = {
4443
4443
  [ONLINE_RESOURCE]: (value) => intersection(Object.keys(value), [RESOURCE_SUB_TYPE, RESOURCE_TYPE, IDENTIFIER]).length === 3,
4444
4444
  [TIE_FORMAT_NAME]: (value) => value && tieFormatDefaults({ namedFormat: value }),
4445
+ [UUIDS]: (value) => !value || (Array.isArray(value) && value.every(isString)),
4445
4446
  [TIE_FORMAT]: (value) => !validateTieFormat({ tieFormat: value }).error,
4446
4447
  [EVENT_TYPE]: (value) => [SINGLES, DOUBLES, TEAM$1].includes(value),
4447
4448
  [ENTRY_STAGE]: (value) => validStages.includes(value),
@@ -10363,9 +10364,8 @@ function addMatchUpContext({ scheduleVisibilityFilters, sourceDrawPositionRanges
10363
10364
  if (participant) {
10364
10365
  if (drawDefinition?.entries) {
10365
10366
  const entry = drawDefinition.entries.find((entry) => entry.participantId === side.participantId);
10366
- if (entry?.entryStatus) {
10367
- participant.entryStatus = entry.entryStatus;
10368
- }
10367
+ const eEntry = event?.entries?.find((entry) => entry.participantId === side.participantId);
10368
+ participant.entryStatus = entry?.entryStatus || eEntry?.entryStatus;
10369
10369
  if (entry?.entryStage) {
10370
10370
  participant.entryStage = entry.entryStage;
10371
10371
  }
@@ -13849,11 +13849,11 @@ function getParticipantEntries(params) {
13849
13849
  const drawIds = unique([...drawDefinitions.map(getDrawId), ...flights.map(getDrawId)]);
13850
13850
  for (const drawId of drawIds) {
13851
13851
  const drawDefinition = drawDefinitions.find((drawDefinition) => drawDefinition.drawId === drawId);
13852
+ const scaleNames = [category?.categoryName, category?.ageCategoryCode].filter(Boolean);
13853
+ const { structures = [], drawOrder, drawName, drawType } = drawDefinition ?? {};
13852
13854
  const flight = flights?.find((flight) => flight.drawId === drawId);
13853
13855
  const entries = drawDefinition?.entries || flight?.drawEntries;
13854
- const { structures = [], drawOrder, drawName, drawType } = drawDefinition ?? {};
13855
13856
  const flightNumber = flight?.flightNumber;
13856
- const scaleNames = [category?.categoryName, category?.ageCategoryCode].filter(Boolean);
13857
13857
  const orderedStructureIds = (drawDefinition?.structures || [])
13858
13858
  .sort((a, b) => structureSort(a, b))
13859
13859
  .map(({ structureId, structures }) => {
@@ -14727,7 +14727,7 @@ function addDrawEntries$1(params) {
14727
14727
  : { ...SUCCESS };
14728
14728
  }
14729
14729
 
14730
- function addDrawEntries({ suppressDuplicateEntries = true, autoEntryPositions = true, entryStageSequence, ignoreStageSpace, drawDefinition, participantIds, entryStatus, roundTarget, entryStage, extension, drawId, event, }) {
14730
+ function addDrawEntries({ suppressDuplicateEntries = true, autoEntryPositions = true, entryStageSequence, ignoreStageSpace, participantIds, drawDefinition, entryStatus, roundTarget, entryStage, extension, drawId, event, }) {
14731
14731
  if (!participantIds?.length)
14732
14732
  return { error: MISSING_PARTICIPANT_IDS };
14733
14733
  if (!event)
@@ -14745,8 +14745,8 @@ function addDrawEntries({ suppressDuplicateEntries = true, autoEntryPositions =
14745
14745
  autoEntryPositions,
14746
14746
  stage: entryStage,
14747
14747
  ignoreStageSpace,
14748
- drawDefinition,
14749
14748
  participantIds,
14749
+ drawDefinition,
14750
14750
  entryStatus,
14751
14751
  roundTarget,
14752
14752
  extension,
@@ -15231,10 +15231,12 @@ function removeParticipantIdsFromAllTeams({ participantRole = COMPETITOR, indivi
15231
15231
  }
15232
15232
 
15233
15233
  function deleteParticipants(params) {
15234
- if (!params?.tournamentRecord)
15235
- return { error: MISSING_TOURNAMENT_RECORD };
15236
- if (!params?.participantIds?.length)
15237
- return { error: MISSING_PARTICIPANT_IDS };
15234
+ const paramsCheck = checkRequiredParameters(params, [
15235
+ { [TOURNAMENT_RECORD]: true },
15236
+ { participantIds: true, [OF_TYPE]: ARRAY, [ERROR]: MISSING_PARTICIPANT_IDS },
15237
+ ]);
15238
+ if (paramsCheck.error)
15239
+ return paramsCheck;
15238
15240
  const { addIndividualParticipantsToEvents, tournamentRecord, participantIds } = params;
15239
15241
  const participantsCount = tournamentRecord.participants?.length || 0;
15240
15242
  if (!participantsCount)
@@ -15248,18 +15250,17 @@ function deleteParticipants(params) {
15248
15250
  tournamentRecord,
15249
15251
  withDraws: true,
15250
15252
  }).participants ?? [];
15251
- const getPlacedPairParticipantIds = () => {
15253
+ const getPlacedPairParticipantIds = (teamDrawIds) => {
15252
15254
  const matchUps = allTournamentMatchUps({
15253
15255
  matchUpFilters: { drawIds: teamDrawIds, matchUpTypes: [DOUBLES$1] },
15254
15256
  tournamentRecord,
15255
15257
  }).matchUps ?? [];
15256
15258
  const placedPairParticipantIds = matchUps
15257
- .map(({ sides }) => sides?.map(({ participantId }) => participantId))
15258
- .flat()
15259
+ .flatMap(({ sides }) => sides?.map(({ participantId }) => participantId || []))
15259
15260
  .filter(Boolean);
15260
15261
  return intersection(placedPairParticipantIds, participantIds);
15261
15262
  };
15262
- const placedPairParticipantIds = teamDrawIds?.length && getPlacedPairParticipantIds();
15263
+ const placedPairParticipantIds = teamDrawIds?.length ? getPlacedPairParticipantIds(teamDrawIds) : [];
15263
15264
  const participantsInDraws = tournamentParticipants.filter((participant) => participant.draws?.filter((drawInfo) => (!teamDrawIds?.length || !teamDrawIds?.includes(drawInfo.drawId)) && drawInfo.positionAssignments).length);
15264
15265
  if (placedPairParticipantIds?.length || participantsInDraws.length) {
15265
15266
  return { error: EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT };
@@ -15275,17 +15276,18 @@ function deleteParticipants(params) {
15275
15276
  return result;
15276
15277
  eventParticipantIdsRemoved[event.eventId] = result.participantIdsRemoved;
15277
15278
  }
15278
- tournamentRecord.participants = tournamentRecord.participants.filter((participant) => {
15279
+ tournamentRecord.participants = (tournamentRecord.participants ?? []).filter((participant) => {
15279
15280
  const participantToRemove = participantIds.includes(participant.participantId) ||
15280
15281
  (participant.participantType === PAIR &&
15281
- participant.individualParticipantIds.some((id) => participantIds.includes(id)));
15282
+ participant.individualParticipantIds?.some((id) => participantIds.includes(id)));
15282
15283
  if (!participantToRemove &&
15283
15284
  participant.participantType === TEAM$1 &&
15284
- participant.individualParticipantIds.some((id) => participantIds.includes(id))) {
15285
+ participant.individualParticipantIds?.some((id) => participantIds.includes(id))) {
15285
15286
  participant.individualParticipantIds = participant.individualParticipantIds.filter((id) => !participantIds.includes(id));
15286
15287
  }
15287
15288
  if (participantToRemove &&
15288
15289
  addIndividualParticipantsToEvents &&
15290
+ participant.participantType &&
15289
15291
  [PAIR, TEAM].includes(participant.participantType)) {
15290
15292
  for (const individualParticipantId of participant.individualParticipantIds || []) {
15291
15293
  if (!participantIds.includes(individualParticipantId)) {
@@ -17035,6 +17037,18 @@ function assignDrawPosition$1({ provisionalPositioning, inContextDrawMatchUps, i
17035
17037
  });
17036
17038
  }
17037
17039
  }
17040
+ const drawEntry = drawDefinition.entries?.find((entry) => entry.participantId === participantId);
17041
+ const eventEntry = event?.entries?.find((entry) => entry.participantId === participantId);
17042
+ if (!drawEntry && eventEntry) {
17043
+ addDrawEntry({
17044
+ entryStatus: eventEntry.entryStatus,
17045
+ entryStage: structure.stage,
17046
+ ignoreStageSpace: true,
17047
+ drawDefinition,
17048
+ participantId,
17049
+ event,
17050
+ });
17051
+ }
17038
17052
  modifyPositionAssignmentsNotice({
17039
17053
  tournamentId: tournamentRecord?.tournamentId,
17040
17054
  drawDefinition,
@@ -17379,7 +17393,7 @@ function qualifierDrawPositionAssignment(params) {
17379
17393
  return qualifierDrawPositionAssignment$1(params);
17380
17394
  }
17381
17395
 
17382
- function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, }) {
17396
+ function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, event, }) {
17383
17397
  return positionParticipantAction({
17384
17398
  positionActionName: 'alternateDrawPositionAssignment',
17385
17399
  participantIdAttributeName: 'alternateParticipantid',
@@ -17388,6 +17402,7 @@ function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRec
17388
17402
  drawDefinition,
17389
17403
  drawPosition,
17390
17404
  structureId,
17405
+ event,
17391
17406
  });
17392
17407
  }
17393
17408
 
@@ -24764,12 +24779,19 @@ function deleteAdHocMatchUps(params) {
24764
24779
  .flatMap((matchUp) => (matchUp.sides ?? []).map((side) => side.participantId))
24765
24780
  .filter(Boolean)).map((participantId) => ({ participantId }));
24766
24781
  const matchUpFormat = structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
24782
+ const isDualMatchUp = structureResult.existingMatchUps.some((matchUp) => matchUp.matchUpType === TEAM_MATCHUP);
24783
+ const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM_MATCHUP] } : undefined;
24767
24784
  const { matchUps } = getAllStructureMatchUps({
24768
24785
  afterRecoveryTimes: false,
24769
24786
  inContext: true,
24787
+ matchUpFilters,
24770
24788
  structure,
24771
24789
  event,
24772
24790
  });
24791
+ const isAdHocStructure = isAdHoc({ structure });
24792
+ if (isAdHocStructure) {
24793
+ structure.positionAssignments = unique(matchUps.flatMap((matchUp) => (matchUp.sides ?? []).map((side) => side.participantId)).filter(Boolean)).map((participantId) => ({ participantId }));
24794
+ }
24773
24795
  const result = updateAssignmentParticipantResults({
24774
24796
  positionAssignments: structure.positionAssignments,
24775
24797
  tournamentRecord,
@@ -25651,9 +25673,7 @@ function getValidAlternatesAction({ tournamentParticipants = [], possiblyDisabli
25651
25673
  .sort((a, b) => (a.entryPosition ?? Infinity) - (b.entryPosition ?? Infinity))
25652
25674
  .map(({ participantId }) => participantId)
25653
25675
  .filter(Boolean);
25654
- const { allPositionedParticipantIds } = getAllPositionedParticipantIds({
25655
- drawDefinition,
25656
- });
25676
+ const { allPositionedParticipantIds } = getAllPositionedParticipantIds({ drawDefinition });
25657
25677
  const assignedParticipantIds = positionAssignments.map((assignment) => assignment.participantId).filter(Boolean);
25658
25678
  const availableDrawEnteredParticipantIds = drawEnteredParticipantIds.filter((participantId) => structure.stage && [QUALIFYING, MAIN, PLAY_OFF].includes(structure.stage)
25659
25679
  ? !allPositionedParticipantIds?.includes(participantId)
@@ -34805,9 +34825,8 @@ function getDrawData(params) {
34805
34825
  if (structure.stage && [MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
34806
34826
  seedAssignments = mainStageSeedAssignments;
34807
34827
  }
34808
- if (structure?.stage === QUALIFYING) {
34828
+ if (structure?.stage === QUALIFYING)
34809
34829
  seedAssignments = qualificationStageSeedAssignments;
34810
- }
34811
34830
  const { matchUps, roundMatchUps, roundProfile } = getAllStructureMatchUps({
34812
34831
  seedAssignments: !structure?.seedAssignments?.length ? seedAssignments : undefined,
34813
34832
  context: { drawId: drawInfo.drawId, ...context },
@@ -34821,9 +34840,7 @@ function getDrawData(params) {
34821
34840
  structure,
34822
34841
  event,
34823
34842
  });
34824
- const { positionAssignments } = getPositionAssignments$1({
34825
- structure,
34826
- });
34843
+ const { positionAssignments } = getPositionAssignments$1({ structure });
34827
34844
  let participantResults = positionAssignments?.filter(xa(PARTICIPANT_ID)).map((assignment) => {
34828
34845
  const participantResult = findExtension({ element: assignment, name: TALLY })?.extension?.value;
34829
34846
  const { drawPosition, participantId } = assignment;
@@ -34838,12 +34855,16 @@ function getDrawData(params) {
34838
34855
  ((!participantResults?.length && params.allParticipantResults) ||
34839
34856
  (refreshResults && !structure.structures))) {
34840
34857
  const { subOrderMap } = createSubOrderMap({ positionAssignments });
34858
+ const hasTeamMatchUps = matchUps.some((matchUp) => matchUp.matchUpType === TEAM_MATCHUP);
34859
+ const consideredMatchUps = hasTeamMatchUps
34860
+ ? matchUps.filter((matchUp) => matchUp.matchUpType === TEAM_MATCHUP)
34861
+ : matchUps;
34841
34862
  const result = tallyParticipantResults({
34842
34863
  matchUpFormat: structure.matchUpFormat,
34864
+ matchUps: consideredMatchUps,
34843
34865
  policyDefinitions,
34844
34866
  pressureRating,
34845
34867
  subOrderMap,
34846
- matchUps,
34847
34868
  });
34848
34869
  participantResults = positionAssignments?.filter(xa(PARTICIPANT_ID)).map((assignment) => {
34849
34870
  const { drawPosition, participantId } = assignment;
@@ -39901,18 +39922,22 @@ function deleteFlightAndFlightDraw({ autoPublish = true, tournamentRecord, audit
39901
39922
  return refreshEventDrawOrder({ tournamentRecord, event });
39902
39923
  }
39903
39924
 
39904
- function modifyPairAssignment({ replacementIndividualParticipantId, existingIndividualParticipantId, tournamentRecord, drawDefinition, participantId, event, uuids, }) {
39905
- if (!event)
39906
- return { error: MISSING_EVENT };
39925
+ function modifyPairAssignment(params) {
39926
+ const paramsCheck = checkRequiredParameters(params, [
39927
+ { [EVENT]: true, [TOURNAMENT_RECORD]: true, [UUIDS]: false },
39928
+ {
39929
+ replacementIndividualParticipantId: true,
39930
+ [VALIDATE]: (value) => isString(value),
39931
+ existingIndividualParticipantId: true,
39932
+ [ERROR]: MISSING_PARTICIPANT_ID,
39933
+ participantId: true,
39934
+ },
39935
+ ]);
39936
+ const { replacementIndividualParticipantId, existingIndividualParticipantId, tournamentRecord, drawDefinition, participantId, event, uuids, } = params;
39937
+ if (paramsCheck.error)
39938
+ return paramsCheck;
39907
39939
  if (event?.eventType !== DOUBLES)
39908
39940
  return { error: INVALID_EVENT_TYPE };
39909
- if (uuids && !Array.isArray(uuids))
39910
- return { error: INVALID_VALUES };
39911
- if (!tournamentRecord)
39912
- return { error: MISSING_TOURNAMENT_RECORD };
39913
- if (![replacementIndividualParticipantId, existingIndividualParticipantId, participantId].every((id) => typeof id === 'string')) {
39914
- return { error: MISSING_PARTICIPANT_ID };
39915
- }
39916
39941
  const availableIndividualParticipantIds = event?.entries
39917
39942
  ?.filter(({ entryStatus }) => [UNGROUPED, UNPAIRED].includes(entryStatus))
39918
39943
  .map(({ participantId }) => participantId) || [];
@@ -39959,18 +39984,19 @@ function modifyPairAssignment({ replacementIndividualParticipantId, existingIndi
39959
39984
  }
39960
39985
  drawDefinition.entries = drawDefinition.entries.map((entry) => entry.participantId === participantId ? { ...entry, participantId: newPairParticipantId } : entry);
39961
39986
  for (const structure of drawDefinition.structures || []) {
39962
- if (structure.positionAssignments) {
39963
- structure.positionAssignments = structure.positionAssignments.map((assignment) => assignment.participantId === participantId
39964
- ? { ...assignment, participantId: newPairParticipantId }
39965
- : assignment);
39966
- }
39967
- else if (structure.structures) {
39987
+ if (structure.structures) {
39988
+ structure.positionAssignments = undefined;
39968
39989
  for (const subStructure of structure.structures) {
39969
39990
  subStructure.positionAssignments = subStructure.positionAssignments.map((assignment) => assignment.participantId === participantId
39970
39991
  ? { ...assignment, participantId: newPairParticipantId }
39971
39992
  : assignment);
39972
39993
  }
39973
39994
  }
39995
+ else if (structure.positionAssignments) {
39996
+ structure.positionAssignments = structure.positionAssignments.map((assignment) => assignment.participantId === participantId
39997
+ ? { ...assignment, participantId: newPairParticipantId }
39998
+ : assignment);
39999
+ }
39974
40000
  }
39975
40001
  }
39976
40002
  event.entries = event.entries.map((entry) => (entry.participantId === participantId && {
@@ -40428,7 +40454,9 @@ function modifyEvent(params) {
40428
40454
  const enteredParticipants = getEnteredParticipants(params);
40429
40455
  const participantsProfile = getParticipantsProfile({ enteredParticipants });
40430
40456
  const { enteredParticipantGenders, enteredParticipantTypes } = participantsProfile;
40431
- const genderResult = checkGenderUpdates({ enteredParticipantGenders, eventUpdates, stack });
40457
+ const flights = getFlightProfile({ event })?.flightProfile?.flights;
40458
+ const noFlightsNoDraws = !event.drawDefinitions?.length && !flights?.length;
40459
+ const genderResult = checkGenderUpdates({ noFlightsNoDraws, enteredParticipantGenders, eventUpdates, stack });
40432
40460
  if (genderResult.error)
40433
40461
  return genderResult;
40434
40462
  const eventTypeResult = checkEventType({ enteredParticipantTypes, eventUpdates, stack });
@@ -40543,10 +40571,12 @@ function getParticipantsProfile({ enteredParticipants }) {
40543
40571
  const enteredParticipantGenders = unique(genderAccumulator);
40544
40572
  return { enteredParticipantTypes, enteredParticipantGenders };
40545
40573
  }
40546
- function checkGenderUpdates({ enteredParticipantGenders, eventUpdates, stack }) {
40574
+ function checkGenderUpdates({ noFlightsNoDraws, enteredParticipantGenders, eventUpdates, stack }) {
40547
40575
  const validGender = !enteredParticipantGenders.length ||
40548
- [MIXED, ANY].includes(eventUpdates.gender ?? '') ||
40549
- (enteredParticipantGenders.length === 1 && enteredParticipantGenders[0] === eventUpdates.gender);
40576
+ !eventUpdates.gender ||
40577
+ eventUpdates.gender === ANY ||
40578
+ (enteredParticipantGenders.length === 1 && enteredParticipantGenders[0] === eventUpdates.gender) ||
40579
+ (noFlightsNoDraws && eventUpdates.gender === MIXED);
40550
40580
  return eventUpdates.gender && !validGender
40551
40581
  ? decorateResult({
40552
40582
  context: { gender: eventUpdates.gender, validGender },