tods-competition-factory 2.1.16 → 2.1.17

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.17';
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
 
@@ -25651,9 +25666,7 @@ function getValidAlternatesAction({ tournamentParticipants = [], possiblyDisabli
25651
25666
  .sort((a, b) => (a.entryPosition ?? Infinity) - (b.entryPosition ?? Infinity))
25652
25667
  .map(({ participantId }) => participantId)
25653
25668
  .filter(Boolean);
25654
- const { allPositionedParticipantIds } = getAllPositionedParticipantIds({
25655
- drawDefinition,
25656
- });
25669
+ const { allPositionedParticipantIds } = getAllPositionedParticipantIds({ drawDefinition });
25657
25670
  const assignedParticipantIds = positionAssignments.map((assignment) => assignment.participantId).filter(Boolean);
25658
25671
  const availableDrawEnteredParticipantIds = drawEnteredParticipantIds.filter((participantId) => structure.stage && [QUALIFYING, MAIN, PLAY_OFF].includes(structure.stage)
25659
25672
  ? !allPositionedParticipantIds?.includes(participantId)
@@ -39901,18 +39914,22 @@ function deleteFlightAndFlightDraw({ autoPublish = true, tournamentRecord, audit
39901
39914
  return refreshEventDrawOrder({ tournamentRecord, event });
39902
39915
  }
39903
39916
 
39904
- function modifyPairAssignment({ replacementIndividualParticipantId, existingIndividualParticipantId, tournamentRecord, drawDefinition, participantId, event, uuids, }) {
39905
- if (!event)
39906
- return { error: MISSING_EVENT };
39917
+ function modifyPairAssignment(params) {
39918
+ const paramsCheck = checkRequiredParameters(params, [
39919
+ { [EVENT]: true, [TOURNAMENT_RECORD]: true, [UUIDS]: false },
39920
+ {
39921
+ replacementIndividualParticipantId: true,
39922
+ [VALIDATE]: (value) => isString(value),
39923
+ existingIndividualParticipantId: true,
39924
+ [ERROR]: MISSING_PARTICIPANT_ID,
39925
+ participantId: true,
39926
+ },
39927
+ ]);
39928
+ const { replacementIndividualParticipantId, existingIndividualParticipantId, tournamentRecord, drawDefinition, participantId, event, uuids, } = params;
39929
+ if (paramsCheck.error)
39930
+ return paramsCheck;
39907
39931
  if (event?.eventType !== DOUBLES)
39908
39932
  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
39933
  const availableIndividualParticipantIds = event?.entries
39917
39934
  ?.filter(({ entryStatus }) => [UNGROUPED, UNPAIRED].includes(entryStatus))
39918
39935
  .map(({ participantId }) => participantId) || [];
@@ -39959,18 +39976,19 @@ function modifyPairAssignment({ replacementIndividualParticipantId, existingIndi
39959
39976
  }
39960
39977
  drawDefinition.entries = drawDefinition.entries.map((entry) => entry.participantId === participantId ? { ...entry, participantId: newPairParticipantId } : entry);
39961
39978
  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) {
39979
+ if (structure.structures) {
39980
+ structure.positionAssignments = undefined;
39968
39981
  for (const subStructure of structure.structures) {
39969
39982
  subStructure.positionAssignments = subStructure.positionAssignments.map((assignment) => assignment.participantId === participantId
39970
39983
  ? { ...assignment, participantId: newPairParticipantId }
39971
39984
  : assignment);
39972
39985
  }
39973
39986
  }
39987
+ else if (structure.positionAssignments) {
39988
+ structure.positionAssignments = structure.positionAssignments.map((assignment) => assignment.participantId === participantId
39989
+ ? { ...assignment, participantId: newPairParticipantId }
39990
+ : assignment);
39991
+ }
39974
39992
  }
39975
39993
  }
39976
39994
  event.entries = event.entries.map((entry) => (entry.participantId === participantId && {