tods-competition-factory 2.0.1 → 2.0.2

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.
@@ -2901,10 +2901,10 @@ type DeleteAdHocMatchUpsArgs = {
2901
2901
  tournamentRecord?: Tournament;
2902
2902
  drawDefinition: DrawDefinition;
2903
2903
  matchUpIds?: string[];
2904
- structureId: string;
2904
+ structureId?: string;
2905
2905
  event?: Event$1;
2906
2906
  };
2907
- declare function deleteAdHocMatchUps({ tournamentRecord, matchUpIds, drawDefinition, structureId, event, }: DeleteAdHocMatchUpsArgs): {
2907
+ declare function deleteAdHocMatchUps(params: DeleteAdHocMatchUpsArgs): {
2908
2908
  error: {
2909
2909
  message: string;
2910
2910
  code: string;
@@ -2939,11 +2939,12 @@ declare function updateTeamLineUp({ drawDefinition, participantId, tieFormat, li
2939
2939
  error?: ErrorType;
2940
2940
  };
2941
2941
 
2942
- declare function addAdHocMatchUps({ tournamentRecord, drawDefinition, structureId, matchUps }: {
2942
+ declare function addAdHocMatchUps({ tournamentRecord, drawDefinition, structureId, matchUps, event }: {
2943
2943
  tournamentRecord: any;
2944
2944
  drawDefinition: any;
2945
2945
  structureId: any;
2946
2946
  matchUps: any;
2947
+ event: any;
2947
2948
  }): ResultType;
2948
2949
 
2949
2950
  type ModifyDrawNameArgs = {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.0.1';
6
+ return '2.0.2';
7
7
  }
8
8
 
9
9
  /******************************************************************************
@@ -3966,15 +3966,13 @@ function drawUpdatedAt(drawDefinition, structureIds) {
3966
3966
  if (!drawDefinition)
3967
3967
  return { error: MISSING_DRAW_DEFINITION };
3968
3968
  var timeStamp = Date.now();
3969
- if (drawDefinition.updatedAt &&
3970
- timeStamp === new Date(drawDefinition.updatedAt).getTime())
3969
+ if (drawDefinition.updatedAt && timeStamp === new Date(drawDefinition.updatedAt).getTime())
3971
3970
  timeStamp += 1;
3972
3971
  var updatedAt = new Date(timeStamp).toISOString();
3973
3972
  var relevantStructureIds = structureIds === null || structureIds === void 0 ? void 0 : structureIds.filter(Boolean);
3974
3973
  drawDefinition.updatedAt = updatedAt;
3975
3974
  (_a = drawDefinition.structures) === null || _a === void 0 ? void 0 : _a.filter(Boolean).forEach(function (structure) {
3976
- if (!(relevantStructureIds === null || relevantStructureIds === void 0 ? void 0 : relevantStructureIds.length) ||
3977
- (relevantStructureIds === null || relevantStructureIds === void 0 ? void 0 : relevantStructureIds.includes(structure.structureId))) {
3975
+ if (!(relevantStructureIds === null || relevantStructureIds === void 0 ? void 0 : relevantStructureIds.length) || (relevantStructureIds === null || relevantStructureIds === void 0 ? void 0 : relevantStructureIds.includes(structure.structureId))) {
3978
3976
  structure.updatedAt = updatedAt;
3979
3977
  }
3980
3978
  });
@@ -26406,21 +26404,16 @@ function pruneDrawDefinition(_a) {
26406
26404
  var structureId = _a.structureId;
26407
26405
  return mainStructure_1.structureId === structureId;
26408
26406
  });
26409
- var matchUps = (_b = mainStructure_1.matchUps) !== null && _b !== void 0 ? _b : [];
26410
- relevantMatchUps = matchUps
26411
- .sort(function (a, b) { return a.roundPosition - b.roundPosition; })
26412
- .filter(function (_a) {
26407
+ var matchUps = ((_b = mainStructure_1.matchUps) !== null && _b !== void 0 ? _b : []).sort(function (a, b) { return a.roundPosition - b.roundPosition; });
26408
+ relevantMatchUps = matchUps.filter(function (_a) {
26413
26409
  var roundNumber = _a.roundNumber;
26414
26410
  return !structureData_1.inactiveRounds.includes(roundNumber);
26415
26411
  });
26416
26412
  var relevantMatchUpIds_1 = relevantMatchUps.map(getMatchUpId);
26417
- var deletedMatchUpIds = matchUps
26418
- .map(getMatchUpId)
26419
- .filter(function (matchUpId) { return !relevantMatchUpIds_1.includes(matchUpId); });
26413
+ var deletedMatchUpIds = matchUps.map(getMatchUpId).filter(function (matchUpId) { return !relevantMatchUpIds_1.includes(matchUpId); });
26420
26414
  // only ifMatchPlay can the positionAssignments be reallocated
26421
26415
  if (isMatchPlay) {
26422
26416
  var matchPlayMatchUps = relevantMatchUps
26423
- .sort(function (a, b) { return a.roundPosition - b.roundPosition; })
26424
26417
  .filter(function (_a) {
26425
26418
  var roundNumber = _a.roundNumber;
26426
26419
  return !structureData_1.inactiveRounds.includes(roundNumber);
@@ -26451,9 +26444,7 @@ function pruneDrawDefinition(_a) {
26451
26444
  }
26452
26445
  });
26453
26446
  if (matchPlayDrawPositions) {
26454
- var updatedPositionAssignments = (_c = mainStructure_1 === null || mainStructure_1 === void 0 ? void 0 : mainStructure_1.positionAssignments) === null || _c === void 0 ? void 0 : _c.filter(function (assignment) {
26455
- return existingDrawPositions_1.includes(assignment.drawPosition);
26456
- }).map(function (assignment) {
26447
+ var updatedPositionAssignments = (_c = mainStructure_1 === null || mainStructure_1 === void 0 ? void 0 : mainStructure_1.positionAssignments) === null || _c === void 0 ? void 0 : _c.filter(function (assignment) { return existingDrawPositions_1.includes(assignment.drawPosition); }).map(function (assignment) {
26457
26448
  assignment.drawPosition = drawPositionsMap_1[assignment.drawPosition];
26458
26449
  return assignment;
26459
26450
  });
@@ -26512,17 +26503,21 @@ function assignDrawPosition(_a) {
26512
26503
  return __assign({}, SUCCESS);
26513
26504
  }
26514
26505
 
26515
- function deleteAdHocMatchUps(_a) {
26516
- var e_1, _b;
26517
- var _c, _d, _e, _f, _g;
26518
- var tournamentRecord = _a.tournamentRecord, _h = _a.matchUpIds, matchUpIds = _h === void 0 ? [] : _h, drawDefinition = _a.drawDefinition, structureId = _a.structureId, event = _a.event;
26506
+ function deleteAdHocMatchUps(params) {
26507
+ var e_1, _a;
26508
+ var _b, _c, _d, _e, _f, _g, _h, _j;
26509
+ var tournamentRecord = params.tournamentRecord, _k = params.matchUpIds, matchUpIds = _k === void 0 ? [] : _k, drawDefinition = params.drawDefinition, event = params.event;
26519
26510
  if (typeof drawDefinition !== 'object')
26520
26511
  return { error: MISSING_DRAW_DEFINITION };
26521
- if (typeof structureId !== 'string')
26522
- return { error: MISSING_STRUCTURE_ID };
26523
26512
  if (!Array.isArray(matchUpIds))
26524
26513
  return { error: INVALID_VALUES };
26525
- var structure = (_c = drawDefinition.structures) === null || _c === void 0 ? void 0 : _c.find(function (structure) { return structure.structureId === structureId; });
26514
+ var structureId = (_b = params.structureId) !== null && _b !== void 0 ? _b : (_d = (_c = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _c === void 0 ? void 0 : _c.find(function (structure) { var _a; return (_a = structure.matchUps) === null || _a === void 0 ? void 0 : _a.some(function (_a) {
26515
+ var matchUpId = _a.matchUpId;
26516
+ return matchUpIds.includes(matchUpId);
26517
+ }); })) === null || _d === void 0 ? void 0 : _d.structureId;
26518
+ if (!structureId)
26519
+ return { error: STRUCTURE_NOT_FOUND };
26520
+ var structure = (_e = drawDefinition.structures) === null || _e === void 0 ? void 0 : _e.find(function (structure) { return structure.structureId === structureId; });
26526
26521
  if (!structure)
26527
26522
  return { error: STRUCTURE_NOT_FOUND };
26528
26523
  var existingMatchUps = structure === null || structure === void 0 ? void 0 : structure.matchUps;
@@ -26531,21 +26526,28 @@ function deleteAdHocMatchUps(_a) {
26531
26526
  return { error: INVALID_STRUCTURE };
26532
26527
  }
26533
26528
  var matchUpIdsWithScoreValue = [];
26534
- var matchUpsToDelete = (_d = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.filter(function (_a) {
26529
+ var matchUpsToDelete = (_f = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.filter(function (_a) {
26535
26530
  var matchUpId = _a.matchUpId, score = _a.score;
26536
26531
  if (checkScoreHasValue({ score: score }))
26537
26532
  matchUpIdsWithScoreValue.push(matchUpId);
26538
26533
  return matchUpIds.includes(matchUpId);
26539
- })) !== null && _d !== void 0 ? _d : [];
26540
- var matchUpIdsToDelete = matchUpsToDelete.map(xa('matchUpId'));
26534
+ })) !== null && _f !== void 0 ? _f : [];
26535
+ var matchUpIdsToDelete = matchUpsToDelete.map(getMatchUpId);
26536
+ var tieMatchUpIdsToDelete = matchUpsToDelete
26537
+ .map(function (_a) {
26538
+ var tieMatchUps = _a.tieMatchUps;
26539
+ return tieMatchUps === null || tieMatchUps === void 0 ? void 0 : tieMatchUps.map(getMatchUpId);
26540
+ })
26541
+ .filter(Boolean)
26542
+ .flat();
26541
26543
  if (matchUpIdsToDelete.length) {
26542
- structure.matchUps = ((_e = structure.matchUps) !== null && _e !== void 0 ? _e : []).filter(function (_a) {
26544
+ structure.matchUps = ((_g = structure.matchUps) !== null && _g !== void 0 ? _g : []).filter(function (_a) {
26543
26545
  var matchUpId = _a.matchUpId;
26544
26546
  return !matchUpIdsToDelete.includes(matchUpId);
26545
26547
  });
26546
26548
  deleteMatchUpsNotice({
26547
26549
  tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
26548
- matchUpIds: matchUpIdsToDelete,
26550
+ matchUpIds: __spreadArray(__spreadArray([], __read(tieMatchUpIdsToDelete), false), __read(matchUpIdsToDelete), false),
26549
26551
  action: 'deleteAdHocMatchUps',
26550
26552
  eventId: event === null || event === void 0 ? void 0 : event.eventId,
26551
26553
  drawDefinition: drawDefinition,
@@ -26577,7 +26579,7 @@ function deleteAdHocMatchUps(_a) {
26577
26579
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
26578
26580
  finally {
26579
26581
  try {
26580
- if (missingRoundNumbers_1_1 && !missingRoundNumbers_1_1.done && (_b = missingRoundNumbers_1.return)) _b.call(missingRoundNumbers_1);
26582
+ if (missingRoundNumbers_1_1 && !missingRoundNumbers_1_1.done && (_a = missingRoundNumbers_1.return)) _a.call(missingRoundNumbers_1);
26581
26583
  }
26582
26584
  finally { if (e_1) throw e_1.error; }
26583
26585
  }
@@ -26586,7 +26588,7 @@ function deleteAdHocMatchUps(_a) {
26586
26588
  structure.positionAssignments = unique(structure.matchUps
26587
26589
  .flatMap(function (matchUp) { var _a; return ((_a = matchUp.sides) !== null && _a !== void 0 ? _a : []).map(function (side) { return side.participantId; }); })
26588
26590
  .filter(Boolean)).map(function (participantId) { return ({ participantId: participantId }); });
26589
- var matchUpFormat = (_g = (_f = structure === null || structure === void 0 ? void 0 : structure.matchUpFormat) !== null && _f !== void 0 ? _f : drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.matchUpFormat) !== null && _g !== void 0 ? _g : event === null || event === void 0 ? void 0 : event.matchUpFormat;
26591
+ var matchUpFormat = (_j = (_h = structure === null || structure === void 0 ? void 0 : structure.matchUpFormat) !== null && _h !== void 0 ? _h : drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.matchUpFormat) !== null && _j !== void 0 ? _j : event === null || event === void 0 ? void 0 : event.matchUpFormat;
26590
26592
  var result = updateAssignmentParticipantResults({
26591
26593
  positionAssignments: structure.positionAssignments,
26592
26594
  matchUps: structure.matchUps,
@@ -26641,11 +26643,11 @@ function removeRoundMatchUps(_a) {
26641
26643
  }
26642
26644
  return __assign({}, SUCCESS);
26643
26645
  }
26644
- // TODO: move to drawEngine and passthrough
26645
26646
  function removeAdHocRound(_a) {
26646
26647
  var _b;
26647
26648
  var removeCompletedMatchUps = _a.removeCompletedMatchUps, drawDefinition = _a.drawDefinition, tournamentId = _a.tournamentId, roundNumber = _a.roundNumber, structure = _a.structure, eventId = _a.eventId;
26648
26649
  var matchUps = (_b = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _b !== void 0 ? _b : [];
26650
+ var deletedTieMatchUpIds = [];
26649
26651
  var deletedMatchUpIds = [];
26650
26652
  var roundRemoved = false;
26651
26653
  var roundNumbers = matchUps
@@ -26660,13 +26662,17 @@ function removeAdHocRound(_a) {
26660
26662
  var updatedMatchUps = matchUps.filter(function (matchUp) {
26661
26663
  var target = matchUp.roundNumber === roundNumber &&
26662
26664
  (!completedMatchUpStatuses.includes(matchUp.matchUpStatus) || removeCompletedMatchUps);
26663
- if (target)
26665
+ if (target) {
26664
26666
  deletedMatchUpIds.push(matchUp.matchUpId);
26667
+ if (matchUp.tieMatchUps) {
26668
+ deletedTieMatchUpIds.push.apply(deletedTieMatchUpIds, __spreadArray([], __read(matchUp.tieMatchUps.map(getMatchUpId)), false));
26669
+ }
26670
+ }
26665
26671
  return !target;
26666
26672
  });
26667
26673
  if (deletedMatchUpIds.length) {
26668
26674
  deleteMatchUpsNotice({
26669
- matchUpIds: deletedMatchUpIds,
26675
+ matchUpIds: __spreadArray(__spreadArray([], __read(deletedTieMatchUpIds), false), __read(deletedMatchUpIds), false),
26670
26676
  drawDefinition: drawDefinition,
26671
26677
  tournamentId: tournamentId,
26672
26678
  eventId: eventId,
@@ -26695,7 +26701,7 @@ function removeAdHocRound(_a) {
26695
26701
  function addAdHocMatchUps(_a) {
26696
26702
  var _b;
26697
26703
  var _c, _d, _e, _f, _g, _h, _j;
26698
- var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, matchUps = _a.matchUps;
26704
+ var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, matchUps = _a.matchUps, event = _a.event;
26699
26705
  if (typeof drawDefinition !== 'object')
26700
26706
  return { error: MISSING_DRAW_DEFINITION };
26701
26707
  if (!structureId && ((_c = drawDefinition.structures) === null || _c === void 0 ? void 0 : _c.length) === 1)
@@ -26724,10 +26730,18 @@ function addAdHocMatchUps(_a) {
26724
26730
  };
26725
26731
  }
26726
26732
  (_b = structure.matchUps).push.apply(_b, __spreadArray([], __read(matchUps), false));
26733
+ var tieMatchUps = matchUps
26734
+ .map(function (_a) {
26735
+ var tieMatchUps = _a.tieMatchUps;
26736
+ return tieMatchUps;
26737
+ })
26738
+ .filter(Boolean)
26739
+ .flat();
26727
26740
  addMatchUpsNotice({
26728
26741
  tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
26742
+ matchUps: __spreadArray(__spreadArray([], __read(tieMatchUps), false), __read(matchUps), false),
26743
+ eventId: event === null || event === void 0 ? void 0 : event.eventId,
26729
26744
  drawDefinition: drawDefinition,
26730
- matchUps: matchUps,
26731
26745
  });
26732
26746
  modifyDrawNotice({ drawDefinition: drawDefinition, structureIds: [structureId] });
26733
26747
  return __assign({}, SUCCESS);
@@ -32989,6 +33003,7 @@ function generateDrawDefinition(params) {
32989
33003
  tournamentRecord: tournamentRecord,
32990
33004
  drawDefinition: drawDefinition,
32991
33005
  structureId: structureId_1,
33006
+ event: event,
32992
33007
  });
32993
33008
  }
32994
33009
  else {
@@ -33006,6 +33021,7 @@ function generateDrawDefinition(params) {
33006
33021
  drawDefinition: drawDefinition,
33007
33022
  structureId: structureId,
33008
33023
  matchUps: matchUps,
33024
+ event: event,
33009
33025
  });
33010
33026
  });
33011
33027
  }
@@ -65115,10 +65131,10 @@ function asyncEngineInvoke(engine, args) {
65115
65131
  });
65116
65132
  }
65117
65133
 
65118
- function importMethods(engine, engineInvoke, submittedMethods, collections, maxDepth) {
65134
+ function importMethods(engine, engineInvoke, submittedMethods, traverse, maxDepth) {
65119
65135
  if (!isObject(submittedMethods))
65120
65136
  return { error: INVALID_VALUES };
65121
- var collectionFilter = Array.isArray(collections) ? collections : [];
65137
+ var collectionFilter = Array.isArray(traverse) ? traverse : [];
65122
65138
  var methods = {};
65123
65139
  var attrWalker = function (obj, depth) {
65124
65140
  if (depth === void 0) { depth = 0; }
@@ -65127,7 +65143,7 @@ function importMethods(engine, engineInvoke, submittedMethods, collections, maxD
65127
65143
  methods[key] = obj[key];
65128
65144
  }
65129
65145
  else if (isObject(obj[key]) &&
65130
- (collections === true || (collectionFilter === null || collectionFilter === void 0 ? void 0 : collectionFilter.includes(key))) &&
65146
+ (traverse === true || (collectionFilter === null || collectionFilter === void 0 ? void 0 : collectionFilter.includes(key))) &&
65131
65147
  (maxDepth === undefined || depth < maxDepth)) {
65132
65148
  attrWalker(obj[key], depth + 1);
65133
65149
  }