tods-competition-factory 1.7.10 → 1.7.11

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.
@@ -362,7 +362,7 @@ var matchUpFormatCode = {
362
362
  };
363
363
 
364
364
  function factoryVersion() {
365
- return '1.7.10';
365
+ return '1.7.11';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -47939,8 +47939,8 @@ function removeStructure(_a) {
47939
47939
  }
47940
47940
 
47941
47941
  function generateAdHocMatchUps$1(_a) {
47942
- var _b, _c, _d, _e, _f, _g, _h, _j;
47943
- var participantIdPairings = _a.participantIdPairings, _k = _a.addToStructure, addToStructure = _k === void 0 ? true : _k, tournamentRecord = _a.tournamentRecord, _l = _a.matchUpIds, matchUpIds = _l === void 0 ? [] : _l, drawDefinition = _a.drawDefinition, matchUpsCount = _a.matchUpsCount, roundNumber = _a.roundNumber, structureId = _a.structureId, newRound = _a.newRound;
47942
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
47943
+ var participantIdPairings = _a.participantIdPairings, _l = _a.addToStructure, addToStructure = _l === void 0 ? true : _l, tournamentRecord = _a.tournamentRecord, _m = _a.matchUpIds, matchUpIds = _m === void 0 ? [] : _m, drawDefinition = _a.drawDefinition, matchUpsCount = _a.matchUpsCount, roundNumber = _a.roundNumber, structureId = _a.structureId, newRound = _a.newRound;
47944
47944
  if (typeof drawDefinition !== 'object')
47945
47945
  return { error: MISSING_DRAW_DEFINITION };
47946
47946
  if (!structureId && ((_b = drawDefinition.structures) === null || _b === void 0 ? void 0 : _b.length) === 1)
@@ -47951,17 +47951,28 @@ function generateAdHocMatchUps$1(_a) {
47951
47951
  var structure = (_e = drawDefinition.structures) === null || _e === void 0 ? void 0 : _e.find(function (structure) { return structure.structureId === structureId; });
47952
47952
  if (!structure)
47953
47953
  return { error: STRUCTURE_NOT_FOUND };
47954
+ var structureHasRoundPositions;
47955
+ var existingMatchUps = (_f = structure.matchUps) !== null && _f !== void 0 ? _f : [];
47956
+ var lastRoundNumber = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.reduce(function (roundNumber, matchUp) {
47957
+ if (matchUp.roundPosition)
47958
+ structureHasRoundPositions = true;
47959
+ return ((matchUp === null || matchUp === void 0 ? void 0 : matchUp.roundNumber) || 0) > roundNumber
47960
+ ? matchUp.roundNumber
47961
+ : roundNumber;
47962
+ }, 0);
47954
47963
  if (!matchUpsCount) {
47955
- var selectedEntries = (_g = (_f = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _f === void 0 ? void 0 : _f.filter(function (entry) {
47964
+ var selectedEntries = (_h = (_g = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _g === void 0 ? void 0 : _g.filter(function (entry) {
47956
47965
  var entryStatus = entry.entryStatus;
47957
47966
  return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
47958
- })) !== null && _g !== void 0 ? _g : [];
47967
+ })) !== null && _h !== void 0 ? _h : [];
47959
47968
  var roundMatchUpsCount = Math.floor((selectedEntries === null || selectedEntries === void 0 ? void 0 : selectedEntries.length) / 2) || 1;
47960
47969
  if (newRound) {
47961
47970
  matchUpsCount = roundMatchUpsCount;
47962
47971
  }
47963
47972
  else {
47964
- var maxRemaining = roundMatchUpsCount - (((_h = structure.matchUps) === null || _h === void 0 ? void 0 : _h.length) || 0); // TODO: minus the number of existing matchUps in roundNumber
47973
+ var targetRoundNumber_1 = roundNumber || lastRoundNumber || 1;
47974
+ var existingRoundMatchUps = ((_k = (_j = structure.matchUps) === null || _j === void 0 ? void 0 : _j.filter(function (matchUp) { return matchUp.roundNumber === targetRoundNumber_1; })) === null || _k === void 0 ? void 0 : _k.length) || 0;
47975
+ var maxRemaining = roundMatchUpsCount - existingRoundMatchUps;
47965
47976
  if (maxRemaining > 0)
47966
47977
  matchUpsCount = maxRemaining;
47967
47978
  }
@@ -47972,15 +47983,6 @@ function generateAdHocMatchUps$1(_a) {
47972
47983
  (!participantIdPairings && !matchUpsCount)) {
47973
47984
  return { error: INVALID_VALUES, info: 'matchUpsCount or pairings error' };
47974
47985
  }
47975
- var structureHasRoundPositions;
47976
- var existingMatchUps = (_j = structure.matchUps) !== null && _j !== void 0 ? _j : [];
47977
- var lastRoundNumber = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.reduce(function (roundNumber, matchUp) {
47978
- if (matchUp.roundPosition)
47979
- structureHasRoundPositions = true;
47980
- return ((matchUp === null || matchUp === void 0 ? void 0 : matchUp.roundNumber) || 0) > roundNumber
47981
- ? matchUp.roundNumber
47982
- : roundNumber;
47983
- }, 0);
47984
47986
  // structure must not be a container of other structures
47985
47987
  // structure must not contain matchUps with roundPosition
47986
47988
  // structure must not determine finishingPosition by ROUND_OUTCOME
@@ -48682,11 +48684,11 @@ function setPositionAssignments$1(_a) {
48682
48684
  return __assign({}, SUCCESS);
48683
48685
  }
48684
48686
 
48685
- // build up an array of participantIds which are assigned positions in structures
48686
- // optionally filter to included only specified stages
48687
48687
  function getAssignedParticipantIds(_a) {
48688
48688
  var drawDefinition = _a.drawDefinition, stages = _a.stages;
48689
- var stageStructures = ((drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) || []).filter(function (structure) { return !(stages === null || stages === void 0 ? void 0 : stages.length) || stages.includes(structure.stage); });
48689
+ var stageStructures = ((drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) || []).filter(function (structure) {
48690
+ return !(stages === null || stages === void 0 ? void 0 : stages.length) || (structure.stage && stages.includes(structure.stage));
48691
+ });
48690
48692
  return stageStructures
48691
48693
  .map(function (structure) {
48692
48694
  var positionAssignments = getPositionAssignments$1({
@@ -49281,45 +49283,56 @@ function participantInFlightEntries(_a) {
49281
49283
  }
49282
49284
 
49283
49285
  function removeEventEntries(_a) {
49284
- var _b, _c;
49285
- var _d = _a.autoEntryPositions, autoEntryPositions = _d === void 0 ? true : _d, tournamentParticipants = _a.tournamentParticipants, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, event = _a.event;
49286
+ var _b, _c, _d, _e, _f;
49287
+ var _g = _a.autoEntryPositions, autoEntryPositions = _g === void 0 ? true : _g, _h = _a.participantIds, participantIds = _h === void 0 ? [] : _h, entryStatuses = _a.entryStatuses, stage = _a.stage, event = _a.event;
49286
49288
  var stack = 'removeEventEntries';
49287
49289
  if (!(event === null || event === void 0 ? void 0 : event.eventId))
49288
49290
  return { error: MISSING_EVENT };
49289
- if (!Array.isArray(participantIds))
49290
- return decorateResult({
49291
- result: { error: MISSING_PARTICIPANT_IDS },
49292
- stack: stack,
49293
- });
49294
- participantIds = participantIds === null || participantIds === void 0 ? void 0 : participantIds.filter(Boolean);
49295
- if (!(participantIds === null || participantIds === void 0 ? void 0 : participantIds.length))
49296
- return decorateResult({
49297
- result: { error: MISSING_PARTICIPANT_IDS },
49298
- stack: stack,
49299
- });
49300
- var eventId = event.eventId;
49301
- if (!tournamentParticipants) {
49302
- // cannot use getParticipants() because event objects don't have drawIds array
49303
- tournamentParticipants = getTournamentParticipants({
49304
- participantFilters: { participantIds: participantIds },
49305
- tournamentRecord: tournamentRecord,
49306
- withEvents: true,
49307
- withDraws: true,
49308
- }).tournamentParticipants;
49291
+ if (!Array.isArray(participantIds) ||
49292
+ participantIds.some(function (participantId) { return !isString(participantId); })) {
49293
+ return decorateResult({ result: { error: INVALID_PARTICIPANT_ID }, stack: stack });
49309
49294
  }
49310
- var enteredParticipantIds = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.every(function (participant) {
49311
- var eventObject = participant.events.find(function (event) { return event.eventId === eventId; });
49312
- var drawIds = (eventObject === null || eventObject === void 0 ? void 0 : eventObject.drawIds) || [];
49313
- return participant.draws.filter(function (drawInfo) {
49314
- return drawIds.includes(drawInfo.drawId) && drawInfo.positionAssignments;
49315
- }).length;
49316
- });
49317
- if (enteredParticipantIds) {
49295
+ // do not filter by stages; must kmow all participantIds assigned to any stage!
49296
+ var assignedParticipantIds = ((_b = event.drawDefinitions) !== null && _b !== void 0 ? _b : []).flatMap(function (drawDefinition) { return getAssignedParticipantIds({ drawDefinition: drawDefinition }); });
49297
+ var statusParticipantIds = (((entryStatuses === null || entryStatuses === void 0 ? void 0 : entryStatuses.length) &&
49298
+ ((_c = event.entries) === null || _c === void 0 ? void 0 : _c.filter(function (entry) {
49299
+ return entry.entryStatus && entryStatuses.includes(entry.entryStatus);
49300
+ }))) ||
49301
+ [])
49302
+ .map(extractAttributes('participantId'))
49303
+ .filter(function (participantId) { return !assignedParticipantIds.includes(participantId); });
49304
+ var stageParticipantIds = ((stage &&
49305
+ ((_d = event.entries) === null || _d === void 0 ? void 0 : _d.filter(function (entry) { return entry.entryStage && entry.entryStage === stage; }))) ||
49306
+ [])
49307
+ .map(extractAttributes('participantId'))
49308
+ .filter(function (participantId) { return !assignedParticipantIds.includes(participantId); });
49309
+ if (participantIds.length) {
49310
+ participantIds = participantIds.filter(function (participantId) {
49311
+ return (!(entryStatuses === null || entryStatuses === void 0 ? void 0 : entryStatuses.length) ||
49312
+ statusParticipantIds.includes(participantId)) &&
49313
+ (!stage || stageParticipantIds.includes(participantId));
49314
+ });
49315
+ }
49316
+ else if (statusParticipantIds.length && stageParticipantIds.length) {
49317
+ participantIds = intersection(statusParticipantIds, stageParticipantIds);
49318
+ }
49319
+ else if (statusParticipantIds.length) {
49320
+ participantIds = statusParticipantIds;
49321
+ }
49322
+ else if (stageParticipantIds.length) {
49323
+ participantIds = stageParticipantIds;
49324
+ }
49325
+ if ((participantIds === null || participantIds === void 0 ? void 0 : participantIds.length) &&
49326
+ assignedParticipantIds.some(function (participantId) {
49327
+ return participantIds.includes(participantId);
49328
+ })) {
49318
49329
  return decorateResult({
49319
49330
  result: { error: EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT },
49320
49331
  stack: stack,
49321
49332
  });
49322
49333
  }
49334
+ if (!(participantIds === null || participantIds === void 0 ? void 0 : participantIds.length))
49335
+ return __assign(__assign({}, SUCCESS), { participantIdsRemoved: [] });
49323
49336
  var participantIdsRemoved = [];
49324
49337
  event.entries = (event.entries || []).filter(function (entry) {
49325
49338
  var keepEntry = !participantIds.includes(entry === null || entry === void 0 ? void 0 : entry.participantId);
@@ -49334,10 +49347,10 @@ function removeEventEntries(_a) {
49334
49347
  }
49335
49348
  // also remove entry from all flights and drawDefinitions
49336
49349
  var flightProfile = getFlightProfile({ event: event }).flightProfile;
49337
- (_b = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _b === void 0 ? void 0 : _b.forEach(function (flight) {
49350
+ (_e = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _e === void 0 ? void 0 : _e.forEach(function (flight) {
49338
49351
  flight.drawEntries = (flight.drawEntries || []).filter(function (entry) { return !participantIds.includes(entry.participantId); });
49339
49352
  });
49340
- (_c = event.drawDefinitions) === null || _c === void 0 ? void 0 : _c.forEach(function (drawDefinition) {
49353
+ (_f = event.drawDefinitions) === null || _f === void 0 ? void 0 : _f.forEach(function (drawDefinition) {
49341
49354
  drawDefinition.entries = (drawDefinition.entries || []).filter(function (entry) { return !participantIds.includes(entry.participantId); });
49342
49355
  });
49343
49356
  return __assign(__assign({}, SUCCESS), { participantIdsRemoved: participantIdsRemoved });
@@ -49494,7 +49507,6 @@ function addEventEntries(params) {
49494
49507
  removeEventEntries({
49495
49508
  participantIds: ungroupedParticipantIdsToRemove,
49496
49509
  autoEntryPositions: false,
49497
- tournamentRecord: tournamentRecord,
49498
49510
  event: event,
49499
49511
  });
49500
49512
  }
@@ -49830,8 +49842,6 @@ function deleteParticipants(params) {
49830
49842
  for (var _f = __values(tournamentRecord.events || []), _g = _f.next(); !_g.done; _g = _f.next()) {
49831
49843
  var event_1 = _g.value;
49832
49844
  var result = removeEventEntries({
49833
- tournamentParticipants: tournamentParticipants,
49834
- tournamentRecord: tournamentRecord,
49835
49845
  participantIds: participantIds,
49836
49846
  event: event_1,
49837
49847
  });
@@ -50012,7 +50022,6 @@ function destroyGroupEntry(_a) {
50012
50022
  // remove the group participant from event entries
50013
50023
  var result = removeEventEntries({
50014
50024
  participantIds: [participantId],
50015
- tournamentRecord: tournamentRecord,
50016
50025
  event: event,
50017
50026
  });
50018
50027
  if (result.error)