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.
package/dist/index.mjs CHANGED
@@ -2404,7 +2404,7 @@ const matchUpFormatCode = {
2404
2404
  };
2405
2405
 
2406
2406
  function factoryVersion() {
2407
- return "1.8.41";
2407
+ return "1.8.42";
2408
2408
  }
2409
2409
 
2410
2410
  function getObjectTieFormat(obj) {
@@ -20773,6 +20773,7 @@ function bulkScheduleMatchUps$1({
20773
20773
  errorOnAnachronism = false,
20774
20774
  checkChronology = true,
20775
20775
  matchUpDependencies,
20776
+ removePriorValues,
20776
20777
  tournamentRecords,
20777
20778
  tournamentRecord,
20778
20779
  matchUpDetails,
@@ -20789,7 +20790,10 @@ function bulkScheduleMatchUps$1({
20789
20790
  const warnings = [];
20790
20791
  let scheduled = 0;
20791
20792
  if (checkChronology && !matchUpDependencies) {
20792
- const result = getMatchUpDependencies({ tournamentRecords });
20793
+ const result = getMatchUpDependencies({
20794
+ tournamentRecords,
20795
+ tournamentRecord
20796
+ });
20793
20797
  matchUpDependencies = result.matchUpDependencies;
20794
20798
  inContextMatchUps = result.matchUps;
20795
20799
  }
@@ -20830,6 +20834,7 @@ function bulkScheduleMatchUps$1({
20830
20834
  schedule: matchUpSchedule,
20831
20835
  matchUpDependencies,
20832
20836
  errorOnAnachronism,
20837
+ removePriorValues,
20833
20838
  inContextMatchUps,
20834
20839
  tournamentRecords,
20835
20840
  tournamentRecord,
@@ -20854,6 +20859,7 @@ function bulkScheduleMatchUps({
20854
20859
  scheduleByeMatchUps = false,
20855
20860
  errorOnAnachronism,
20856
20861
  matchUpContextIds,
20862
+ removePriorValues,
20857
20863
  tournamentRecords,
20858
20864
  checkChronology,
20859
20865
  matchUpDetails,
@@ -20883,6 +20889,7 @@ function bulkScheduleMatchUps({
20883
20889
  scheduleByeMatchUps,
20884
20890
  matchUpDependencies,
20885
20891
  errorOnAnachronism,
20892
+ removePriorValues,
20886
20893
  tournamentRecords,
20887
20894
  tournamentRecord,
20888
20895
  checkChronology,
@@ -32568,13 +32575,16 @@ function processAlreadyScheduledMatchUps({
32568
32575
  minutesMap,
32569
32576
  matchUps
32570
32577
  }) {
32571
- const byeScheduledMatchUpIds = [];
32578
+ const byeScheduledMatchUpDetails = [];
32572
32579
  if (!dateScheduledMatchUpIds) {
32573
32580
  dateScheduledMatchUps = matchUps?.filter((matchUp) => {
32574
32581
  const schedule = matchUp.schedule || {};
32575
32582
  const isByeMatchUp = matchUp.matchUpStatus === BYE;
32576
32583
  if (isByeMatchUp)
32577
- byeScheduledMatchUpIds.push(matchUp.matchUpId);
32584
+ byeScheduledMatchUpDetails.push({
32585
+ tournamentId: matchUp.tournamentId,
32586
+ matchUpId: matchUp.matchUpId
32587
+ });
32578
32588
  return !isByeMatchUp && hasSchedule({ schedule }) && (!scheduleDate || matchUp.schedule.scheduledDate === scheduleDate);
32579
32589
  });
32580
32590
  dateScheduledMatchUpIds = dateScheduledMatchUps.map(getMatchUpId);
@@ -32609,7 +32619,7 @@ function processAlreadyScheduledMatchUps({
32609
32619
  }
32610
32620
  return {
32611
32621
  dateScheduledMatchUpIds,
32612
- byeScheduledMatchUpIds,
32622
+ byeScheduledMatchUpDetails,
32613
32623
  dateScheduledMatchUps,
32614
32624
  clearDate
32615
32625
  };
@@ -32648,10 +32658,10 @@ function getGroupedRounds({
32648
32658
  }
32649
32659
  if (groupedMatchUpIds.length) {
32650
32660
  groupedRounds.push({
32651
- averageMinutes,
32652
- recoveryMinutes,
32661
+ matchUpIds: groupedMatchUpIds,
32653
32662
  roundPeriodLength,
32654
- matchUpIds: groupedMatchUpIds
32663
+ recoveryMinutes,
32664
+ averageMinutes
32655
32665
  });
32656
32666
  }
32657
32667
  return { groupedRounds };
@@ -32867,7 +32877,7 @@ function getVenueSchedulingDetails({
32867
32877
  }) {
32868
32878
  const venueScheduledRoundDetails = {};
32869
32879
  const allDateScheduledMatchUpIds = [];
32870
- const allDateScheduledByeMatchUpIds = [];
32880
+ const allDateScheduledByeMatchUpDetails = [];
32871
32881
  const allDateMatchUpIds = [];
32872
32882
  for (const venue of venues) {
32873
32883
  const { rounds = [], venueId } = venue;
@@ -32918,9 +32928,9 @@ function getVenueSchedulingDetails({
32918
32928
  matchUps
32919
32929
  });
32920
32930
  ({ dateScheduledMatchUpIds, dateScheduledMatchUps } = processResult);
32921
- const { byeScheduledMatchUpIds, clearDate } = processResult;
32922
- if (byeScheduledMatchUpIds?.length)
32923
- allDateScheduledByeMatchUpIds.push(...byeScheduledMatchUpIds);
32931
+ const { byeScheduledMatchUpDetails, clearDate } = processResult;
32932
+ if (byeScheduledMatchUpDetails?.length)
32933
+ allDateScheduledByeMatchUpDetails.push(...byeScheduledMatchUpDetails);
32924
32934
  const { matchUpsToSchedule, matchUpMap } = getMatchUpsToSchedule({
32925
32935
  matchUpPotentialParticipantIds,
32926
32936
  scheduleCompletedMatchUps,
@@ -32951,7 +32961,7 @@ function getVenueSchedulingDetails({
32951
32961
  }
32952
32962
  }
32953
32963
  return {
32954
- allDateScheduledByeMatchUpIds,
32964
+ allDateScheduledByeMatchUpDetails,
32955
32965
  allDateScheduledMatchUpIds,
32956
32966
  venueScheduledRoundDetails,
32957
32967
  allDateMatchUpIds
@@ -33119,8 +33129,8 @@ function jinnScheduler({
33119
33129
  matchUpDependencies,
33120
33130
  matchUpDailyLimits,
33121
33131
  clearScheduleDates,
33122
- schedulingProfile,
33123
33132
  tournamentRecords,
33133
+ schedulingProfile,
33124
33134
  personRequests,
33125
33135
  periodLength,
33126
33136
  matchUps,
@@ -33173,7 +33183,11 @@ function jinnScheduler({
33173
33183
  });
33174
33184
  }
33175
33185
  });
33176
- const { venueScheduledRoundDetails, allDateMatchUpIds } = getVenueSchedulingDetails({
33186
+ const {
33187
+ allDateScheduledByeMatchUpDetails,
33188
+ venueScheduledRoundDetails,
33189
+ allDateMatchUpIds
33190
+ } = getVenueSchedulingDetails({
33177
33191
  matchUpPotentialParticipantIds,
33178
33192
  individualParticipantProfiles,
33179
33193
  scheduleCompletedMatchUps,
@@ -33367,6 +33381,21 @@ function jinnScheduler({
33367
33381
  (a, b) => timeStringMinutes(a.scheduleTime) - timeStringMinutes(b.scheduleTime)
33368
33382
  );
33369
33383
  }
33384
+ if (!dryRun && allDateScheduledByeMatchUpDetails?.length) {
33385
+ bulkScheduleMatchUps({
33386
+ matchUpDetails: allDateScheduledByeMatchUpDetails,
33387
+ scheduleByeMatchUps: true,
33388
+ removePriorValues: true,
33389
+ tournamentRecords,
33390
+ schedule: {
33391
+ scheduledDate: "",
33392
+ scheduledTime: "",
33393
+ courtOrder: "",
33394
+ courtId: "",
33395
+ venueId: ""
33396
+ }
33397
+ });
33398
+ }
33370
33399
  for (const venue of dateSchedulingProfile.venues) {
33371
33400
  for (const round of venue.rounds) {
33372
33401
  const matchUpIds = round.matchUps?.map(({ matchUpId }) => matchUpId) || [];
@@ -33417,6 +33446,179 @@ function jinnScheduler({
33417
33446
  };
33418
33447
  }
33419
33448
 
33449
+ function getPersonRequests({
33450
+ tournamentRecords,
33451
+ requestType
33452
+ }) {
33453
+ if (typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length)
33454
+ return { error: MISSING_TOURNAMENT_RECORDS };
33455
+ const personRequests = {};
33456
+ for (const tournamentRecord of Object.values(tournamentRecords)) {
33457
+ const { extension } = findTournamentExtension({
33458
+ name: PERSON_REQUESTS,
33459
+ tournamentRecord
33460
+ });
33461
+ const requestObjects = extension?.value || [];
33462
+ for (const requestObject of requestObjects) {
33463
+ const { personId, requests } = requestObject || {};
33464
+ if (!personRequests[personId])
33465
+ personRequests[personId] = [];
33466
+ for (const request of requests) {
33467
+ if (requestType && request.requestType !== requestType)
33468
+ continue;
33469
+ personRequests[personId].push(request);
33470
+ }
33471
+ }
33472
+ }
33473
+ return { personRequests };
33474
+ }
33475
+ function savePersonRequests({
33476
+ tournamentRecords,
33477
+ personRequests
33478
+ }) {
33479
+ if (!tournamentRecords)
33480
+ return { error: MISSING_TOURNAMENT_RECORDS };
33481
+ if (!personRequests)
33482
+ return { ...SUCCESS };
33483
+ const tournaments = Object.values(tournamentRecords);
33484
+ for (const tournamentRecord of tournaments) {
33485
+ const tournamentParticipants = tournamentRecord.participants ?? [];
33486
+ const relevantPersonRequests = [];
33487
+ for (const personId of Object.keys(personRequests)) {
33488
+ if (findParticipant({ tournamentParticipants, personId })) {
33489
+ const requests = personRequests[personId];
33490
+ if (requests.length)
33491
+ relevantPersonRequests.push({ personId, requests });
33492
+ }
33493
+ }
33494
+ if (Object.keys(relevantPersonRequests).length) {
33495
+ const extension = {
33496
+ name: PERSON_REQUESTS,
33497
+ value: relevantPersonRequests
33498
+ };
33499
+ addTournamentExtension({ tournamentRecord, extension });
33500
+ }
33501
+ }
33502
+ return { ...SUCCESS };
33503
+ }
33504
+ function addPersonRequests({
33505
+ tournamentRecords,
33506
+ personId,
33507
+ requests
33508
+ }) {
33509
+ if (!tournamentRecords)
33510
+ return { error: MISSING_TOURNAMENT_RECORDS };
33511
+ if (typeof personId !== "string")
33512
+ return { error: INVALID_VALUES };
33513
+ if (!Array.isArray(requests))
33514
+ return { error: INVALID_VALUES };
33515
+ const { personRequests } = getPersonRequests({ tournamentRecords });
33516
+ const { mergeCount } = mergePersonRequests({
33517
+ personRequests,
33518
+ personId,
33519
+ requests
33520
+ });
33521
+ if (mergeCount && personRequests) {
33522
+ return savePersonRequests({ tournamentRecords, personRequests });
33523
+ } else {
33524
+ return { error: INVALID_VALUES };
33525
+ }
33526
+ }
33527
+ function mergePersonRequests({ personRequests, personId, requests }) {
33528
+ if (!personRequests[personId])
33529
+ personRequests[personId] = [];
33530
+ const filteredRequests = requests.filter(({ requestType }) => requestType).map((request) => {
33531
+ let { date, startTime, endTime } = request;
33532
+ if (request.requestType === DO_NOT_SCHEDULE) {
33533
+ date = extractDate(date);
33534
+ startTime = extractTime(startTime);
33535
+ endTime = extractTime(endTime);
33536
+ if (date && startTime && endTime) {
33537
+ return { date, startTime, endTime, requestType: request.requestType };
33538
+ }
33539
+ }
33540
+ return request;
33541
+ }).filter(Boolean);
33542
+ for (const request of filteredRequests) {
33543
+ request.requestId = generateTimeCode();
33544
+ personRequests[personId].push(request);
33545
+ }
33546
+ return { mergeCount: filteredRequests.length };
33547
+ }
33548
+ function removePersonRequests({
33549
+ tournamentRecords,
33550
+ requestType,
33551
+ requestId,
33552
+ personId,
33553
+ date
33554
+ }) {
33555
+ if (typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length)
33556
+ return { error: MISSING_TOURNAMENT_RECORDS };
33557
+ const { personRequests } = getPersonRequests({ tournamentRecords });
33558
+ const filterRequests = (personId2) => {
33559
+ if (personRequests) {
33560
+ personRequests[personId2] = personRequests[personId2].filter((request) => {
33561
+ return (!requestType || request.requestType !== requestType) && (!requestId || request.requestId !== requestId) && (!date || request.date !== date);
33562
+ });
33563
+ if (!personRequests?.[personId2]?.length)
33564
+ delete personRequests[personId2];
33565
+ }
33566
+ };
33567
+ const removeAll = !requestType && !requestId && !personId && !date;
33568
+ if (!removeAll) {
33569
+ if (personId && personRequests?.[personId]) {
33570
+ filterRequests(personId);
33571
+ } else if (personRequests) {
33572
+ for (const personId2 of Object.keys(personRequests)) {
33573
+ filterRequests(personId2);
33574
+ }
33575
+ }
33576
+ }
33577
+ if (removeAll || !personRequests || !Object.keys(personRequests).length) {
33578
+ return removeExtension({ tournamentRecords, name: PERSON_REQUESTS });
33579
+ } else {
33580
+ return savePersonRequests({ tournamentRecords, personRequests });
33581
+ }
33582
+ }
33583
+ function modifyPersonRequests({
33584
+ tournamentRecords,
33585
+ requests,
33586
+ personId
33587
+ }) {
33588
+ if (!tournamentRecords)
33589
+ return { error: MISSING_TOURNAMENT_RECORDS };
33590
+ if (!Array.isArray(requests))
33591
+ return { error: INVALID_VALUES };
33592
+ const requestIds = requests.map(({ requestId }) => requestId).filter(Boolean);
33593
+ const { personRequests } = getPersonRequests({ tournamentRecords });
33594
+ const modifyRequests = (personId2) => {
33595
+ if (personRequests) {
33596
+ personRequests[personId2] = personRequests[personId2].map((request) => {
33597
+ if (!requestIds.includes(request.requestId))
33598
+ return request;
33599
+ const modification = requests.find(
33600
+ (updatedRequest) => updatedRequest.requestId === request.requestId
33601
+ );
33602
+ if (!modification.requestType)
33603
+ return;
33604
+ return Object.assign(request, modification);
33605
+ }).filter(Boolean);
33606
+ }
33607
+ };
33608
+ if (personId && personRequests?.[personId]) {
33609
+ modifyRequests(personId);
33610
+ } else if (personRequests) {
33611
+ for (const personId2 of Object.keys(personRequests)) {
33612
+ modifyRequests(personId2);
33613
+ }
33614
+ }
33615
+ const newRequests = requests.filter((request) => !request.requestId);
33616
+ if (newRequests.length) {
33617
+ mergePersonRequests({ personRequests, personId, requests: newRequests });
33618
+ }
33619
+ return savePersonRequests({ tournamentRecords, personRequests });
33620
+ }
33621
+
33420
33622
  function getEarliestCourtTime({
33421
33623
  averageMinutes,
33422
33624
  startTime,
@@ -33464,7 +33666,7 @@ function getEarliestCourtTime({
33464
33666
  return { earliestCourtTime, courtStartTime, courtEndTime };
33465
33667
  }
33466
33668
 
33467
- function proScheduler({
33669
+ function v2Scheduler({
33468
33670
  schedulingProfileModifications,
33469
33671
  checkPotentialRequestConflicts,
33470
33672
  scheduleCompletedMatchUps,
@@ -33479,7 +33681,7 @@ function proScheduler({
33479
33681
  periodLength = 30,
33480
33682
  schedulingProfile,
33481
33683
  personRequests,
33482
- matchUps,
33684
+ matchUps = [],
33483
33685
  courts,
33484
33686
  dryRun
33485
33687
  }) {
@@ -33492,7 +33694,7 @@ function proScheduler({
33492
33694
  const overLimitMatchUpIds = {};
33493
33695
  const noTimeMatchUpIds = {};
33494
33696
  const requestConflicts = {};
33495
- for (const dateSchedulingProfile of dateSchedulingProfiles) {
33697
+ for (const dateSchedulingProfile of dateSchedulingProfiles ?? []) {
33496
33698
  const scheduleDate = extractDate(dateSchedulingProfile?.scheduleDate);
33497
33699
  const venues = dateSchedulingProfile?.venues || [];
33498
33700
  const matchUpPotentialParticipantIds = {};
@@ -33517,7 +33719,7 @@ function proScheduler({
33517
33719
  noTimeMatchUpIds[scheduleDate] = [];
33518
33720
  requestConflicts[scheduleDate] = [];
33519
33721
  const matchUpNotBeforeTimes = {};
33520
- matchUps.forEach((matchUp) => {
33722
+ matchUps?.forEach((matchUp) => {
33521
33723
  if (matchUp.schedule?.scheduledDate && sameDay(scheduleDate, extractDate(matchUp.schedule.scheduledDate))) {
33522
33724
  processNextMatchUps({
33523
33725
  matchUpPotentialParticipantIds,
@@ -33527,7 +33729,7 @@ function proScheduler({
33527
33729
  }
33528
33730
  });
33529
33731
  const {
33530
- allDateScheduledByeMatchUpIds,
33732
+ allDateScheduledByeMatchUpDetails,
33531
33733
  allDateScheduledMatchUpIds,
33532
33734
  venueScheduledRoundDetails,
33533
33735
  allDateMatchUpIds
@@ -33547,7 +33749,7 @@ function proScheduler({
33547
33749
  courts,
33548
33750
  venues
33549
33751
  });
33550
- const dateScheduledMatchUps = matchUps.filter(
33752
+ const dateScheduledMatchUps = matchUps?.filter(
33551
33753
  ({ matchUpId }) => allDateScheduledMatchUpIds.includes(matchUpId)
33552
33754
  );
33553
33755
  const { bookings } = generateBookings({
@@ -33809,7 +34011,21 @@ function proScheduler({
33809
34011
  getMatchUpId
33810
34012
  );
33811
34013
  }
33812
- if (!dryRun && allDateScheduledByeMatchUpIds?.length) ;
34014
+ if (!dryRun && allDateScheduledByeMatchUpDetails?.length) {
34015
+ bulkScheduleMatchUps({
34016
+ matchUpDetails: allDateScheduledByeMatchUpDetails,
34017
+ scheduleByeMatchUps: true,
34018
+ removePriorValues: true,
34019
+ tournamentRecords,
34020
+ schedule: {
34021
+ scheduledDate: "",
34022
+ scheduledTime: "",
34023
+ courtOrder: "",
34024
+ courtId: "",
34025
+ venueId: ""
34026
+ }
34027
+ });
34028
+ }
33813
34029
  for (const venue of dateSchedulingProfile.venues) {
33814
34030
  for (const round of venue.rounds) {
33815
34031
  const matchUpIds = (round.matchUps ?? []).map(
@@ -33831,7 +34047,7 @@ function proScheduler({
33831
34047
  }
33832
34048
  }
33833
34049
  }
33834
- const scheduledDates = dateSchedulingProfiles.map(
34050
+ const scheduledDates = (dateSchedulingProfiles ?? []).map(
33835
34051
  ({ scheduleDate }) => scheduleDate
33836
34052
  );
33837
34053
  const autoSchedulingAudit = {
@@ -33860,179 +34076,6 @@ function proScheduler({
33860
34076
  };
33861
34077
  }
33862
34078
 
33863
- function getPersonRequests({
33864
- tournamentRecords,
33865
- requestType
33866
- }) {
33867
- if (typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length)
33868
- return { error: MISSING_TOURNAMENT_RECORDS };
33869
- const personRequests = {};
33870
- for (const tournamentRecord of Object.values(tournamentRecords)) {
33871
- const { extension } = findTournamentExtension({
33872
- name: PERSON_REQUESTS,
33873
- tournamentRecord
33874
- });
33875
- const requestObjects = extension?.value || [];
33876
- for (const requestObject of requestObjects) {
33877
- const { personId, requests } = requestObject || {};
33878
- if (!personRequests[personId])
33879
- personRequests[personId] = [];
33880
- for (const request of requests) {
33881
- if (requestType && request.requestType !== requestType)
33882
- continue;
33883
- personRequests[personId].push(request);
33884
- }
33885
- }
33886
- }
33887
- return { personRequests };
33888
- }
33889
- function savePersonRequests({
33890
- tournamentRecords,
33891
- personRequests
33892
- }) {
33893
- if (!tournamentRecords)
33894
- return { error: MISSING_TOURNAMENT_RECORDS };
33895
- if (!personRequests)
33896
- return { ...SUCCESS };
33897
- const tournaments = Object.values(tournamentRecords);
33898
- for (const tournamentRecord of tournaments) {
33899
- const tournamentParticipants = tournamentRecord.participants ?? [];
33900
- const relevantPersonRequests = [];
33901
- for (const personId of Object.keys(personRequests)) {
33902
- if (findParticipant({ tournamentParticipants, personId })) {
33903
- const requests = personRequests[personId];
33904
- if (requests.length)
33905
- relevantPersonRequests.push({ personId, requests });
33906
- }
33907
- }
33908
- if (Object.keys(relevantPersonRequests).length) {
33909
- const extension = {
33910
- name: PERSON_REQUESTS,
33911
- value: relevantPersonRequests
33912
- };
33913
- addTournamentExtension({ tournamentRecord, extension });
33914
- }
33915
- }
33916
- return { ...SUCCESS };
33917
- }
33918
- function addPersonRequests({
33919
- tournamentRecords,
33920
- personId,
33921
- requests
33922
- }) {
33923
- if (!tournamentRecords)
33924
- return { error: MISSING_TOURNAMENT_RECORDS };
33925
- if (typeof personId !== "string")
33926
- return { error: INVALID_VALUES };
33927
- if (!Array.isArray(requests))
33928
- return { error: INVALID_VALUES };
33929
- const { personRequests } = getPersonRequests({ tournamentRecords });
33930
- const { mergeCount } = mergePersonRequests({
33931
- personRequests,
33932
- personId,
33933
- requests
33934
- });
33935
- if (mergeCount && personRequests) {
33936
- return savePersonRequests({ tournamentRecords, personRequests });
33937
- } else {
33938
- return { error: INVALID_VALUES };
33939
- }
33940
- }
33941
- function mergePersonRequests({ personRequests, personId, requests }) {
33942
- if (!personRequests[personId])
33943
- personRequests[personId] = [];
33944
- const filteredRequests = requests.filter(({ requestType }) => requestType).map((request) => {
33945
- let { date, startTime, endTime } = request;
33946
- if (request.requestType === DO_NOT_SCHEDULE) {
33947
- date = extractDate(date);
33948
- startTime = extractTime(startTime);
33949
- endTime = extractTime(endTime);
33950
- if (date && startTime && endTime) {
33951
- return { date, startTime, endTime, requestType: request.requestType };
33952
- }
33953
- }
33954
- return request;
33955
- }).filter(Boolean);
33956
- for (const request of filteredRequests) {
33957
- request.requestId = generateTimeCode();
33958
- personRequests[personId].push(request);
33959
- }
33960
- return { mergeCount: filteredRequests.length };
33961
- }
33962
- function removePersonRequests({
33963
- tournamentRecords,
33964
- requestType,
33965
- requestId,
33966
- personId,
33967
- date
33968
- }) {
33969
- if (typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length)
33970
- return { error: MISSING_TOURNAMENT_RECORDS };
33971
- const { personRequests } = getPersonRequests({ tournamentRecords });
33972
- const filterRequests = (personId2) => {
33973
- if (personRequests) {
33974
- personRequests[personId2] = personRequests[personId2].filter((request) => {
33975
- return (!requestType || request.requestType !== requestType) && (!requestId || request.requestId !== requestId) && (!date || request.date !== date);
33976
- });
33977
- if (!personRequests?.[personId2]?.length)
33978
- delete personRequests[personId2];
33979
- }
33980
- };
33981
- const removeAll = !requestType && !requestId && !personId && !date;
33982
- if (!removeAll) {
33983
- if (personId && personRequests?.[personId]) {
33984
- filterRequests(personId);
33985
- } else if (personRequests) {
33986
- for (const personId2 of Object.keys(personRequests)) {
33987
- filterRequests(personId2);
33988
- }
33989
- }
33990
- }
33991
- if (removeAll || !personRequests || !Object.keys(personRequests).length) {
33992
- return removeExtension({ tournamentRecords, name: PERSON_REQUESTS });
33993
- } else {
33994
- return savePersonRequests({ tournamentRecords, personRequests });
33995
- }
33996
- }
33997
- function modifyPersonRequests({
33998
- tournamentRecords,
33999
- requests,
34000
- personId
34001
- }) {
34002
- if (!tournamentRecords)
34003
- return { error: MISSING_TOURNAMENT_RECORDS };
34004
- if (!Array.isArray(requests))
34005
- return { error: INVALID_VALUES };
34006
- const requestIds = requests.map(({ requestId }) => requestId).filter(Boolean);
34007
- const { personRequests } = getPersonRequests({ tournamentRecords });
34008
- const modifyRequests = (personId2) => {
34009
- if (personRequests) {
34010
- personRequests[personId2] = personRequests[personId2].map((request) => {
34011
- if (!requestIds.includes(request.requestId))
34012
- return request;
34013
- const modification = requests.find(
34014
- (updatedRequest) => updatedRequest.requestId === request.requestId
34015
- );
34016
- if (!modification.requestType)
34017
- return;
34018
- return Object.assign(request, modification);
34019
- }).filter(Boolean);
34020
- }
34021
- };
34022
- if (personId && personRequests?.[personId]) {
34023
- modifyRequests(personId);
34024
- } else if (personRequests) {
34025
- for (const personId2 of Object.keys(personRequests)) {
34026
- modifyRequests(personId2);
34027
- }
34028
- }
34029
- const newRequests = requests.filter((request) => !request.requestId);
34030
- if (newRequests.length) {
34031
- mergePersonRequests({ personRequests, personId, requests: newRequests });
34032
- }
34033
- return savePersonRequests({ tournamentRecords, personRequests });
34034
- }
34035
-
34036
34079
  function clearScheduledMatchUps$1({
34037
34080
  scheduleAttributes = ["scheduledDate", "scheduledTime"],
34038
34081
  ignoreMatchUpStatuses = completedMatchUpStatuses,
@@ -34144,6 +34187,7 @@ function scheduleProfileRounds({
34144
34187
  scheduleDates = [],
34145
34188
  tournamentRecords,
34146
34189
  periodLength,
34190
+ useGarman,
34147
34191
  dryRun,
34148
34192
  pro
34149
34193
  }) {
@@ -34155,9 +34199,9 @@ function scheduleProfileRounds({
34155
34199
  if (result.error)
34156
34200
  return result;
34157
34201
  const {
34158
- schedulingProfile = [],
34202
+ modifications: schedulingProfileModifications,
34159
34203
  issues: schedulingProfileIssues = [],
34160
- modifications: schedulingProfileModifications
34204
+ schedulingProfile = []
34161
34205
  } = result;
34162
34206
  const containedStructureIds = Object.assign(
34163
34207
  {},
@@ -34182,10 +34226,10 @@ function scheduleProfileRounds({
34182
34226
  const scheduledDates = Array.isArray(clearScheduleDates) ? clearScheduleDates : [];
34183
34227
  clearScheduledMatchUps({ tournamentRecords, scheduledDates });
34184
34228
  }
34185
- const { courts } = getVenuesAndCourts({
34229
+ const courts = getVenuesAndCourts({
34186
34230
  ignoreDisabled: false,
34187
34231
  tournamentRecords
34188
- });
34232
+ }).courts;
34189
34233
  const { matchUps } = allCompetitionMatchUps({
34190
34234
  matchUpFilters: { matchUpTypes: [SINGLES$1, DOUBLES$1] },
34191
34235
  afterRecoveryTimes: true,
@@ -34222,12 +34266,13 @@ function scheduleProfileRounds({
34222
34266
  schedulingProfile,
34223
34267
  personRequests,
34224
34268
  periodLength,
34269
+ useGarman,
34225
34270
  matchUps,
34226
34271
  dryRun,
34227
34272
  courts
34228
34273
  };
34229
34274
  if (pro) {
34230
- return proScheduler(params);
34275
+ return v2Scheduler(params);
34231
34276
  } else {
34232
34277
  return jinnScheduler(params);
34233
34278
  }
@@ -37413,7 +37458,7 @@ function deleteVenue$1({
37413
37458
  const appliedPolicies = getAppliedPolicies({
37414
37459
  tournamentRecord
37415
37460
  })?.appliedPolicies;
37416
- const allowModificationWhenMatchUpsScheduled = force || appliedPolicies?.[POLICY_TYPE_SCHEDULING]?.allowDeletionWithScoresPresent?.venues;
37461
+ const allowModificationWhenMatchUpsScheduled = force ?? appliedPolicies?.[POLICY_TYPE_SCHEDULING]?.allowDeletionWithScoresPresent?.venues;
37417
37462
  if (!matchUpsToUnschedule.length || allowModificationWhenMatchUpsScheduled) {
37418
37463
  for (const matchUp of matchUpsToUnschedule) {
37419
37464
  const result = removeCourtAssignment({
@@ -37641,7 +37686,7 @@ function deleteCourt$1({
37641
37686
  const appliedPolicies = getAppliedPolicies({
37642
37687
  tournamentRecord
37643
37688
  })?.appliedPolicies;
37644
- const allowModificationWhenMatchUpsScheduled = force || appliedPolicies?.[POLICY_TYPE_SCHEDULING]?.allowDeletionWithScoresPresent?.courts;
37689
+ const allowModificationWhenMatchUpsScheduled = force ?? appliedPolicies?.[POLICY_TYPE_SCHEDULING]?.allowDeletionWithScoresPresent?.courts;
37645
37690
  if (!matchUps?.length || allowModificationWhenMatchUpsScheduled) {
37646
37691
  for (const matchUp of matchUps ?? []) {
37647
37692
  const result2 = removeCourtAssignment({
@@ -37839,8 +37884,16 @@ function modifyCourtAvailability({
37839
37884
  const appliedPolicies = getAppliedPolicies({
37840
37885
  tournamentRecord
37841
37886
  })?.appliedPolicies;
37842
- force || appliedPolicies?.[POLICY_TYPE_SCHEDULING]?.allowDeletionWithScoresPresent?.courts;
37843
- console.log("scheduled court matchUps", courtMatchUps.length);
37887
+ const allowModificationWhenMatchUpsScheduled = force ?? appliedPolicies?.[POLICY_TYPE_SCHEDULING]?.allowDeletionWithScoresPresent?.courts;
37888
+ const matchUpsWithInvalidScheduling = [];
37889
+ if (matchUpsWithInvalidScheduling.length) {
37890
+ if (allowModificationWhenMatchUpsScheduled) ; else {
37891
+ console.log(
37892
+ "throw error: scheduled court matchUps",
37893
+ matchUpsWithInvalidScheduling.length
37894
+ );
37895
+ }
37896
+ }
37844
37897
  }
37845
37898
  if (court) {
37846
37899
  court.dateAvailability = dateAvailability;
@@ -38179,7 +38232,7 @@ function modifyVenue$1({
38179
38232
  const appliedPolicies = getAppliedPolicies({
38180
38233
  tournamentRecord
38181
38234
  })?.appliedPolicies;
38182
- const allowModificationWhenMatchUpsScheduled = force || appliedPolicies?.[POLICY_TYPE_SCHEDULING]?.allowDeletionWithScoresPresent?.venues;
38235
+ const allowModificationWhenMatchUpsScheduled = force ?? appliedPolicies?.[POLICY_TYPE_SCHEDULING]?.allowDeletionWithScoresPresent?.venues;
38183
38236
  const { matchUps: venueMatchUps } = getScheduledVenueMatchUps({
38184
38237
  tournamentRecord,
38185
38238
  venueId
@@ -38210,6 +38263,7 @@ function modifyVenue$1({
38210
38263
  const courtIdsToDelete = existingCourtIds.filter(
38211
38264
  (courtId) => !courtIdsToModify.includes(courtId)
38212
38265
  );
38266
+ const matchUpsWithCourtId = [];
38213
38267
  if (courtIdsToDelete.length) {
38214
38268
  const courtsToDelete = venue?.courts?.filter(
38215
38269
  (court) => courtIdsToDelete.includes(court.courtId)
@@ -38220,12 +38274,24 @@ function modifyVenue$1({
38220
38274
  tournamentRecord,
38221
38275
  venueMatchUps
38222
38276
  });
38277
+ for (const matchUp of result2.matchUps ?? []) {
38278
+ matchUpsWithCourtId.push({
38279
+ matchUpId: matchUp.matchUpId,
38280
+ drawId: matchUp.drawId
38281
+ });
38282
+ }
38223
38283
  return result2.matchUps?.length ?? 0;
38224
38284
  }).reduce((a, b) => a + b);
38225
38285
  if (venue && (!scheduleDeletionsCount || allowModificationWhenMatchUpsScheduled)) {
38226
38286
  venue.courts = venue.courts?.filter(
38227
38287
  (court) => courtIdsToModify.includes(court.courtId)
38228
38288
  );
38289
+ bulkScheduleMatchUps$1({
38290
+ schedule: { courtId: "", scheduledDate: "" },
38291
+ matchUpDetails: matchUpsWithCourtId,
38292
+ removePriorValues: true,
38293
+ tournamentRecord
38294
+ });
38229
38295
  } else {
38230
38296
  return deletionMessage({
38231
38297
  matchUpsCount: scheduleDeletionsCount
@@ -41254,7 +41320,10 @@ function generateDrawTypeAndModifyDrawDefinition$1(params) {
41254
41320
  });
41255
41321
  }
41256
41322
  const { inContextDrawMatchUps } = addGoesTo({ drawDefinition, matchUpsMap });
41257
- modifyDrawNotice({ drawDefinition });
41323
+ modifyDrawNotice({
41324
+ tournamentId: params.tournamentRecord?.tournamentId,
41325
+ drawDefinition
41326
+ });
41258
41327
  return {
41259
41328
  inContextDrawMatchUps,
41260
41329
  drawDefinition,
@@ -44591,7 +44660,6 @@ function removeStructure({
44591
44660
  }
44592
44661
  const structureIds = structures.map(extractAttributes("structureId"));
44593
44662
  const removedMatchUpIds = [];
44594
- const idsToRemove = [structureId];
44595
44663
  const getTargetedStructureIds = (structureId2) => drawDefinition.links?.map(
44596
44664
  (link) => link.source.structureId === structureId2 && link.target.structureId !== mainStageSequence1?.structureId && link.target.structureId
44597
44665
  ).filter(Boolean) ?? [];
@@ -44606,7 +44674,8 @@ function removeStructure({
44606
44674
  isQualifyingStructure ? getQualifyingSourceStructureIds(id) : getTargetedStructureIds(id)
44607
44675
  )
44608
44676
  );
44609
- while (idsToRemove.length) {
44677
+ const idsToRemove = isMainStageSequence1 ? relatedStructureIdsMap.get(structureId) : [structureId];
44678
+ while (idsToRemove?.length) {
44610
44679
  const idBeingRemoved = idsToRemove.pop();
44611
44680
  const { structure: structure2 } = findStructure({
44612
44681
  structureId: idBeingRemoved,
@@ -44627,8 +44696,7 @@ function removeStructure({
44627
44696
  }
44628
44697
  );
44629
44698
  }
44630
- const targetedStructureIds = idBeingRemoved && // targetedStructureIdsMap[idBeingRemoved].filter(
44631
- relatedStructureIdsMap.get(idBeingRemoved)?.filter(
44699
+ const targetedStructureIds = idBeingRemoved && relatedStructureIdsMap.get(idBeingRemoved)?.filter(
44632
44700
  (id) => (
44633
44701
  // IMPORTANT: only delete MAIN stageSequence: 1 if specified to protect against DOUBLE_ELIMINATION scenario
44634
44702
  id !== mainStageSequence1?.structureId || structureId === mainStageSequence1.structureId
@@ -44647,6 +44715,8 @@ function removeStructure({
44647
44715
  }
44648
44716
  });
44649
44717
  if (isMainStageSequence1) {
44718
+ const mainStageSequence1MatchUpIds = (mainStageSequence1.matchUps ?? [])?.map(extractAttributes("matchUpId"));
44719
+ removedMatchUpIds.push(...mainStageSequence1MatchUpIds);
44650
44720
  mainStageSequence1.positionAssignments = [];
44651
44721
  mainStageSequence1.seedAssignments = [];
44652
44722
  mainStageSequence1.matchUps = [];
@@ -64854,6 +64924,7 @@ function modifyTournamentRecord(params) {
64854
64924
  schedulingProfile,
64855
64925
  tournamentRecord,
64856
64926
  eventProfiles,
64927
+ periodLength,
64857
64928
  venueProfiles,
64858
64929
  autoSchedule,
64859
64930
  drawProfiles,
@@ -65029,7 +65100,10 @@ function modifyTournamentRecord(params) {
65029
65100
  if (autoSchedule) {
65030
65101
  const { tournamentId } = tournamentRecord;
65031
65102
  const tournamentRecords2 = { [tournamentId]: tournamentRecord };
65032
- schedulerResult = scheduleProfileRounds({ tournamentRecords: tournamentRecords2 });
65103
+ schedulerResult = scheduleProfileRounds({
65104
+ tournamentRecords: tournamentRecords2,
65105
+ periodLength
65106
+ });
65033
65107
  }
65034
65108
  }
65035
65109
  const totalParticipantsCount = tournamentRecord.participants.length;
@@ -65133,6 +65207,7 @@ function generateTournamentRecord(params) {
65133
65207
  randomWinningSide,
65134
65208
  policyDefinitions,
65135
65209
  schedulingProfile,
65210
+ periodLength,
65136
65211
  autoSchedule,
65137
65212
  eventProfiles,
65138
65213
  venueProfiles,
@@ -65273,7 +65348,8 @@ function generateTournamentRecord(params) {
65273
65348
  const tournamentRecords = { [tournamentId]: tournamentRecord };
65274
65349
  schedulerResult = scheduleProfileRounds({
65275
65350
  scheduleCompletedMatchUps,
65276
- tournamentRecords
65351
+ tournamentRecords,
65352
+ periodLength
65277
65353
  });
65278
65354
  }
65279
65355
  }