tods-competition-factory 1.8.41 → 1.8.42

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.
@@ -2929,7 +2929,7 @@ var matchUpFormatCode = {
2929
2929
  };
2930
2930
 
2931
2931
  function factoryVersion() {
2932
- return '1.8.41';
2932
+ return '1.8.42';
2933
2933
  }
2934
2934
 
2935
2935
  function getObjectTieFormat(obj) {
@@ -22853,7 +22853,7 @@ function getDrawDefinition$1(_a) {
22853
22853
  function bulkScheduleMatchUps$1(_a) {
22854
22854
  var e_1, _b, e_2, _c;
22855
22855
  var _d, _e, _f, _g;
22856
- var _h = _a.scheduleCompletedMatchUps, scheduleCompletedMatchUps = _h === void 0 ? false : _h, _j = _a.scheduleByeMatchUps, scheduleByeMatchUps = _j === void 0 ? false : _j, _k = _a.errorOnAnachronism, errorOnAnachronism = _k === void 0 ? false : _k, _l = _a.checkChronology, checkChronology = _l === void 0 ? true : _l, matchUpDependencies = _a.matchUpDependencies, tournamentRecords = _a.tournamentRecords, tournamentRecord = _a.tournamentRecord, matchUpDetails = _a.matchUpDetails, matchUpIds = _a.matchUpIds, schedule = _a.schedule;
22856
+ var _h = _a.scheduleCompletedMatchUps, scheduleCompletedMatchUps = _h === void 0 ? false : _h, _j = _a.scheduleByeMatchUps, scheduleByeMatchUps = _j === void 0 ? false : _j, _k = _a.errorOnAnachronism, errorOnAnachronism = _k === void 0 ? false : _k, _l = _a.checkChronology, checkChronology = _l === void 0 ? true : _l, matchUpDependencies = _a.matchUpDependencies, removePriorValues = _a.removePriorValues, tournamentRecords = _a.tournamentRecords, tournamentRecord = _a.tournamentRecord, matchUpDetails = _a.matchUpDetails, matchUpIds = _a.matchUpIds, schedule = _a.schedule;
22857
22857
  if (!tournamentRecord)
22858
22858
  return { error: MISSING_TOURNAMENT_RECORD };
22859
22859
  if (!matchUpDetails && (!matchUpIds || !Array.isArray(matchUpIds)))
@@ -22866,7 +22866,10 @@ function bulkScheduleMatchUps$1(_a) {
22866
22866
  // Optimize getting matchUps for all tournamentRecords
22867
22867
  // if matchUpDependencies are provided, skip this step
22868
22868
  if (checkChronology && !matchUpDependencies) {
22869
- var result = getMatchUpDependencies({ tournamentRecords: tournamentRecords });
22869
+ var result = getMatchUpDependencies({
22870
+ tournamentRecords: tournamentRecords,
22871
+ tournamentRecord: tournamentRecord,
22872
+ });
22870
22873
  matchUpDependencies = result.matchUpDependencies;
22871
22874
  inContextMatchUps = result.matchUps;
22872
22875
  }
@@ -22915,6 +22918,7 @@ function bulkScheduleMatchUps$1(_a) {
22915
22918
  schedule: matchUpSchedule,
22916
22919
  matchUpDependencies: matchUpDependencies,
22917
22920
  errorOnAnachronism: errorOnAnachronism,
22921
+ removePriorValues: removePriorValues,
22918
22922
  inContextMatchUps: inContextMatchUps,
22919
22923
  tournamentRecords: tournamentRecords,
22920
22924
  tournamentRecord: tournamentRecord,
@@ -22961,7 +22965,7 @@ function bulkScheduleMatchUps$1(_a) {
22961
22965
  function bulkScheduleMatchUps(_a) {
22962
22966
  var e_1, _b;
22963
22967
  var _c;
22964
- var _d = _a.scheduleCompletedMatchUps, scheduleCompletedMatchUps = _d === void 0 ? false : _d, _e = _a.scheduleByeMatchUps, scheduleByeMatchUps = _e === void 0 ? false : _e, errorOnAnachronism = _a.errorOnAnachronism, matchUpContextIds = _a.matchUpContextIds, tournamentRecords = _a.tournamentRecords, checkChronology = _a.checkChronology, matchUpDetails = _a.matchUpDetails, schedule = _a.schedule;
22968
+ var _d = _a.scheduleCompletedMatchUps, scheduleCompletedMatchUps = _d === void 0 ? false : _d, _e = _a.scheduleByeMatchUps, scheduleByeMatchUps = _e === void 0 ? false : _e, errorOnAnachronism = _a.errorOnAnachronism, matchUpContextIds = _a.matchUpContextIds, removePriorValues = _a.removePriorValues, tournamentRecords = _a.tournamentRecords, checkChronology = _a.checkChronology, matchUpDetails = _a.matchUpDetails, schedule = _a.schedule;
22965
22969
  if (!tournamentRecords)
22966
22970
  return { error: MISSING_TOURNAMENT_RECORDS };
22967
22971
  if (!Array.isArray(matchUpContextIds) && !Array.isArray(matchUpDetails))
@@ -22984,6 +22988,7 @@ function bulkScheduleMatchUps(_a) {
22984
22988
  scheduleByeMatchUps: scheduleByeMatchUps,
22985
22989
  matchUpDependencies: matchUpDependencies,
22986
22990
  errorOnAnachronism: errorOnAnachronism,
22991
+ removePriorValues: removePriorValues,
22987
22992
  tournamentRecords: tournamentRecords,
22988
22993
  tournamentRecord: tournamentRecord,
22989
22994
  checkChronology: checkChronology,
@@ -35260,13 +35265,16 @@ function processAlreadyScheduledMatchUps(_a) {
35260
35265
  var e_1, _b;
35261
35266
  var _c, _d;
35262
35267
  var matchUpPotentialParticipantIds = _a.matchUpPotentialParticipantIds, individualParticipantProfiles = _a.individualParticipantProfiles, dateScheduledMatchUpIds = _a.dateScheduledMatchUpIds, greatestAverageMinutes = _a.greatestAverageMinutes, dateScheduledMatchUps = _a.dateScheduledMatchUps, matchUpNotBeforeTimes = _a.matchUpNotBeforeTimes, matchUpScheduleTimes = _a.matchUpScheduleTimes, matchUpDependencies = _a.matchUpDependencies, clearScheduleDates = _a.clearScheduleDates, scheduleDate = _a.scheduleDate, minutesMap = _a.minutesMap, matchUps = _a.matchUps;
35263
- var byeScheduledMatchUpIds = [];
35268
+ var byeScheduledMatchUpDetails = [];
35264
35269
  if (!dateScheduledMatchUpIds) {
35265
35270
  dateScheduledMatchUps = matchUps === null || matchUps === void 0 ? void 0 : matchUps.filter(function (matchUp) {
35266
35271
  var schedule = matchUp.schedule || {};
35267
35272
  var isByeMatchUp = matchUp.matchUpStatus === BYE;
35268
35273
  if (isByeMatchUp)
35269
- byeScheduledMatchUpIds.push(matchUp.matchUpId);
35274
+ byeScheduledMatchUpDetails.push({
35275
+ tournamentId: matchUp.tournamentId,
35276
+ matchUpId: matchUp.matchUpId,
35277
+ });
35270
35278
  return (!isByeMatchUp &&
35271
35279
  hasSchedule({ schedule: schedule }) &&
35272
35280
  (!scheduleDate || matchUp.schedule.scheduledDate === scheduleDate));
@@ -35321,7 +35329,7 @@ function processAlreadyScheduledMatchUps(_a) {
35321
35329
  }
35322
35330
  return {
35323
35331
  dateScheduledMatchUpIds: dateScheduledMatchUpIds,
35324
- byeScheduledMatchUpIds: byeScheduledMatchUpIds,
35332
+ byeScheduledMatchUpDetails: byeScheduledMatchUpDetails,
35325
35333
  dateScheduledMatchUps: dateScheduledMatchUps,
35326
35334
  clearDate: clearDate,
35327
35335
  };
@@ -35373,10 +35381,10 @@ function getGroupedRounds(_a) {
35373
35381
  }
35374
35382
  if (groupedMatchUpIds.length) {
35375
35383
  groupedRounds.push({
35376
- averageMinutes: averageMinutes,
35377
- recoveryMinutes: recoveryMinutes,
35378
- roundPeriodLength: roundPeriodLength,
35379
35384
  matchUpIds: groupedMatchUpIds,
35385
+ roundPeriodLength: roundPeriodLength,
35386
+ recoveryMinutes: recoveryMinutes,
35387
+ averageMinutes: averageMinutes,
35380
35388
  });
35381
35389
  }
35382
35390
  return { groupedRounds: groupedRounds };
@@ -35565,7 +35573,7 @@ function getVenueSchedulingDetails(_a) {
35565
35573
  var venueScheduledRoundDetails = {};
35566
35574
  // checking that matchUpDependencies is scoped to only those matchUps that are already or are to be scheduled on the same date
35567
35575
  var allDateScheduledMatchUpIds = [];
35568
- var allDateScheduledByeMatchUpIds = [];
35576
+ var allDateScheduledByeMatchUpDetails = [];
35569
35577
  var allDateMatchUpIds = [];
35570
35578
  var _loop_1 = function (venue) {
35571
35579
  var _d;
@@ -35615,9 +35623,9 @@ function getVenueSchedulingDetails(_a) {
35615
35623
  matchUps: matchUps,
35616
35624
  });
35617
35625
  (dateScheduledMatchUpIds = processResult.dateScheduledMatchUpIds, dateScheduledMatchUps = processResult.dateScheduledMatchUps);
35618
- var byeScheduledMatchUpIds = processResult.byeScheduledMatchUpIds, clearDate = processResult.clearDate;
35619
- if (byeScheduledMatchUpIds === null || byeScheduledMatchUpIds === void 0 ? void 0 : byeScheduledMatchUpIds.length)
35620
- allDateScheduledByeMatchUpIds.push.apply(allDateScheduledByeMatchUpIds, __spreadArray([], __read(byeScheduledMatchUpIds), false));
35626
+ var byeScheduledMatchUpDetails = processResult.byeScheduledMatchUpDetails, clearDate = processResult.clearDate;
35627
+ if (byeScheduledMatchUpDetails === null || byeScheduledMatchUpDetails === void 0 ? void 0 : byeScheduledMatchUpDetails.length)
35628
+ allDateScheduledByeMatchUpDetails.push.apply(allDateScheduledByeMatchUpDetails, __spreadArray([], __read(byeScheduledMatchUpDetails), false));
35621
35629
  var _g = getMatchUpsToSchedule({
35622
35630
  matchUpPotentialParticipantIds: matchUpPotentialParticipantIds,
35623
35631
  scheduleCompletedMatchUps: scheduleCompletedMatchUps,
@@ -35661,7 +35669,7 @@ function getVenueSchedulingDetails(_a) {
35661
35669
  finally { if (e_1) throw e_1.error; }
35662
35670
  }
35663
35671
  return {
35664
- allDateScheduledByeMatchUpIds: allDateScheduledByeMatchUpIds,
35672
+ allDateScheduledByeMatchUpDetails: allDateScheduledByeMatchUpDetails,
35665
35673
  allDateScheduledMatchUpIds: allDateScheduledMatchUpIds,
35666
35674
  venueScheduledRoundDetails: venueScheduledRoundDetails,
35667
35675
  allDateMatchUpIds: allDateMatchUpIds,
@@ -35826,7 +35834,7 @@ function jinnScheduler(_a) {
35826
35834
  var e_1, _b;
35827
35835
  var _c, _d, _e, _f, _g, _h, _j;
35828
35836
  var schedulingProfileModifications = _a.schedulingProfileModifications, checkPotentialRequestConflicts = _a.checkPotentialRequestConflicts, scheduleCompletedMatchUps = _a.scheduleCompletedMatchUps, // override which can be used by mocksEngine
35829
- schedulingProfileIssues = _a.schedulingProfileIssues, dateSchedulingProfiles = _a.dateSchedulingProfiles, containedStructureIds = _a.containedStructureIds, matchUpDependencies = _a.matchUpDependencies, matchUpDailyLimits = _a.matchUpDailyLimits, clearScheduleDates = _a.clearScheduleDates, schedulingProfile = _a.schedulingProfile, tournamentRecords = _a.tournamentRecords, personRequests = _a.personRequests, periodLength = _a.periodLength, matchUps = _a.matchUps, courts = _a.courts, dryRun = _a.dryRun;
35837
+ schedulingProfileIssues = _a.schedulingProfileIssues, dateSchedulingProfiles = _a.dateSchedulingProfiles, containedStructureIds = _a.containedStructureIds, matchUpDependencies = _a.matchUpDependencies, matchUpDailyLimits = _a.matchUpDailyLimits, clearScheduleDates = _a.clearScheduleDates, tournamentRecords = _a.tournamentRecords, schedulingProfile = _a.schedulingProfile, personRequests = _a.personRequests, periodLength = _a.periodLength, matchUps = _a.matchUps, courts = _a.courts, dryRun = _a.dryRun;
35830
35838
  var scheduleTimesRemaining = {};
35831
35839
  var skippedScheduleTimes = {};
35832
35840
  var recoveryTimeDeferredMatchUpIds = {};
@@ -35893,7 +35901,7 @@ function jinnScheduler(_a) {
35893
35901
  matchUps: matchUps,
35894
35902
  courts: courts,
35895
35903
  venues: venues,
35896
- }), venueScheduledRoundDetails = _p.venueScheduledRoundDetails, allDateMatchUpIds = _p.allDateMatchUpIds;
35904
+ }), allDateScheduledByeMatchUpDetails = _p.allDateScheduledByeMatchUpDetails, venueScheduledRoundDetails = _p.venueScheduledRoundDetails, allDateMatchUpIds = _p.allDateMatchUpIds;
35897
35905
  var maxScheduleTimeAttempts = 10; // TODO: calculate this based on max court start/end range and averageMinutes
35898
35906
  var schedulingIterations = 0;
35899
35907
  var schedulingComplete = void 0;
@@ -36121,6 +36129,23 @@ function jinnScheduler(_a) {
36121
36129
  }
36122
36130
  finally { if (e_3) throw e_3.error; }
36123
36131
  }
36132
+ if (!dryRun && (allDateScheduledByeMatchUpDetails === null || allDateScheduledByeMatchUpDetails === void 0 ? void 0 : allDateScheduledByeMatchUpDetails.length)) {
36133
+ // remove scheduling information for BYE matchUps from any rounds that were scheduled
36134
+ // remove scheduling information for BYE matchUps from any rounds that were scheduled
36135
+ bulkScheduleMatchUps({
36136
+ matchUpDetails: allDateScheduledByeMatchUpDetails,
36137
+ scheduleByeMatchUps: true,
36138
+ removePriorValues: true,
36139
+ tournamentRecords: tournamentRecords,
36140
+ schedule: {
36141
+ scheduledDate: '',
36142
+ scheduledTime: '',
36143
+ courtOrder: '',
36144
+ courtId: '',
36145
+ venueId: '',
36146
+ },
36147
+ });
36148
+ }
36124
36149
  try {
36125
36150
  for (var _q = (e_4 = void 0, __values(dateSchedulingProfile.venues)), _r = _q.next(); !_r.done; _r = _q.next()) {
36126
36151
  var venue = _r.value;
@@ -36192,6 +36217,285 @@ function jinnScheduler(_a) {
36192
36217
  return __assign(__assign({}, SUCCESS), { schedulingProfileModifications: schedulingProfileModifications, schedulingProfileIssues: schedulingProfileIssues, scheduleTimesRemaining: scheduleTimesRemaining, dateSchedulingProfiles: dateSchedulingProfiles, skippedScheduleTimes: skippedScheduleTimes, recoveryTimeDeferredMatchUpIds: recoveryTimeDeferredMatchUpIds, dependencyDeferredMatchUpIds: dependencyDeferredMatchUpIds, matchUpScheduleTimes: matchUpScheduleTimes, overLimitMatchUpIds: overLimitMatchUpIds, scheduledMatchUpIds: scheduledMatchUpIds, noTimeMatchUpIds: noTimeMatchUpIds, requestConflicts: requestConflicts, scheduledDates: scheduledDates });
36193
36218
  }
36194
36219
 
36220
+ function getPersonRequests(_a) {
36221
+ var e_1, _b, e_2, _c, e_3, _d;
36222
+ var tournamentRecords = _a.tournamentRecords, requestType = _a.requestType;
36223
+ if (typeof tournamentRecords !== 'object' ||
36224
+ !Object.keys(tournamentRecords).length)
36225
+ return { error: MISSING_TOURNAMENT_RECORDS };
36226
+ var personRequests = {};
36227
+ try {
36228
+ // create merged view of person requests across tournamentRecords
36229
+ // ... possible for a person to be in multiple linked tournamentRecords
36230
+ for (var _e = __values(Object.values(tournamentRecords)), _f = _e.next(); !_f.done; _f = _e.next()) {
36231
+ var tournamentRecord = _f.value;
36232
+ var extension = findTournamentExtension({
36233
+ name: PERSON_REQUESTS,
36234
+ tournamentRecord: tournamentRecord,
36235
+ }).extension;
36236
+ var requestObjects = (extension === null || extension === void 0 ? void 0 : extension.value) || [];
36237
+ try {
36238
+ for (var requestObjects_1 = (e_2 = void 0, __values(requestObjects)), requestObjects_1_1 = requestObjects_1.next(); !requestObjects_1_1.done; requestObjects_1_1 = requestObjects_1.next()) {
36239
+ var requestObject = requestObjects_1_1.value;
36240
+ var _g = requestObject || {}, personId = _g.personId, requests = _g.requests;
36241
+ if (!personRequests[personId])
36242
+ personRequests[personId] = [];
36243
+ try {
36244
+ for (var requests_1 = (e_3 = void 0, __values(requests)), requests_1_1 = requests_1.next(); !requests_1_1.done; requests_1_1 = requests_1.next()) {
36245
+ var request = requests_1_1.value;
36246
+ if (requestType && request.requestType !== requestType)
36247
+ continue;
36248
+ personRequests[personId].push(request);
36249
+ }
36250
+ }
36251
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
36252
+ finally {
36253
+ try {
36254
+ if (requests_1_1 && !requests_1_1.done && (_d = requests_1.return)) _d.call(requests_1);
36255
+ }
36256
+ finally { if (e_3) throw e_3.error; }
36257
+ }
36258
+ }
36259
+ }
36260
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
36261
+ finally {
36262
+ try {
36263
+ if (requestObjects_1_1 && !requestObjects_1_1.done && (_c = requestObjects_1.return)) _c.call(requestObjects_1);
36264
+ }
36265
+ finally { if (e_2) throw e_2.error; }
36266
+ }
36267
+ }
36268
+ }
36269
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
36270
+ finally {
36271
+ try {
36272
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
36273
+ }
36274
+ finally { if (e_1) throw e_1.error; }
36275
+ }
36276
+ // audit requests and filter out any that are no longer relevant
36277
+ // (tournament dates changed & etc)
36278
+ return { personRequests: personRequests };
36279
+ }
36280
+ function savePersonRequests(_a) {
36281
+ var e_4, _b, e_5, _c;
36282
+ var _d;
36283
+ var tournamentRecords = _a.tournamentRecords, personRequests = _a.personRequests;
36284
+ if (!tournamentRecords)
36285
+ return { error: MISSING_TOURNAMENT_RECORDS };
36286
+ if (!personRequests)
36287
+ return __assign({}, SUCCESS);
36288
+ var tournaments = Object.values(tournamentRecords);
36289
+ try {
36290
+ for (var tournaments_1 = __values(tournaments), tournaments_1_1 = tournaments_1.next(); !tournaments_1_1.done; tournaments_1_1 = tournaments_1.next()) {
36291
+ var tournamentRecord = tournaments_1_1.value;
36292
+ var tournamentParticipants = (_d = tournamentRecord.participants) !== null && _d !== void 0 ? _d : [];
36293
+ var relevantPersonRequests = [];
36294
+ try {
36295
+ for (var _e = (e_5 = void 0, __values(Object.keys(personRequests))), _f = _e.next(); !_f.done; _f = _e.next()) {
36296
+ var personId = _f.value;
36297
+ if (findParticipant({ tournamentParticipants: tournamentParticipants, personId: personId })) {
36298
+ var requests = personRequests[personId];
36299
+ if (requests.length)
36300
+ relevantPersonRequests.push({ personId: personId, requests: requests });
36301
+ }
36302
+ }
36303
+ }
36304
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
36305
+ finally {
36306
+ try {
36307
+ if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
36308
+ }
36309
+ finally { if (e_5) throw e_5.error; }
36310
+ }
36311
+ if (Object.keys(relevantPersonRequests).length) {
36312
+ var extension = {
36313
+ name: PERSON_REQUESTS,
36314
+ value: relevantPersonRequests,
36315
+ };
36316
+ addTournamentExtension({ tournamentRecord: tournamentRecord, extension: extension });
36317
+ }
36318
+ }
36319
+ }
36320
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
36321
+ finally {
36322
+ try {
36323
+ if (tournaments_1_1 && !tournaments_1_1.done && (_b = tournaments_1.return)) _b.call(tournaments_1);
36324
+ }
36325
+ finally { if (e_4) throw e_4.error; }
36326
+ }
36327
+ return __assign({}, SUCCESS);
36328
+ }
36329
+ function addPersonRequests(_a) {
36330
+ var tournamentRecords = _a.tournamentRecords, personId = _a.personId, requests = _a.requests;
36331
+ if (!tournamentRecords)
36332
+ return { error: MISSING_TOURNAMENT_RECORDS };
36333
+ if (typeof personId !== 'string')
36334
+ return { error: INVALID_VALUES };
36335
+ if (!Array.isArray(requests))
36336
+ return { error: INVALID_VALUES };
36337
+ var personRequests = getPersonRequests({ tournamentRecords: tournamentRecords }).personRequests;
36338
+ var mergeCount = mergePersonRequests({
36339
+ personRequests: personRequests,
36340
+ personId: personId,
36341
+ requests: requests,
36342
+ }).mergeCount;
36343
+ if (mergeCount && personRequests) {
36344
+ return savePersonRequests({ tournamentRecords: tournamentRecords, personRequests: personRequests });
36345
+ }
36346
+ else {
36347
+ return { error: INVALID_VALUES };
36348
+ }
36349
+ }
36350
+ // check whether there is a request for the date with overlapping times
36351
+ // extend startTime/endTime rather than creating multiple
36352
+ // ... only pertains to { requestType: DO_NOT_SCHEDULE }
36353
+ function mergePersonRequests(_a) {
36354
+ var e_6, _b;
36355
+ var personRequests = _a.personRequests, personId = _a.personId, requests = _a.requests;
36356
+ if (!personRequests[personId])
36357
+ personRequests[personId] = [];
36358
+ var filteredRequests = requests
36359
+ .filter(function (_a) {
36360
+ var requestType = _a.requestType;
36361
+ return requestType;
36362
+ })
36363
+ .map(function (request) {
36364
+ var date = request.date, startTime = request.startTime, endTime = request.endTime;
36365
+ // validate requestType
36366
+ if (request.requestType === DO_NOT_SCHEDULE) {
36367
+ date = extractDate(date);
36368
+ startTime = extractTime(startTime);
36369
+ endTime = extractTime(endTime);
36370
+ if (date && startTime && endTime) {
36371
+ return { date: date, startTime: startTime, endTime: endTime, requestType: request.requestType };
36372
+ }
36373
+ }
36374
+ return request;
36375
+ })
36376
+ .filter(Boolean);
36377
+ try {
36378
+ // Do not add any request that is missing requestType
36379
+ for (var filteredRequests_1 = __values(filteredRequests), filteredRequests_1_1 = filteredRequests_1.next(); !filteredRequests_1_1.done; filteredRequests_1_1 = filteredRequests_1.next()) {
36380
+ var request = filteredRequests_1_1.value;
36381
+ request.requestId = generateTimeCode();
36382
+ personRequests[personId].push(request);
36383
+ }
36384
+ }
36385
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
36386
+ finally {
36387
+ try {
36388
+ if (filteredRequests_1_1 && !filteredRequests_1_1.done && (_b = filteredRequests_1.return)) _b.call(filteredRequests_1);
36389
+ }
36390
+ finally { if (e_6) throw e_6.error; }
36391
+ }
36392
+ return { mergeCount: filteredRequests.length };
36393
+ }
36394
+ // personRequests can be removed by date, requestId, or requestType
36395
+ function removePersonRequests(_a) {
36396
+ var e_7, _b;
36397
+ var tournamentRecords = _a.tournamentRecords, requestType = _a.requestType, requestId = _a.requestId, personId = _a.personId, date = _a.date;
36398
+ if (typeof tournamentRecords !== 'object' ||
36399
+ !Object.keys(tournamentRecords).length)
36400
+ return { error: MISSING_TOURNAMENT_RECORDS };
36401
+ var personRequests = getPersonRequests({ tournamentRecords: tournamentRecords }).personRequests;
36402
+ var filterRequests = function (personId) {
36403
+ var _a;
36404
+ if (personRequests) {
36405
+ personRequests[personId] = personRequests[personId].filter(function (request) {
36406
+ return ((!requestType || request.requestType !== requestType) &&
36407
+ (!requestId || request.requestId !== requestId) &&
36408
+ (!date || request.date !== date));
36409
+ });
36410
+ if (!((_a = personRequests === null || personRequests === void 0 ? void 0 : personRequests[personId]) === null || _a === void 0 ? void 0 : _a.length))
36411
+ delete personRequests[personId];
36412
+ }
36413
+ };
36414
+ var removeAll = !requestType && !requestId && !personId && !date;
36415
+ if (!removeAll) {
36416
+ if (personId && (personRequests === null || personRequests === void 0 ? void 0 : personRequests[personId])) {
36417
+ filterRequests(personId);
36418
+ }
36419
+ else if (personRequests) {
36420
+ try {
36421
+ for (var _c = __values(Object.keys(personRequests)), _d = _c.next(); !_d.done; _d = _c.next()) {
36422
+ var personId_1 = _d.value;
36423
+ filterRequests(personId_1);
36424
+ }
36425
+ }
36426
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
36427
+ finally {
36428
+ try {
36429
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
36430
+ }
36431
+ finally { if (e_7) throw e_7.error; }
36432
+ }
36433
+ }
36434
+ }
36435
+ if (removeAll || !personRequests || !Object.keys(personRequests).length) {
36436
+ return removeExtension({ tournamentRecords: tournamentRecords, name: PERSON_REQUESTS });
36437
+ }
36438
+ else {
36439
+ return savePersonRequests({ tournamentRecords: tournamentRecords, personRequests: personRequests });
36440
+ }
36441
+ }
36442
+ // can be used to both add and remove requests
36443
+ // requests which don't have existing requestId will be added
36444
+ // requests which don't have requestType will be removed
36445
+ function modifyPersonRequests(_a) {
36446
+ var e_8, _b;
36447
+ var tournamentRecords = _a.tournamentRecords, requests = _a.requests, personId = _a.personId;
36448
+ if (!tournamentRecords)
36449
+ return { error: MISSING_TOURNAMENT_RECORDS };
36450
+ if (!Array.isArray(requests))
36451
+ return { error: INVALID_VALUES };
36452
+ var requestIds = requests.map(function (_a) {
36453
+ var requestId = _a.requestId;
36454
+ return requestId;
36455
+ }).filter(Boolean);
36456
+ var personRequests = getPersonRequests({ tournamentRecords: tournamentRecords }).personRequests;
36457
+ var modifyRequests = function (personId) {
36458
+ if (personRequests) {
36459
+ personRequests[personId] = personRequests[personId]
36460
+ .map(function (request) {
36461
+ // if requestId not in requestIds then return unmodified
36462
+ if (!requestIds.includes(request.requestId))
36463
+ return request;
36464
+ // find the updatedRequest
36465
+ var modification = requests.find(function (updatedRequest) { return updatedRequest.requestId === request.requestId; });
36466
+ // FEATURE: returning an updatedRequest without a requestType will remove it
36467
+ if (!modification.requestType)
36468
+ return;
36469
+ return Object.assign(request, modification);
36470
+ })
36471
+ .filter(Boolean);
36472
+ }
36473
+ };
36474
+ if (personId && (personRequests === null || personRequests === void 0 ? void 0 : personRequests[personId])) {
36475
+ modifyRequests(personId);
36476
+ }
36477
+ else if (personRequests) {
36478
+ try {
36479
+ for (var _c = __values(Object.keys(personRequests)), _d = _c.next(); !_d.done; _d = _c.next()) {
36480
+ var personId_2 = _d.value;
36481
+ modifyRequests(personId_2);
36482
+ }
36483
+ }
36484
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
36485
+ finally {
36486
+ try {
36487
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
36488
+ }
36489
+ finally { if (e_8) throw e_8.error; }
36490
+ }
36491
+ }
36492
+ var newRequests = requests.filter(function (request) { return !request.requestId; });
36493
+ if (newRequests.length) {
36494
+ mergePersonRequests({ personRequests: personRequests, personId: personId, requests: newRequests });
36495
+ }
36496
+ return savePersonRequests({ tournamentRecords: tournamentRecords, personRequests: personRequests });
36497
+ }
36498
+
36195
36499
  function getEarliestCourtTime(_a) {
36196
36500
  var averageMinutes = _a.averageMinutes, startTime = _a.startTime, endTime = _a.endTime, court = _a.court, date = _a.date;
36197
36501
  if (!Array.isArray(court.dateAvailability))
@@ -36231,11 +36535,11 @@ function getEarliestCourtTime(_a) {
36231
36535
  return { earliestCourtTime: earliestCourtTime, courtStartTime: courtStartTime, courtEndTime: courtEndTime };
36232
36536
  }
36233
36537
 
36234
- function proScheduler(_a) {
36538
+ function v2Scheduler(_a) {
36235
36539
  var e_1, _b;
36236
36540
  var _c, _d;
36237
36541
  var schedulingProfileModifications = _a.schedulingProfileModifications, checkPotentialRequestConflicts = _a.checkPotentialRequestConflicts, scheduleCompletedMatchUps = _a.scheduleCompletedMatchUps, // override which can be used by mocksEngine
36238
- schedulingProfileIssues = _a.schedulingProfileIssues, dateSchedulingProfiles = _a.dateSchedulingProfiles, containedStructureIds = _a.containedStructureIds, matchUpDependencies = _a.matchUpDependencies, matchUpDailyLimits = _a.matchUpDailyLimits, clearScheduleDates = _a.clearScheduleDates, tournamentRecords = _a.tournamentRecords, _e = _a.periodLength, periodLength = _e === void 0 ? 30 : _e, schedulingProfile = _a.schedulingProfile, personRequests = _a.personRequests, matchUps = _a.matchUps, courts = _a.courts, dryRun = _a.dryRun;
36542
+ schedulingProfileIssues = _a.schedulingProfileIssues, dateSchedulingProfiles = _a.dateSchedulingProfiles, containedStructureIds = _a.containedStructureIds, matchUpDependencies = _a.matchUpDependencies, matchUpDailyLimits = _a.matchUpDailyLimits, clearScheduleDates = _a.clearScheduleDates, tournamentRecords = _a.tournamentRecords, _e = _a.periodLength, periodLength = _e === void 0 ? 30 : _e, schedulingProfile = _a.schedulingProfile, personRequests = _a.personRequests, _f = _a.matchUps, matchUps = _f === void 0 ? [] : _f, courts = _a.courts, dryRun = _a.dryRun;
36239
36543
  var recoveryTimeDeferredMatchUpIds = {};
36240
36544
  var dependencyDeferredMatchUpIds = {};
36241
36545
  var scheduleDateRequestConflicts = {};
@@ -36246,7 +36550,7 @@ function proScheduler(_a) {
36246
36550
  var noTimeMatchUpIds = {};
36247
36551
  var requestConflicts = {};
36248
36552
  var _loop_1 = function (dateSchedulingProfile) {
36249
- var e_2, _f, e_3, _g, e_4, _h, e_5, _j;
36553
+ var e_2, _j, e_3, _k, e_4, _l, e_5, _m;
36250
36554
  var scheduleDate = extractDate(dateSchedulingProfile === null || dateSchedulingProfile === void 0 ? void 0 : dateSchedulingProfile.scheduleDate);
36251
36555
  var venues = (dateSchedulingProfile === null || dateSchedulingProfile === void 0 ? void 0 : dateSchedulingProfile.venues) || [];
36252
36556
  var matchUpPotentialParticipantIds = {};
@@ -36272,7 +36576,7 @@ function proScheduler(_a) {
36272
36576
  requestConflicts[scheduleDate] = [];
36273
36577
  // Build up matchUpNotBeforeTimes for all matchUps already scheduled on scheduleDate
36274
36578
  var matchUpNotBeforeTimes = {};
36275
- matchUps.forEach(function (matchUp) {
36579
+ matchUps === null || matchUps === void 0 ? void 0 : matchUps.forEach(function (matchUp) {
36276
36580
  var _a;
36277
36581
  if (((_a = matchUp.schedule) === null || _a === void 0 ? void 0 : _a.scheduledDate) &&
36278
36582
  sameDay(scheduleDate, extractDate(matchUp.schedule.scheduledDate))) {
@@ -36283,7 +36587,7 @@ function proScheduler(_a) {
36283
36587
  });
36284
36588
  }
36285
36589
  });
36286
- var _k = getVenueSchedulingDetails({
36590
+ var _o = getVenueSchedulingDetails({
36287
36591
  matchUpPotentialParticipantIds: matchUpPotentialParticipantIds,
36288
36592
  individualParticipantProfiles: individualParticipantProfiles,
36289
36593
  scheduleCompletedMatchUps: scheduleCompletedMatchUps,
@@ -36298,8 +36602,8 @@ function proScheduler(_a) {
36298
36602
  matchUps: matchUps,
36299
36603
  courts: courts,
36300
36604
  venues: venues,
36301
- }), allDateScheduledByeMatchUpIds = _k.allDateScheduledByeMatchUpIds, allDateScheduledMatchUpIds = _k.allDateScheduledMatchUpIds, venueScheduledRoundDetails = _k.venueScheduledRoundDetails, allDateMatchUpIds = _k.allDateMatchUpIds;
36302
- var dateScheduledMatchUps = matchUps.filter(function (_a) {
36605
+ }), allDateScheduledByeMatchUpDetails = _o.allDateScheduledByeMatchUpDetails, allDateScheduledMatchUpIds = _o.allDateScheduledMatchUpIds, venueScheduledRoundDetails = _o.venueScheduledRoundDetails, allDateMatchUpIds = _o.allDateMatchUpIds;
36606
+ var dateScheduledMatchUps = matchUps === null || matchUps === void 0 ? void 0 : matchUps.filter(function (_a) {
36303
36607
  var matchUpId = _a.matchUpId;
36304
36608
  return allDateScheduledMatchUpIds.includes(matchUpId);
36305
36609
  });
@@ -36342,7 +36646,7 @@ function proScheduler(_a) {
36342
36646
  var schedulingComplete = void 0;
36343
36647
  while (!schedulingComplete) {
36344
36648
  var _loop_2 = function (venueId) {
36345
- var e_6, _q;
36649
+ var e_6, _t;
36346
36650
  var details = venueScheduledRoundDetails[venueId];
36347
36651
  // on each pass attempt to schedule one matchUp per court
36348
36652
  // when a matchUp is scheduled, add it to details.dateScheduledMatchUps
@@ -36353,30 +36657,30 @@ function proScheduler(_a) {
36353
36657
  var passIterations = 0;
36354
36658
  while (!venuePassComplete) {
36355
36659
  var _loop_4 = function (matchUp) {
36356
- var _t;
36660
+ var _w;
36357
36661
  if (courtIdsScheduled.length === details.courtsCount ||
36358
36662
  matchUpIdsScheduled.length === details.courtsCount) {
36359
36663
  venuePassComplete = true;
36360
36664
  return "break";
36361
36665
  }
36362
36666
  var matchUpId = matchUp.matchUpId, matchUpType = matchUp.matchUpType;
36363
- var _u = checkDailyLimits({
36667
+ var _x = checkDailyLimits({
36364
36668
  matchUpPotentialParticipantIds: matchUpPotentialParticipantIds,
36365
36669
  individualParticipantProfiles: individualParticipantProfiles,
36366
36670
  matchUpDailyLimits: matchUpDailyLimits,
36367
36671
  matchUp: matchUp,
36368
- }), participantIdsAtLimit = _u.participantIdsAtLimit, relevantParticipantIds = _u.relevantParticipantIds;
36672
+ }), participantIdsAtLimit = _x.participantIdsAtLimit, relevantParticipantIds = _x.relevantParticipantIds;
36369
36673
  if (participantIdsAtLimit.length) {
36370
36674
  if (!overLimitMatchUpIds[scheduleDate].includes(matchUpId))
36371
36675
  overLimitMatchUpIds[scheduleDate].push(matchUpId);
36372
36676
  return "continue";
36373
36677
  }
36374
- var _v = checkDependenciesScheduled({
36678
+ var _y = checkDependenciesScheduled({
36375
36679
  matchUpScheduleTimes: matchUpScheduleTimes,
36376
36680
  matchUpDependencies: matchUpDependencies,
36377
36681
  allDateMatchUpIds: allDateMatchUpIds,
36378
36682
  matchUp: matchUp,
36379
- }), dependenciesScheduled = _v.dependenciesScheduled, remainingDependencies = _v.remainingDependencies;
36683
+ }), dependenciesScheduled = _y.dependenciesScheduled, remainingDependencies = _y.remainingDependencies;
36380
36684
  if (!dependenciesScheduled) {
36381
36685
  if (!dependencyDeferredMatchUpIds[scheduleDate][matchUpId])
36382
36686
  dependencyDeferredMatchUpIds[scheduleDate][matchUpId] = [];
@@ -36488,12 +36792,12 @@ function proScheduler(_a) {
36488
36792
  else if (schedulingConflicts === null || schedulingConflicts === void 0 ? void 0 : schedulingConflicts.length) {
36489
36793
  if (!scheduleDateRequestConflicts[scheduleDate])
36490
36794
  scheduleDateRequestConflicts[scheduleDate] = [];
36491
- (_t = scheduleDateRequestConflicts[scheduleDate]).push.apply(_t, __spreadArray([], __read(schedulingConflicts), false));
36795
+ (_w = scheduleDateRequestConflicts[scheduleDate]).push.apply(_w, __spreadArray([], __read(schedulingConflicts), false));
36492
36796
  }
36493
36797
  };
36494
36798
  try {
36495
- for (var _r = (e_6 = void 0, __values(details.matchUpsToSchedule)), _s = _r.next(); !_s.done; _s = _r.next()) {
36496
- var matchUp = _s.value;
36799
+ for (var _u = (e_6 = void 0, __values(details.matchUpsToSchedule)), _v = _u.next(); !_v.done; _v = _u.next()) {
36800
+ var matchUp = _v.value;
36497
36801
  var state_1 = _loop_4(matchUp);
36498
36802
  if (state_1 === "break")
36499
36803
  break;
@@ -36502,7 +36806,7 @@ function proScheduler(_a) {
36502
36806
  catch (e_6_1) { e_6 = { error: e_6_1 }; }
36503
36807
  finally {
36504
36808
  try {
36505
- if (_s && !_s.done && (_q = _r.return)) _q.call(_r);
36809
+ if (_v && !_v.done && (_t = _u.return)) _t.call(_u);
36506
36810
  }
36507
36811
  finally { if (e_6) throw e_6.error; }
36508
36812
  }
@@ -36541,7 +36845,7 @@ function proScheduler(_a) {
36541
36845
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
36542
36846
  finally {
36543
36847
  try {
36544
- if (venues_1_1 && !venues_1_1.done && (_f = venues_1.return)) _f.call(venues_1);
36848
+ if (venues_1_1 && !venues_1_1.done && (_j = venues_1.return)) _j.call(venues_1);
36545
36849
  }
36546
36850
  finally { if (e_2) throw e_2.error; }
36547
36851
  }
@@ -36615,17 +36919,32 @@ function proScheduler(_a) {
36615
36919
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
36616
36920
  finally {
36617
36921
  try {
36618
- if (venues_2_1 && !venues_2_1.done && (_g = venues_2.return)) _g.call(venues_2);
36922
+ if (venues_2_1 && !venues_2_1.done && (_k = venues_2.return)) _k.call(venues_2);
36619
36923
  }
36620
36924
  finally { if (e_3) throw e_3.error; }
36621
36925
  }
36622
- if (!dryRun && (allDateScheduledByeMatchUpIds === null || allDateScheduledByeMatchUpIds === void 0 ? void 0 : allDateScheduledByeMatchUpIds.length)) ;
36926
+ if (!dryRun && (allDateScheduledByeMatchUpDetails === null || allDateScheduledByeMatchUpDetails === void 0 ? void 0 : allDateScheduledByeMatchUpDetails.length)) {
36927
+ // remove scheduling information for BYE matchUps from any rounds that were scheduled
36928
+ bulkScheduleMatchUps({
36929
+ matchUpDetails: allDateScheduledByeMatchUpDetails,
36930
+ scheduleByeMatchUps: true,
36931
+ removePriorValues: true,
36932
+ tournamentRecords: tournamentRecords,
36933
+ schedule: {
36934
+ scheduledDate: '',
36935
+ scheduledTime: '',
36936
+ courtOrder: '',
36937
+ courtId: '',
36938
+ venueId: '',
36939
+ },
36940
+ });
36941
+ }
36623
36942
  try {
36624
- for (var _l = (e_4 = void 0, __values(dateSchedulingProfile.venues)), _m = _l.next(); !_m.done; _m = _l.next()) {
36625
- var venue = _m.value;
36943
+ for (var _p = (e_4 = void 0, __values(dateSchedulingProfile.venues)), _q = _p.next(); !_q.done; _q = _p.next()) {
36944
+ var venue = _q.value;
36626
36945
  try {
36627
- for (var _o = (e_5 = void 0, __values(venue.rounds)), _p = _o.next(); !_p.done; _p = _o.next()) {
36628
- var round = _p.value;
36946
+ for (var _r = (e_5 = void 0, __values(venue.rounds)), _s = _r.next(); !_s.done; _s = _r.next()) {
36947
+ var round = _s.value;
36629
36948
  var matchUpIds = ((_d = round.matchUps) !== null && _d !== void 0 ? _d : []).map(function (_a) {
36630
36949
  var matchUpId = _a.matchUpId;
36631
36950
  return matchUpId;
@@ -36646,7 +36965,7 @@ function proScheduler(_a) {
36646
36965
  catch (e_5_1) { e_5 = { error: e_5_1 }; }
36647
36966
  finally {
36648
36967
  try {
36649
- if (_p && !_p.done && (_j = _o.return)) _j.call(_o);
36968
+ if (_s && !_s.done && (_m = _r.return)) _m.call(_r);
36650
36969
  }
36651
36970
  finally { if (e_5) throw e_5.error; }
36652
36971
  }
@@ -36655,27 +36974,27 @@ function proScheduler(_a) {
36655
36974
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
36656
36975
  finally {
36657
36976
  try {
36658
- if (_m && !_m.done && (_h = _l.return)) _h.call(_l);
36977
+ if (_q && !_q.done && (_l = _p.return)) _l.call(_p);
36659
36978
  }
36660
36979
  finally { if (e_4) throw e_4.error; }
36661
36980
  }
36662
36981
  };
36663
36982
  try {
36664
36983
  // Start SCHEDULING
36665
- for (var dateSchedulingProfiles_1 = __values(dateSchedulingProfiles), dateSchedulingProfiles_1_1 = dateSchedulingProfiles_1.next(); !dateSchedulingProfiles_1_1.done; dateSchedulingProfiles_1_1 = dateSchedulingProfiles_1.next()) {
36666
- var dateSchedulingProfile = dateSchedulingProfiles_1_1.value;
36984
+ for (var _g = __values(dateSchedulingProfiles !== null && dateSchedulingProfiles !== void 0 ? dateSchedulingProfiles : []), _h = _g.next(); !_h.done; _h = _g.next()) {
36985
+ var dateSchedulingProfile = _h.value;
36667
36986
  _loop_1(dateSchedulingProfile);
36668
36987
  }
36669
36988
  }
36670
36989
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
36671
36990
  finally {
36672
36991
  try {
36673
- if (dateSchedulingProfiles_1_1 && !dateSchedulingProfiles_1_1.done && (_b = dateSchedulingProfiles_1.return)) _b.call(dateSchedulingProfiles_1);
36992
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
36674
36993
  }
36675
36994
  finally { if (e_1) throw e_1.error; }
36676
36995
  }
36677
36996
  // returns the original form of the dateStrings, before extractDate()
36678
- var scheduledDates = dateSchedulingProfiles.map(function (_a) {
36997
+ var scheduledDates = (dateSchedulingProfiles !== null && dateSchedulingProfiles !== void 0 ? dateSchedulingProfiles : []).map(function (_a) {
36679
36998
  var scheduleDate = _a.scheduleDate;
36680
36999
  return scheduleDate;
36681
37000
  });
@@ -36692,285 +37011,6 @@ function proScheduler(_a) {
36692
37011
  return __assign(__assign({}, SUCCESS), { schedulingProfileModifications: schedulingProfileModifications, schedulingProfileIssues: schedulingProfileIssues, dateSchedulingProfiles: dateSchedulingProfiles, recoveryTimeDeferredMatchUpIds: recoveryTimeDeferredMatchUpIds, dependencyDeferredMatchUpIds: dependencyDeferredMatchUpIds, matchUpScheduleTimes: matchUpScheduleTimes, overLimitMatchUpIds: overLimitMatchUpIds, scheduledMatchUpIds: scheduledMatchUpIds, noTimeMatchUpIds: noTimeMatchUpIds, requestConflicts: requestConflicts, scheduledDates: scheduledDates });
36693
37012
  }
36694
37013
 
36695
- function getPersonRequests(_a) {
36696
- var e_1, _b, e_2, _c, e_3, _d;
36697
- var tournamentRecords = _a.tournamentRecords, requestType = _a.requestType;
36698
- if (typeof tournamentRecords !== 'object' ||
36699
- !Object.keys(tournamentRecords).length)
36700
- return { error: MISSING_TOURNAMENT_RECORDS };
36701
- var personRequests = {};
36702
- try {
36703
- // create merged view of person requests across tournamentRecords
36704
- // ... possible for a person to be in multiple linked tournamentRecords
36705
- for (var _e = __values(Object.values(tournamentRecords)), _f = _e.next(); !_f.done; _f = _e.next()) {
36706
- var tournamentRecord = _f.value;
36707
- var extension = findTournamentExtension({
36708
- name: PERSON_REQUESTS,
36709
- tournamentRecord: tournamentRecord,
36710
- }).extension;
36711
- var requestObjects = (extension === null || extension === void 0 ? void 0 : extension.value) || [];
36712
- try {
36713
- for (var requestObjects_1 = (e_2 = void 0, __values(requestObjects)), requestObjects_1_1 = requestObjects_1.next(); !requestObjects_1_1.done; requestObjects_1_1 = requestObjects_1.next()) {
36714
- var requestObject = requestObjects_1_1.value;
36715
- var _g = requestObject || {}, personId = _g.personId, requests = _g.requests;
36716
- if (!personRequests[personId])
36717
- personRequests[personId] = [];
36718
- try {
36719
- for (var requests_1 = (e_3 = void 0, __values(requests)), requests_1_1 = requests_1.next(); !requests_1_1.done; requests_1_1 = requests_1.next()) {
36720
- var request = requests_1_1.value;
36721
- if (requestType && request.requestType !== requestType)
36722
- continue;
36723
- personRequests[personId].push(request);
36724
- }
36725
- }
36726
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
36727
- finally {
36728
- try {
36729
- if (requests_1_1 && !requests_1_1.done && (_d = requests_1.return)) _d.call(requests_1);
36730
- }
36731
- finally { if (e_3) throw e_3.error; }
36732
- }
36733
- }
36734
- }
36735
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
36736
- finally {
36737
- try {
36738
- if (requestObjects_1_1 && !requestObjects_1_1.done && (_c = requestObjects_1.return)) _c.call(requestObjects_1);
36739
- }
36740
- finally { if (e_2) throw e_2.error; }
36741
- }
36742
- }
36743
- }
36744
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
36745
- finally {
36746
- try {
36747
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
36748
- }
36749
- finally { if (e_1) throw e_1.error; }
36750
- }
36751
- // audit requests and filter out any that are no longer relevant
36752
- // (tournament dates changed & etc)
36753
- return { personRequests: personRequests };
36754
- }
36755
- function savePersonRequests(_a) {
36756
- var e_4, _b, e_5, _c;
36757
- var _d;
36758
- var tournamentRecords = _a.tournamentRecords, personRequests = _a.personRequests;
36759
- if (!tournamentRecords)
36760
- return { error: MISSING_TOURNAMENT_RECORDS };
36761
- if (!personRequests)
36762
- return __assign({}, SUCCESS);
36763
- var tournaments = Object.values(tournamentRecords);
36764
- try {
36765
- for (var tournaments_1 = __values(tournaments), tournaments_1_1 = tournaments_1.next(); !tournaments_1_1.done; tournaments_1_1 = tournaments_1.next()) {
36766
- var tournamentRecord = tournaments_1_1.value;
36767
- var tournamentParticipants = (_d = tournamentRecord.participants) !== null && _d !== void 0 ? _d : [];
36768
- var relevantPersonRequests = [];
36769
- try {
36770
- for (var _e = (e_5 = void 0, __values(Object.keys(personRequests))), _f = _e.next(); !_f.done; _f = _e.next()) {
36771
- var personId = _f.value;
36772
- if (findParticipant({ tournamentParticipants: tournamentParticipants, personId: personId })) {
36773
- var requests = personRequests[personId];
36774
- if (requests.length)
36775
- relevantPersonRequests.push({ personId: personId, requests: requests });
36776
- }
36777
- }
36778
- }
36779
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
36780
- finally {
36781
- try {
36782
- if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
36783
- }
36784
- finally { if (e_5) throw e_5.error; }
36785
- }
36786
- if (Object.keys(relevantPersonRequests).length) {
36787
- var extension = {
36788
- name: PERSON_REQUESTS,
36789
- value: relevantPersonRequests,
36790
- };
36791
- addTournamentExtension({ tournamentRecord: tournamentRecord, extension: extension });
36792
- }
36793
- }
36794
- }
36795
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
36796
- finally {
36797
- try {
36798
- if (tournaments_1_1 && !tournaments_1_1.done && (_b = tournaments_1.return)) _b.call(tournaments_1);
36799
- }
36800
- finally { if (e_4) throw e_4.error; }
36801
- }
36802
- return __assign({}, SUCCESS);
36803
- }
36804
- function addPersonRequests(_a) {
36805
- var tournamentRecords = _a.tournamentRecords, personId = _a.personId, requests = _a.requests;
36806
- if (!tournamentRecords)
36807
- return { error: MISSING_TOURNAMENT_RECORDS };
36808
- if (typeof personId !== 'string')
36809
- return { error: INVALID_VALUES };
36810
- if (!Array.isArray(requests))
36811
- return { error: INVALID_VALUES };
36812
- var personRequests = getPersonRequests({ tournamentRecords: tournamentRecords }).personRequests;
36813
- var mergeCount = mergePersonRequests({
36814
- personRequests: personRequests,
36815
- personId: personId,
36816
- requests: requests,
36817
- }).mergeCount;
36818
- if (mergeCount && personRequests) {
36819
- return savePersonRequests({ tournamentRecords: tournamentRecords, personRequests: personRequests });
36820
- }
36821
- else {
36822
- return { error: INVALID_VALUES };
36823
- }
36824
- }
36825
- // check whether there is a request for the date with overlapping times
36826
- // extend startTime/endTime rather than creating multiple
36827
- // ... only pertains to { requestType: DO_NOT_SCHEDULE }
36828
- function mergePersonRequests(_a) {
36829
- var e_6, _b;
36830
- var personRequests = _a.personRequests, personId = _a.personId, requests = _a.requests;
36831
- if (!personRequests[personId])
36832
- personRequests[personId] = [];
36833
- var filteredRequests = requests
36834
- .filter(function (_a) {
36835
- var requestType = _a.requestType;
36836
- return requestType;
36837
- })
36838
- .map(function (request) {
36839
- var date = request.date, startTime = request.startTime, endTime = request.endTime;
36840
- // validate requestType
36841
- if (request.requestType === DO_NOT_SCHEDULE) {
36842
- date = extractDate(date);
36843
- startTime = extractTime(startTime);
36844
- endTime = extractTime(endTime);
36845
- if (date && startTime && endTime) {
36846
- return { date: date, startTime: startTime, endTime: endTime, requestType: request.requestType };
36847
- }
36848
- }
36849
- return request;
36850
- })
36851
- .filter(Boolean);
36852
- try {
36853
- // Do not add any request that is missing requestType
36854
- for (var filteredRequests_1 = __values(filteredRequests), filteredRequests_1_1 = filteredRequests_1.next(); !filteredRequests_1_1.done; filteredRequests_1_1 = filteredRequests_1.next()) {
36855
- var request = filteredRequests_1_1.value;
36856
- request.requestId = generateTimeCode();
36857
- personRequests[personId].push(request);
36858
- }
36859
- }
36860
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
36861
- finally {
36862
- try {
36863
- if (filteredRequests_1_1 && !filteredRequests_1_1.done && (_b = filteredRequests_1.return)) _b.call(filteredRequests_1);
36864
- }
36865
- finally { if (e_6) throw e_6.error; }
36866
- }
36867
- return { mergeCount: filteredRequests.length };
36868
- }
36869
- // personRequests can be removed by date, requestId, or requestType
36870
- function removePersonRequests(_a) {
36871
- var e_7, _b;
36872
- var tournamentRecords = _a.tournamentRecords, requestType = _a.requestType, requestId = _a.requestId, personId = _a.personId, date = _a.date;
36873
- if (typeof tournamentRecords !== 'object' ||
36874
- !Object.keys(tournamentRecords).length)
36875
- return { error: MISSING_TOURNAMENT_RECORDS };
36876
- var personRequests = getPersonRequests({ tournamentRecords: tournamentRecords }).personRequests;
36877
- var filterRequests = function (personId) {
36878
- var _a;
36879
- if (personRequests) {
36880
- personRequests[personId] = personRequests[personId].filter(function (request) {
36881
- return ((!requestType || request.requestType !== requestType) &&
36882
- (!requestId || request.requestId !== requestId) &&
36883
- (!date || request.date !== date));
36884
- });
36885
- if (!((_a = personRequests === null || personRequests === void 0 ? void 0 : personRequests[personId]) === null || _a === void 0 ? void 0 : _a.length))
36886
- delete personRequests[personId];
36887
- }
36888
- };
36889
- var removeAll = !requestType && !requestId && !personId && !date;
36890
- if (!removeAll) {
36891
- if (personId && (personRequests === null || personRequests === void 0 ? void 0 : personRequests[personId])) {
36892
- filterRequests(personId);
36893
- }
36894
- else if (personRequests) {
36895
- try {
36896
- for (var _c = __values(Object.keys(personRequests)), _d = _c.next(); !_d.done; _d = _c.next()) {
36897
- var personId_1 = _d.value;
36898
- filterRequests(personId_1);
36899
- }
36900
- }
36901
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
36902
- finally {
36903
- try {
36904
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
36905
- }
36906
- finally { if (e_7) throw e_7.error; }
36907
- }
36908
- }
36909
- }
36910
- if (removeAll || !personRequests || !Object.keys(personRequests).length) {
36911
- return removeExtension({ tournamentRecords: tournamentRecords, name: PERSON_REQUESTS });
36912
- }
36913
- else {
36914
- return savePersonRequests({ tournamentRecords: tournamentRecords, personRequests: personRequests });
36915
- }
36916
- }
36917
- // can be used to both add and remove requests
36918
- // requests which don't have existing requestId will be added
36919
- // requests which don't have requestType will be removed
36920
- function modifyPersonRequests(_a) {
36921
- var e_8, _b;
36922
- var tournamentRecords = _a.tournamentRecords, requests = _a.requests, personId = _a.personId;
36923
- if (!tournamentRecords)
36924
- return { error: MISSING_TOURNAMENT_RECORDS };
36925
- if (!Array.isArray(requests))
36926
- return { error: INVALID_VALUES };
36927
- var requestIds = requests.map(function (_a) {
36928
- var requestId = _a.requestId;
36929
- return requestId;
36930
- }).filter(Boolean);
36931
- var personRequests = getPersonRequests({ tournamentRecords: tournamentRecords }).personRequests;
36932
- var modifyRequests = function (personId) {
36933
- if (personRequests) {
36934
- personRequests[personId] = personRequests[personId]
36935
- .map(function (request) {
36936
- // if requestId not in requestIds then return unmodified
36937
- if (!requestIds.includes(request.requestId))
36938
- return request;
36939
- // find the updatedRequest
36940
- var modification = requests.find(function (updatedRequest) { return updatedRequest.requestId === request.requestId; });
36941
- // FEATURE: returning an updatedRequest without a requestType will remove it
36942
- if (!modification.requestType)
36943
- return;
36944
- return Object.assign(request, modification);
36945
- })
36946
- .filter(Boolean);
36947
- }
36948
- };
36949
- if (personId && (personRequests === null || personRequests === void 0 ? void 0 : personRequests[personId])) {
36950
- modifyRequests(personId);
36951
- }
36952
- else if (personRequests) {
36953
- try {
36954
- for (var _c = __values(Object.keys(personRequests)), _d = _c.next(); !_d.done; _d = _c.next()) {
36955
- var personId_2 = _d.value;
36956
- modifyRequests(personId_2);
36957
- }
36958
- }
36959
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
36960
- finally {
36961
- try {
36962
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
36963
- }
36964
- finally { if (e_8) throw e_8.error; }
36965
- }
36966
- }
36967
- var newRequests = requests.filter(function (request) { return !request.requestId; });
36968
- if (newRequests.length) {
36969
- mergePersonRequests({ personRequests: personRequests, personId: personId, requests: newRequests });
36970
- }
36971
- return savePersonRequests({ tournamentRecords: tournamentRecords, personRequests: personRequests });
36972
- }
36973
-
36974
37014
  function clearScheduledMatchUps$1(_a) {
36975
37015
  var e_1, _b;
36976
37016
  var _c, _d, _e;
@@ -37104,7 +37144,7 @@ function getMatchUpDailyLimits(_a) {
37104
37144
 
37105
37145
  // abstraction layer to allow other schedulers to be defined at a later time
37106
37146
  function scheduleProfileRounds(_a) {
37107
- var _b = _a.checkPotentialRequestConflicts, checkPotentialRequestConflicts = _b === void 0 ? true : _b, scheduleCompletedMatchUps = _a.scheduleCompletedMatchUps, clearScheduleDates = _a.clearScheduleDates, _c = _a.scheduleDates, scheduleDates = _c === void 0 ? [] : _c, tournamentRecords = _a.tournamentRecords, periodLength = _a.periodLength, dryRun = _a.dryRun, pro = _a.pro;
37147
+ var _b = _a.checkPotentialRequestConflicts, checkPotentialRequestConflicts = _b === void 0 ? true : _b, scheduleCompletedMatchUps = _a.scheduleCompletedMatchUps, clearScheduleDates = _a.clearScheduleDates, _c = _a.scheduleDates, scheduleDates = _c === void 0 ? [] : _c, tournamentRecords = _a.tournamentRecords, periodLength = _a.periodLength, useGarman = _a.useGarman, dryRun = _a.dryRun, pro = _a.pro;
37108
37148
  if (!tournamentRecords)
37109
37149
  return { error: MISSING_TOURNAMENT_RECORDS };
37110
37150
  if (!Array.isArray(scheduleDates))
@@ -37112,7 +37152,7 @@ function scheduleProfileRounds(_a) {
37112
37152
  var result = getSchedulingProfile$1({ tournamentRecords: tournamentRecords });
37113
37153
  if (result.error)
37114
37154
  return result;
37115
- var _d = result.schedulingProfile, schedulingProfile = _d === void 0 ? [] : _d, _e = result.issues, schedulingProfileIssues = _e === void 0 ? [] : _e, schedulingProfileModifications = result.modifications;
37155
+ var schedulingProfileModifications = result.modifications, _d = result.issues, schedulingProfileIssues = _d === void 0 ? [] : _d, _e = result.schedulingProfile, schedulingProfile = _e === void 0 ? [] : _e;
37116
37156
  // round robin structures contain other structures and the scheduler
37117
37157
  // needs to reference the containing structure by contained structureIds
37118
37158
  var containedStructureIds = Object.assign.apply(Object, __spreadArray([{}], __read(Object.values(tournamentRecords).map(function (tournamentRecord) {
@@ -37191,12 +37231,13 @@ function scheduleProfileRounds(_a) {
37191
37231
  schedulingProfile: schedulingProfile,
37192
37232
  personRequests: personRequests,
37193
37233
  periodLength: periodLength,
37234
+ useGarman: useGarman,
37194
37235
  matchUps: matchUps,
37195
37236
  dryRun: dryRun,
37196
37237
  courts: courts,
37197
37238
  };
37198
37239
  if (pro) {
37199
- return proScheduler(params);
37240
+ return v2Scheduler(params);
37200
37241
  }
37201
37242
  else {
37202
37243
  return jinnScheduler(params);
@@ -40570,8 +40611,7 @@ function deleteVenue$1(_a) {
40570
40611
  var appliedPolicies = (_d = getAppliedPolicies({
40571
40612
  tournamentRecord: tournamentRecord,
40572
40613
  })) === null || _d === void 0 ? void 0 : _d.appliedPolicies;
40573
- var allowModificationWhenMatchUpsScheduled = force ||
40574
- ((_f = (_e = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SCHEDULING]) === null || _e === void 0 ? void 0 : _e.allowDeletionWithScoresPresent) === null || _f === void 0 ? void 0 : _f.venues);
40614
+ var allowModificationWhenMatchUpsScheduled = force !== null && force !== void 0 ? force : (_f = (_e = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SCHEDULING]) === null || _e === void 0 ? void 0 : _e.allowDeletionWithScoresPresent) === null || _f === void 0 ? void 0 : _f.venues;
40575
40615
  if (!matchUpsToUnschedule.length || allowModificationWhenMatchUpsScheduled) {
40576
40616
  try {
40577
40617
  // if no matchUpsToUnschedule this does nothing but avoid the deletionMessage
@@ -40831,8 +40871,7 @@ function deleteCourt$1(_a) {
40831
40871
  var appliedPolicies = (_c = getAppliedPolicies({
40832
40872
  tournamentRecord: tournamentRecord,
40833
40873
  })) === null || _c === void 0 ? void 0 : _c.appliedPolicies;
40834
- var allowModificationWhenMatchUpsScheduled = force ||
40835
- ((_e = (_d = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SCHEDULING]) === null || _d === void 0 ? void 0 : _d.allowDeletionWithScoresPresent) === null || _e === void 0 ? void 0 : _e.courts);
40874
+ var allowModificationWhenMatchUpsScheduled = force !== null && force !== void 0 ? force : (_e = (_d = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SCHEDULING]) === null || _d === void 0 ? void 0 : _d.allowDeletionWithScoresPresent) === null || _e === void 0 ? void 0 : _e.courts;
40836
40875
  if (!(matchUps === null || matchUps === void 0 ? void 0 : matchUps.length) || allowModificationWhenMatchUpsScheduled) {
40837
40876
  try {
40838
40877
  for (var _g = __values(matchUps !== null && matchUps !== void 0 ? matchUps : []), _h = _g.next(); !_h.done; _h = _g.next()) {
@@ -41055,6 +41094,9 @@ function modifyCourtAvailability(_a) {
41055
41094
  var dateResult = validDateAvailability({ dateAvailability: dateAvailability });
41056
41095
  if (dateResult.error)
41057
41096
  return dateResult;
41097
+ // TODO: build up a map of affected dates and:
41098
+ // 1. whether aggregate time on given dates has increased or decreased
41099
+ // 2. specific periods of time on given dates that are no longer available
41058
41100
  var _e = sortAndMergeDateAvailability(dateAvailability), updatedDateAvailability = _e.updatedDateAvailability, totalMergeCount = _e.totalMergeCount;
41059
41101
  dateAvailability = updatedDateAvailability;
41060
41102
  var courtResult = findCourt({ tournamentRecord: tournamentRecord, courtId: courtId });
@@ -41067,15 +41109,24 @@ function modifyCourtAvailability(_a) {
41067
41109
  courtId: courtId,
41068
41110
  }).matchUps;
41069
41111
  // TODO: check whether there are matchUps which are no longer possible to play
41070
- // this will only apply to Pro Scheduling
41112
+ // In the first instance, matchUps which are explicitly scheduled on the court for times which are no longer available
41113
+ // NOTE: see dateAvailability.test.ts
41071
41114
  if (courtMatchUps === null || courtMatchUps === void 0 ? void 0 : courtMatchUps.length) {
41072
41115
  var appliedPolicies = (_b = getAppliedPolicies({
41073
41116
  tournamentRecord: tournamentRecord,
41074
41117
  })) === null || _b === void 0 ? void 0 : _b.appliedPolicies;
41075
- force ||
41076
- ((_d = (_c = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SCHEDULING]) === null || _c === void 0 ? void 0 : _c.allowDeletionWithScoresPresent) === null || _d === void 0 ? void 0 : _d.courts);
41077
- console.log('scheduled court matchUps', courtMatchUps.length);
41118
+ var allowModificationWhenMatchUpsScheduled = force !== null && force !== void 0 ? force : (_d = (_c = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SCHEDULING]) === null || _c === void 0 ? void 0 : _c.allowDeletionWithScoresPresent) === null || _d === void 0 ? void 0 : _d.courts;
41119
+ // Iterate through courtMatchUps and check that scheduledTime/scheduledDate still avilable
41120
+ var matchUpsWithInvalidScheduling = [];
41121
+ if (matchUpsWithInvalidScheduling.length) {
41122
+ if (allowModificationWhenMatchUpsScheduled) ;
41123
+ else {
41124
+ console.log('throw error: scheduled court matchUps', matchUpsWithInvalidScheduling.length);
41125
+ }
41126
+ }
41078
41127
  }
41128
+ // TODO: In the second instance, if there is reduced aggregate court time matchUps scheduled on the affected dates (but not specific court)
41129
+ // would have scheduling impacts impacts
41079
41130
  if (court) {
41080
41131
  court.dateAvailability = dateAvailability;
41081
41132
  if (!disableNotice && venue)
@@ -41392,8 +41443,7 @@ function modifyVenue$1(_a) {
41392
41443
  var appliedPolicies = (_c = getAppliedPolicies({
41393
41444
  tournamentRecord: tournamentRecord,
41394
41445
  })) === null || _c === void 0 ? void 0 : _c.appliedPolicies;
41395
- var allowModificationWhenMatchUpsScheduled = force ||
41396
- ((_e = (_d = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SCHEDULING]) === null || _d === void 0 ? void 0 : _d.allowDeletionWithScoresPresent) === null || _e === void 0 ? void 0 : _e.venues);
41446
+ var allowModificationWhenMatchUpsScheduled = force !== null && force !== void 0 ? force : (_e = (_d = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SCHEDULING]) === null || _d === void 0 ? void 0 : _d.allowDeletionWithScoresPresent) === null || _e === void 0 ? void 0 : _e.venues;
41397
41447
  var venueMatchUps = getScheduledVenueMatchUps({
41398
41448
  tournamentRecord: tournamentRecord,
41399
41449
  venueId: venueId,
@@ -41417,25 +41467,49 @@ function modifyVenue$1(_a) {
41417
41467
  var existingCourtIds = (_g = (_f = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _f === void 0 ? void 0 : _f.map(function (court) { return court.courtId; })) !== null && _g !== void 0 ? _g : [];
41418
41468
  var courtIdsToModify = ((_h = modifications.courts) === null || _h === void 0 ? void 0 : _h.map(function (court) { return court.courtId; })) || [];
41419
41469
  var courtIdsToDelete = existingCourtIds.filter(function (courtId) { return !courtIdsToModify.includes(courtId); });
41470
+ var matchUpsWithCourtId = [];
41420
41471
  if (courtIdsToDelete.length) {
41421
41472
  var courtsToDelete = (_j = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _j === void 0 ? void 0 : _j.filter(function (court) {
41422
41473
  return courtIdsToDelete.includes(court.courtId);
41423
41474
  });
41424
41475
  var scheduleDeletionsCount = courtsToDelete === null || courtsToDelete === void 0 ? void 0 : courtsToDelete.map(function (court) {
41425
- var _a, _b;
41476
+ var e_2, _a;
41477
+ var _b, _c, _d;
41426
41478
  // check whether deleting court would remove schedule from any matchUps
41427
41479
  var result = getScheduledCourtMatchUps({
41428
41480
  courtId: court.courtId,
41429
41481
  tournamentRecord: tournamentRecord,
41430
41482
  venueMatchUps: venueMatchUps,
41431
41483
  });
41432
- return (_b = (_a = result.matchUps) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
41484
+ try {
41485
+ for (var _e = __values((_b = result.matchUps) !== null && _b !== void 0 ? _b : []), _f = _e.next(); !_f.done; _f = _e.next()) {
41486
+ var matchUp = _f.value;
41487
+ matchUpsWithCourtId.push({
41488
+ matchUpId: matchUp.matchUpId,
41489
+ drawId: matchUp.drawId,
41490
+ });
41491
+ }
41492
+ }
41493
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
41494
+ finally {
41495
+ try {
41496
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
41497
+ }
41498
+ finally { if (e_2) throw e_2.error; }
41499
+ }
41500
+ return (_d = (_c = result.matchUps) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
41433
41501
  }).reduce(function (a, b) { return a + b; });
41434
41502
  if (venue &&
41435
41503
  (!scheduleDeletionsCount || allowModificationWhenMatchUpsScheduled)) {
41436
41504
  venue.courts = (_k = venue.courts) === null || _k === void 0 ? void 0 : _k.filter(function (court) {
41437
41505
  return courtIdsToModify.includes(court.courtId);
41438
41506
  });
41507
+ bulkScheduleMatchUps$1({
41508
+ schedule: { courtId: '', scheduledDate: '' },
41509
+ matchUpDetails: matchUpsWithCourtId,
41510
+ removePriorValues: true,
41511
+ tournamentRecord: tournamentRecord,
41512
+ });
41439
41513
  }
41440
41514
  else {
41441
41515
  return deletionMessage({
@@ -44554,8 +44628,8 @@ function setStageQualifiersCount(_a) {
44554
44628
  }
44555
44629
 
44556
44630
  function generateDrawTypeAndModifyDrawDefinition$1(params) {
44557
- var _a;
44558
- var _b = params || {}, _c = _b.modifyOriginal, modifyOriginal = _c === void 0 ? true : _c, _d = _b.stageSequence, stageSequence = _d === void 0 ? 1 : _d, isMock = _b.isMock;
44631
+ var _a, _b;
44632
+ var _c = params || {}, _d = _c.modifyOriginal, modifyOriginal = _d === void 0 ? true : _d, _e = _c.stageSequence, stageSequence = _e === void 0 ? 1 : _e, isMock = _c.isMock;
44559
44633
  var stack = 'generateDrawTypeAndModifyDrawDefinition';
44560
44634
  if (!params.drawDefinition)
44561
44635
  return decorateResult({
@@ -44625,7 +44699,7 @@ function generateDrawTypeAndModifyDrawDefinition$1(params) {
44625
44699
  }
44626
44700
  var drawSize = params.drawSize || mainStageDrawPositionsCount;
44627
44701
  Object.assign(params, definedAttributes({ drawSize: drawSize, matchUpType: matchUpType, tieFormat: tieFormat }));
44628
- var _e = getAllDrawMatchUps({ drawDefinition: drawDefinition }), matchUps = _e.matchUps, matchUpsMap = _e.matchUpsMap;
44702
+ var _f = getAllDrawMatchUps({ drawDefinition: drawDefinition }), matchUps = _f.matchUps, matchUpsMap = _f.matchUpsMap;
44629
44703
  if (tieFormat) {
44630
44704
  // if there were exiting matchUps, exclude them from this step
44631
44705
  matchUps === null || matchUps === void 0 ? void 0 : matchUps.forEach(function (matchUp) {
@@ -44636,7 +44710,10 @@ function generateDrawTypeAndModifyDrawDefinition$1(params) {
44636
44710
  });
44637
44711
  }
44638
44712
  var inContextDrawMatchUps = addGoesTo({ drawDefinition: drawDefinition, matchUpsMap: matchUpsMap }).inContextDrawMatchUps;
44639
- modifyDrawNotice({ drawDefinition: drawDefinition });
44713
+ modifyDrawNotice({
44714
+ tournamentId: (_b = params.tournamentRecord) === null || _b === void 0 ? void 0 : _b.tournamentId,
44715
+ drawDefinition: drawDefinition,
44716
+ });
44640
44717
  return __assign(__assign({ inContextDrawMatchUps: inContextDrawMatchUps, drawDefinition: drawDefinition, matchUpsMap: matchUpsMap }, SUCCESS), { structures: structures, matchUps: matchUps, links: links });
44641
44718
  }
44642
44719
 
@@ -48128,7 +48205,7 @@ function renameStructures$1(_a) {
48128
48205
  }
48129
48206
 
48130
48207
  function removeStructure(_a) {
48131
- var _b, _c, _d, _e, _f, _g;
48208
+ var _b, _c, _d, _e, _f, _g, _h, _j;
48132
48209
  var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, event = _a.event, force = _a.force;
48133
48210
  if (typeof structureId !== 'string')
48134
48211
  return { error: INVALID_VALUES };
@@ -48175,7 +48252,6 @@ function removeStructure(_a) {
48175
48252
  }
48176
48253
  var structureIds = structures.map(extractAttributes('structureId'));
48177
48254
  var removedMatchUpIds = [];
48178
- var idsToRemove = [structureId];
48179
48255
  var getTargetedStructureIds = function (structureId) {
48180
48256
  var _a, _b;
48181
48257
  return (_b = (_a = drawDefinition.links) === null || _a === void 0 ? void 0 : _a.map(function (link) {
@@ -48199,6 +48275,9 @@ function removeStructure(_a) {
48199
48275
  ? getQualifyingSourceStructureIds(id)
48200
48276
  : getTargetedStructureIds(id));
48201
48277
  });
48278
+ var idsToRemove = isMainStageSequence1
48279
+ ? relatedStructureIdsMap.get(structureId)
48280
+ : [structureId];
48202
48281
  var _loop_1 = function () {
48203
48282
  var idBeingRemoved = idsToRemove.pop();
48204
48283
  var structure_1 = findStructure({
@@ -48223,9 +48302,7 @@ function removeStructure(_a) {
48223
48302
  });
48224
48303
  }
48225
48304
  var targetedStructureIds = idBeingRemoved &&
48226
- (
48227
- // targetedStructureIdsMap[idBeingRemoved].filter(
48228
- (_g = relatedStructureIdsMap.get(idBeingRemoved)) === null || _g === void 0 ? void 0 : _g.filter(function (id) {
48305
+ ((_g = relatedStructureIdsMap.get(idBeingRemoved)) === null || _g === void 0 ? void 0 : _g.filter(function (id) {
48229
48306
  // IMPORTANT: only delete MAIN stageSequence: 1 if specified to protect against DOUBLE_ELIMINATION scenario
48230
48307
  return id !== (mainStageSequence1 === null || mainStageSequence1 === void 0 ? void 0 : mainStageSequence1.structureId) ||
48231
48308
  structureId === mainStageSequence1.structureId;
@@ -48233,7 +48310,7 @@ function removeStructure(_a) {
48233
48310
  if (targetedStructureIds === null || targetedStructureIds === void 0 ? void 0 : targetedStructureIds.length)
48234
48311
  idsToRemove.push.apply(idsToRemove, __spreadArray([], __read(targetedStructureIds), false));
48235
48312
  };
48236
- while (idsToRemove.length) {
48313
+ while (idsToRemove === null || idsToRemove === void 0 ? void 0 : idsToRemove.length) {
48237
48314
  _loop_1();
48238
48315
  }
48239
48316
  // now get all remaining matchUps in the draw
@@ -48250,6 +48327,8 @@ function removeStructure(_a) {
48250
48327
  });
48251
48328
  // if this is MAIN stageSequence: 1 there must be qualifying, return to empty state
48252
48329
  if (isMainStageSequence1) {
48330
+ var mainStageSequence1MatchUpIds = (_j = ((_h = mainStageSequence1.matchUps) !== null && _h !== void 0 ? _h : [])) === null || _j === void 0 ? void 0 : _j.map(extractAttributes('matchUpId'));
48331
+ removedMatchUpIds.push.apply(removedMatchUpIds, __spreadArray([], __read(mainStageSequence1MatchUpIds), false));
48253
48332
  mainStageSequence1.positionAssignments = [];
48254
48333
  mainStageSequence1.seedAssignments = [];
48255
48334
  mainStageSequence1.matchUps = [];
@@ -70664,7 +70743,7 @@ function generateVenues(_a) {
70664
70743
  function modifyTournamentRecord(params) {
70665
70744
  var e_1, _a, e_2, _b, _c, _d;
70666
70745
  var _e, _f, _g;
70667
- var _h = params.ratingsParameters, ratingsParameters$1 = _h === void 0 ? ratingsParameters : _h, _j = params.participantsProfile, participantsProfile = _j === void 0 ? {} : _j, matchUpStatusProfile = params.matchUpStatusProfile, completeAllMatchUps = params.completeAllMatchUps, autoEntryPositions = params.autoEntryPositions, hydrateCollections = params.hydrateCollections, randomWinningSide = params.randomWinningSide, schedulingProfile = params.schedulingProfile, tournamentRecord = params.tournamentRecord, eventProfiles = params.eventProfiles, venueProfiles = params.venueProfiles, autoSchedule = params.autoSchedule, drawProfiles = params.drawProfiles, uuids = params.uuids;
70746
+ var _h = params.ratingsParameters, ratingsParameters$1 = _h === void 0 ? ratingsParameters : _h, _j = params.participantsProfile, participantsProfile = _j === void 0 ? {} : _j, matchUpStatusProfile = params.matchUpStatusProfile, completeAllMatchUps = params.completeAllMatchUps, autoEntryPositions = params.autoEntryPositions, hydrateCollections = params.hydrateCollections, randomWinningSide = params.randomWinningSide, schedulingProfile = params.schedulingProfile, tournamentRecord = params.tournamentRecord, eventProfiles = params.eventProfiles, periodLength = params.periodLength, venueProfiles = params.venueProfiles, autoSchedule = params.autoSchedule, drawProfiles = params.drawProfiles, uuids = params.uuids;
70668
70747
  if (!tournamentRecord)
70669
70748
  return { error: MISSING_TOURNAMENT_RECORD };
70670
70749
  var allUniqueParticipantIds = [];
@@ -70871,7 +70950,10 @@ function modifyTournamentRecord(params) {
70871
70950
  if (autoSchedule) {
70872
70951
  var tournamentId = tournamentRecord.tournamentId;
70873
70952
  var tournamentRecords_1 = (_d = {}, _d[tournamentId] = tournamentRecord, _d);
70874
- schedulerResult = scheduleProfileRounds({ tournamentRecords: tournamentRecords_1 });
70953
+ schedulerResult = scheduleProfileRounds({
70954
+ tournamentRecords: tournamentRecords_1,
70955
+ periodLength: periodLength,
70956
+ });
70875
70957
  }
70876
70958
  }
70877
70959
  var totalParticipantsCount = tournamentRecord.participants.length;
@@ -70996,7 +71078,7 @@ var mockTournamentNames = [
70996
71078
  function generateTournamentRecord(params) {
70997
71079
  var e_1, _a, _b, e_2, _c, e_3, _d, _e;
70998
71080
  var tournamentAttributes = params.tournamentAttributes, startDate = params.startDate, endDate = params.endDate;
70999
- var _f = params.tournamentName, tournamentName = _f === void 0 ? randomPop(mockTournamentNames) : _f, _g = params.ratingsParameters, ratingsParameters$1 = _g === void 0 ? ratingsParameters : _g, scheduleCompletedMatchUps = params.scheduleCompletedMatchUps, tournamentExtensions = params.tournamentExtensions, matchUpStatusProfile = params.matchUpStatusProfile, completeAllMatchUps = params.completeAllMatchUps, participantsProfile = params.participantsProfile, autoEntryPositions = params.autoEntryPositions, hydrateCollections = params.hydrateCollections, randomWinningSide = params.randomWinningSide, policyDefinitions = params.policyDefinitions, schedulingProfile = params.schedulingProfile, autoSchedule = params.autoSchedule, eventProfiles = params.eventProfiles, venueProfiles = params.venueProfiles, drawProfiles = params.drawProfiles, uuids = params.uuids;
71081
+ var _f = params.tournamentName, tournamentName = _f === void 0 ? randomPop(mockTournamentNames) : _f, _g = params.ratingsParameters, ratingsParameters$1 = _g === void 0 ? ratingsParameters : _g, scheduleCompletedMatchUps = params.scheduleCompletedMatchUps, tournamentExtensions = params.tournamentExtensions, matchUpStatusProfile = params.matchUpStatusProfile, completeAllMatchUps = params.completeAllMatchUps, participantsProfile = params.participantsProfile, autoEntryPositions = params.autoEntryPositions, hydrateCollections = params.hydrateCollections, randomWinningSide = params.randomWinningSide, policyDefinitions = params.policyDefinitions, schedulingProfile = params.schedulingProfile, periodLength = params.periodLength, autoSchedule = params.autoSchedule, eventProfiles = params.eventProfiles, venueProfiles = params.venueProfiles, drawProfiles = params.drawProfiles, uuids = params.uuids;
71000
71082
  if ((startDate && !isValidDateString(startDate)) ||
71001
71083
  (endDate && !isValidDateString(endDate)))
71002
71084
  return { error: INVALID_DATE };
@@ -71157,6 +71239,7 @@ function generateTournamentRecord(params) {
71157
71239
  schedulerResult = scheduleProfileRounds({
71158
71240
  scheduleCompletedMatchUps: scheduleCompletedMatchUps,
71159
71241
  tournamentRecords: tournamentRecords,
71242
+ periodLength: periodLength,
71160
71243
  });
71161
71244
  }
71162
71245
  }