tods-competition-factory 2.1.14 → 2.1.15

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.1.14';
6
+ return '2.1.15';
7
7
  }
8
8
 
9
9
  const SINGLES_MATCHUP = 'SINGLES';
@@ -9652,11 +9652,14 @@ function getCourtInfo({ tournamentRecord, internalUse, courtId }) {
9652
9652
  return { ...SUCCESS, courtInfo: makeDeepCopy(courtInfo, false, internalUse) };
9653
9653
  }
9654
9654
 
9655
- function getVenueData({ tournamentRecord, venueId }) {
9656
- if (!tournamentRecord)
9657
- return { error: MISSING_TOURNAMENT_RECORD };
9658
- if (!venueId)
9659
- return { error: MISSING_VENUE_ID };
9655
+ function getVenueData(params) {
9656
+ const paramsCheck = checkRequiredParameters(params, [
9657
+ { [TOURNAMENT_RECORD]: true },
9658
+ { venueId: true, [ERROR]: MISSING_VENUE_ID },
9659
+ ]);
9660
+ if (paramsCheck.error)
9661
+ return paramsCheck;
9662
+ const { tournamentRecord, venueId } = params;
9660
9663
  const result = findVenue({ tournamentRecord, venueId });
9661
9664
  if (result.error)
9662
9665
  return result;
@@ -35023,13 +35026,12 @@ function getEventData(params) {
35023
35026
  })
35024
35027
  .filter((drawData) => drawData.structures?.length)
35025
35028
  : undefined;
35026
- const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
35027
- const venues = tournamentRecord.venues || [];
35029
+ const venues = Array.isArray(tournamentRecord.venues) ? tournamentRecord.venues : [];
35028
35030
  const venuesData = venues.map((venue) => (({ venueData }) => ({
35029
35031
  ...venueData,
35030
35032
  }))(getVenueData({
35031
- tournamentRecord,
35032
35033
  venueId: venue.venueId,
35034
+ tournamentRecord,
35033
35035
  })));
35034
35036
  const eventInfo = (({ eventId, eventName, eventType, eventLevel, surfaceCategory, matchUpFormat, category, gender, startDate, endDate, ballType, discipline, }) => ({
35035
35037
  eventId,
@@ -35049,6 +35051,7 @@ function getEventData(params) {
35049
35051
  element: event,
35050
35052
  name: DISPLAY,
35051
35053
  }).extension?.value;
35054
+ const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
35052
35055
  const eventData = {
35053
35056
  tournamentInfo,
35054
35057
  venuesData,
@@ -35073,6 +35076,87 @@ var query$5 = {
35073
35076
  getVenueData: getVenueData
35074
35077
  };
35075
35078
 
35079
+ function processNextMatchUps({ matchUpPotentialParticipantIds, matchUpNotBeforeTimes, timeAfterRecovery, matchUp, }) {
35080
+ const { individualParticipantIds } = getIndividualParticipantIds(matchUp);
35081
+ timeAfterRecovery = timeAfterRecovery ?? matchUp.schedule?.timeAfterRecovery;
35082
+ const addPotentialParticipantIds = (targetMatchUpId) => {
35083
+ if (!matchUpPotentialParticipantIds[targetMatchUpId])
35084
+ matchUpPotentialParticipantIds[targetMatchUpId] = [];
35085
+ matchUpPotentialParticipantIds[targetMatchUpId] = unique(matchUpPotentialParticipantIds[targetMatchUpId].concat(...individualParticipantIds));
35086
+ };
35087
+ const updateNotBeforeTime = (matchUpId) => {
35088
+ if (timeAfterRecovery &&
35089
+ (!matchUpNotBeforeTimes[matchUpId] || timeAfterRecovery > matchUpNotBeforeTimes[matchUpId])) {
35090
+ matchUpNotBeforeTimes[matchUpId] = timeAfterRecovery;
35091
+ }
35092
+ };
35093
+ const winnerMatchUpId = matchUp.winnerTo?.matchUpId || matchUp.winnerMatchUpId;
35094
+ if (winnerMatchUpId) {
35095
+ timeAfterRecovery && updateNotBeforeTime(winnerMatchUpId);
35096
+ addPotentialParticipantIds(winnerMatchUpId);
35097
+ }
35098
+ const loserMatchUpId = matchUp.loserTo?.matchUpId || matchUp.loserMatchUpId;
35099
+ if (loserMatchUpId) {
35100
+ timeAfterRecovery && updateNotBeforeTime(loserMatchUpId);
35101
+ addPotentialParticipantIds(loserMatchUpId);
35102
+ }
35103
+ if (matchUp.sidesTo?.length) {
35104
+ matchUp.sidesTo.forEach(({ matchUpId }) => {
35105
+ if (matchUpId) {
35106
+ timeAfterRecovery && updateNotBeforeTime(matchUpId);
35107
+ addPotentialParticipantIds(matchUpId);
35108
+ }
35109
+ });
35110
+ }
35111
+ }
35112
+
35113
+ function getMatchUpsToSchedule(params) {
35114
+ const paramsCheck = checkRequiredParameters(params, [{ [MATCHUPS]: true }]);
35115
+ if (paramsCheck.error)
35116
+ return paramsCheck;
35117
+ const { matchUpPotentialParticipantIds, scheduleCompletedMatchUps, dateScheduledMatchUpIds, matchUpNotBeforeTimes, matchUpScheduleTimes, orderedMatchUpIds, clearDate, matchUps, } = params;
35118
+ const alreadyScheduledMatchUpIds = Object.keys(matchUpScheduleTimes);
35119
+ const matchUpsToSchedule = (orderedMatchUpIds ?? [])
35120
+ .map((matchUpId) => matchUps.find((matchUp) => matchUp.matchUpId === matchUpId))
35121
+ .filter(Boolean)
35122
+ .filter((matchUp) => {
35123
+ const alreadyScheduled = !clearDate &&
35124
+ (dateScheduledMatchUpIds.includes(matchUp.matchUpId) || alreadyScheduledMatchUpIds.includes(matchUp.matchUpId));
35125
+ const doNotSchedule = [
35126
+ BYE,
35127
+ DEFAULTED,
35128
+ COMPLETED$1,
35129
+ ABANDONED$1,
35130
+ RETIRED$1,
35131
+ WALKOVER$2,
35132
+ DOUBLE_WALKOVER,
35133
+ DOUBLE_DEFAULT,
35134
+ ].includes(matchUp?.matchUpStatus);
35135
+ return (scheduleCompletedMatchUps ||
35136
+ (!alreadyScheduled && !matchUp.winningSide && !doNotSchedule));
35137
+ });
35138
+ const matchUpMap = matchUpPotentialParticipantIds && matchUpNotBeforeTimes
35139
+ ? matchUpsToSchedule.reduce((aggregator, matchUp) => {
35140
+ const { drawId, tournamentId } = matchUp;
35141
+ if (!aggregator.matchUpMap[tournamentId])
35142
+ aggregator.matchUpMap[tournamentId] = {};
35143
+ if (!aggregator.matchUpMap[tournamentId][drawId]) {
35144
+ aggregator.matchUpMap[tournamentId][drawId] = [matchUp];
35145
+ }
35146
+ else {
35147
+ aggregator.matchUpMap[tournamentId][drawId].push(matchUp);
35148
+ }
35149
+ processNextMatchUps({
35150
+ matchUpPotentialParticipantIds,
35151
+ matchUpNotBeforeTimes,
35152
+ matchUp,
35153
+ });
35154
+ return aggregator;
35155
+ }, { matchUpMap: {} }).matchUpMap
35156
+ : {};
35157
+ return { matchUpsToSchedule, matchUpMap };
35158
+ }
35159
+
35076
35160
  function findMatchUpFormatTiming({ defaultRecoveryMinutes = 0, defaultAverageMinutes, tournamentRecords, matchUpFormat, categoryName, categoryType, tournamentId, eventType, eventId, }) {
35077
35161
  if (!isValidMatchUpFormat({ matchUpFormat }))
35078
35162
  return { error: UNRECOGNIZED_MATCHUP_FORMAT };
@@ -35100,23 +35184,27 @@ function findMatchUpFormatTiming({ defaultRecoveryMinutes = 0, defaultAverageMin
35100
35184
  };
35101
35185
  }
35102
35186
 
35103
- function getScheduledRoundsDetails({ scheduleCompletedMatchUps, containedStructureIds, tournamentRecords, periodLength = 30, matchUps, rounds, }) {
35187
+ function getScheduledRoundsDetails(params) {
35188
+ const paramsCheck = checkRequiredParameters(params, [
35189
+ { [ANY_OF]: { tournamentRecords: false, tournamentRecord: false } },
35190
+ { rounds: true, [OF_TYPE]: ARRAY },
35191
+ ]);
35192
+ if (paramsCheck.error)
35193
+ return paramsCheck;
35194
+ const { scheduleCompletedMatchUps, periodLength = 30 } = params;
35195
+ const tournamentRecords = params.tournamentRecords ||
35196
+ (params.tournamentRecord && {
35197
+ [params.tournamentRecord.tournamentId]: params.tournamentRecord,
35198
+ }) ||
35199
+ {};
35104
35200
  if (typeof tournamentRecords !== 'object')
35105
35201
  return { error: MISSING_TOURNAMENT_RECORDS };
35106
- if (!Array.isArray(rounds))
35107
- return { error: MISSING_VALUE, info: mustBeAnArray('rounds') };
35108
35202
  const matchUpFormatCohorts = {};
35109
35203
  const orderedMatchUpIds = [];
35110
- rounds.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0));
35111
- containedStructureIds =
35112
- containedStructureIds ??
35113
- Object.assign({}, ...Object.values(tournamentRecords).map((tournamentRecord) => getContainedStructures({ tournamentRecord }).containedStructures));
35114
- if (!matchUps) {
35115
- ({ matchUps } = allCompetitionMatchUps({
35116
- nextMatchUps: true,
35117
- tournamentRecords,
35118
- }));
35119
- }
35204
+ const rounds = params.rounds.toSorted((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0));
35205
+ const containedStructureIds = params.containedStructureIds ??
35206
+ Object.assign({}, ...Object.values(tournamentRecords).map((tournamentRecord) => getContainedStructures({ tournamentRecord }).containedStructures));
35207
+ const matchUps = params.matchUps ?? allCompetitionMatchUps({ nextMatchUps: true, tournamentRecords }).matchUps;
35120
35208
  let greatestAverageMinutes = 0;
35121
35209
  const recoveryMinutesMap = {};
35122
35210
  const averageMinutesMap = {};
@@ -35761,6 +35849,7 @@ var query$4 = {
35761
35849
  __proto__: null,
35762
35850
  courtGridRows: courtGridRows,
35763
35851
  findVenue: findVenue,
35852
+ getMatchUpsToSchedule: getMatchUpsToSchedule,
35764
35853
  getPersonRequests: getPersonRequests,
35765
35854
  getProfileRounds: getProfileRounds,
35766
35855
  getScheduledRoundsDetails: getScheduledRoundsDetails,
@@ -37787,6 +37876,7 @@ var index$f = {
37787
37876
  getMatchUpType: getMatchUpType,
37788
37877
  getMatchUpsMap: getMatchUpsMap,
37789
37878
  getMatchUpsStats: getMatchUpsStats,
37879
+ getMatchUpsToSchedule: getMatchUpsToSchedule,
37790
37880
  getMaxEntryPosition: getMaxEntryPosition,
37791
37881
  getModifiedMatchUpFormatTiming: getModifiedMatchUpFormatTiming,
37792
37882
  getPairedParticipant: getPairedParticipant,
@@ -46187,40 +46277,6 @@ function checkDependenciesScheduled({ matchUpScheduleTimes, matchUpDependencies,
46187
46277
  return { dependenciesScheduled, remainingDependencies };
46188
46278
  }
46189
46279
 
46190
- function processNextMatchUps({ matchUpPotentialParticipantIds, matchUpNotBeforeTimes, timeAfterRecovery, matchUp, }) {
46191
- const { individualParticipantIds } = getIndividualParticipantIds(matchUp);
46192
- timeAfterRecovery = timeAfterRecovery ?? matchUp.schedule?.timeAfterRecovery;
46193
- const addPotentialParticipantIds = (targetMatchUpId) => {
46194
- if (!matchUpPotentialParticipantIds[targetMatchUpId])
46195
- matchUpPotentialParticipantIds[targetMatchUpId] = [];
46196
- matchUpPotentialParticipantIds[targetMatchUpId] = unique(matchUpPotentialParticipantIds[targetMatchUpId].concat(...individualParticipantIds));
46197
- };
46198
- const updateNotBeforeTime = (matchUpId) => {
46199
- if (timeAfterRecovery &&
46200
- (!matchUpNotBeforeTimes[matchUpId] || timeAfterRecovery > matchUpNotBeforeTimes[matchUpId])) {
46201
- matchUpNotBeforeTimes[matchUpId] = timeAfterRecovery;
46202
- }
46203
- };
46204
- const winnerMatchUpId = matchUp.winnerTo?.matchUpId || matchUp.winnerMatchUpId;
46205
- if (winnerMatchUpId) {
46206
- timeAfterRecovery && updateNotBeforeTime(winnerMatchUpId);
46207
- addPotentialParticipantIds(winnerMatchUpId);
46208
- }
46209
- const loserMatchUpId = matchUp.loserTo?.matchUpId || matchUp.loserMatchUpId;
46210
- if (loserMatchUpId) {
46211
- timeAfterRecovery && updateNotBeforeTime(loserMatchUpId);
46212
- addPotentialParticipantIds(loserMatchUpId);
46213
- }
46214
- if (matchUp.sidesTo?.length) {
46215
- matchUp.sidesTo.forEach(({ matchUpId }) => {
46216
- if (matchUpId) {
46217
- timeAfterRecovery && updateNotBeforeTime(matchUpId);
46218
- addPotentialParticipantIds(matchUpId);
46219
- }
46220
- });
46221
- }
46222
- }
46223
-
46224
46280
  function checkParticipantProfileInitialization({ individualParticipantProfiles, participantId }) {
46225
46281
  if (!individualParticipantProfiles[participantId]) {
46226
46282
  individualParticipantProfiles[participantId] = {
@@ -46458,47 +46514,6 @@ function processAlreadyScheduledMatchUps({ matchUpPotentialParticipantIds, indiv
46458
46514
  };
46459
46515
  }
46460
46516
 
46461
- function getMatchUpsToSchedule({ matchUpPotentialParticipantIds, scheduleCompletedMatchUps, dateScheduledMatchUpIds, matchUpNotBeforeTimes, matchUpScheduleTimes, orderedMatchUpIds, clearDate, matchUps, }) {
46462
- const alreadyScheduledMatchUpIds = Object.keys(matchUpScheduleTimes);
46463
- const matchUpsToSchedule = orderedMatchUpIds
46464
- .map((matchUpId) => matchUps.find((matchUp) => matchUp.matchUpId === matchUpId))
46465
- .filter(Boolean)
46466
- .filter((matchUp) => {
46467
- const alreadyScheduled = !clearDate &&
46468
- (dateScheduledMatchUpIds.includes(matchUp.matchUpId) || alreadyScheduledMatchUpIds.includes(matchUp.matchUpId));
46469
- const doNotSchedule = [
46470
- BYE,
46471
- DEFAULTED,
46472
- COMPLETED$1,
46473
- ABANDONED$1,
46474
- RETIRED$1,
46475
- WALKOVER$2,
46476
- DOUBLE_WALKOVER,
46477
- DOUBLE_DEFAULT,
46478
- ].includes(matchUp?.matchUpStatus);
46479
- return (scheduleCompletedMatchUps ||
46480
- (!alreadyScheduled && !matchUp.winningSide && !doNotSchedule));
46481
- });
46482
- const { matchUpMap } = matchUpsToSchedule.reduce((aggregator, matchUp) => {
46483
- const { drawId, tournamentId } = matchUp;
46484
- if (!aggregator.matchUpMap[tournamentId])
46485
- aggregator.matchUpMap[tournamentId] = {};
46486
- if (!aggregator.matchUpMap[tournamentId][drawId]) {
46487
- aggregator.matchUpMap[tournamentId][drawId] = [matchUp];
46488
- }
46489
- else {
46490
- aggregator.matchUpMap[tournamentId][drawId].push(matchUp);
46491
- }
46492
- processNextMatchUps({
46493
- matchUpPotentialParticipantIds,
46494
- matchUpNotBeforeTimes,
46495
- matchUp,
46496
- });
46497
- return aggregator;
46498
- }, { matchUpMap: {} });
46499
- return { matchUpsToSchedule, matchUpMap };
46500
- }
46501
-
46502
46517
  function generateBookings({ defaultRecoveryMinutes = 0, averageMatchUpMinutes = 90, dateScheduledMatchUps, tournamentRecords, venueIds = [], periodLength, scheduleDate, matchUps, }) {
46503
46518
  if (typeof tournamentRecords !== 'object')
46504
46519
  return { error: MISSING_TOURNAMENT_RECORDS };
@@ -46793,6 +46808,41 @@ function checkRecoveryTime({ individualParticipantProfiles, matchUpNotBeforeTime
46793
46808
  return { enoughTime };
46794
46809
  }
46795
46810
 
46811
+ function auditAutoScheduling({ autoSchedulingAudit, tournamentRecords }) {
46812
+ addNotice({ topic: AUDIT, payload: autoSchedulingAudit });
46813
+ const getCount = (obj) => {
46814
+ if (!obj)
46815
+ return 0;
46816
+ const values = Object.values(obj);
46817
+ return values.reduce((count, value) => count + value.length || 0, 0);
46818
+ };
46819
+ const profileRoundsCount = (autoSchedulingAudit?.schedulingProfile || []).reduce((count, dateProfile) => count + dateProfile.venues.reduce((vc, venue) => vc + venue.rounds.length, 0), 0);
46820
+ const itemValue = {
46821
+ scheduledDatesCount: autoSchedulingAudit.scheduledDates?.length,
46822
+ noTimeMatchUpIdsCount: getCount(autoSchedulingAudit?.noTimeMatchUpIds),
46823
+ scheduledMatchUpIdsCount: getCount(autoSchedulingAudit?.scheduledMatchUpIds),
46824
+ overLimitMatchUpIdsCount: getCount(autoSchedulingAudit?.overLimitMatchUpIds),
46825
+ requestConflictsCount: getCount(autoSchedulingAudit?.requestConflicts),
46826
+ profileRoundsCount,
46827
+ };
46828
+ const timeItem = {
46829
+ itemType: AUTO_SCHEDULING_AUDIT,
46830
+ itemValue,
46831
+ };
46832
+ for (const tournamentRecord of Object.values(tournamentRecords)) {
46833
+ const tournamentId = tournamentRecord.tournamentId;
46834
+ if (hasTopic(AUDIT)) {
46835
+ addNotice({
46836
+ payload: { type: AUTO_SCHEDULING_AUDIT, tournamentId, detail: itemValue },
46837
+ topic: AUDIT,
46838
+ });
46839
+ }
46840
+ else {
46841
+ addTournamentTimeItem({ tournamentRecord, timeItem });
46842
+ }
46843
+ }
46844
+ }
46845
+
46796
46846
  function checkDailyLimits({ matchUpPotentialParticipantIds, individualParticipantProfiles, matchUpDailyLimits = {}, matchUp, }) {
46797
46847
  const { enteredIndividualParticipantIds } = getIndividualParticipantIds(matchUp);
46798
46848
  const { matchUpId, matchUpType } = matchUp;
@@ -46946,41 +46996,6 @@ function bulkScheduleMatchUps(params) {
46946
46996
  return warnings.length ? { ...SUCCESS, scheduled, warnings } : { ...SUCCESS, scheduled };
46947
46997
  }
46948
46998
 
46949
- function auditAutoScheduling({ autoSchedulingAudit, tournamentRecords }) {
46950
- addNotice({ topic: AUDIT, payload: autoSchedulingAudit });
46951
- const getCount = (obj) => {
46952
- if (!obj)
46953
- return 0;
46954
- const values = Object.values(obj);
46955
- return values.reduce((count, value) => count + value.length || 0, 0);
46956
- };
46957
- const profileRoundsCount = (autoSchedulingAudit?.schedulingProfile || []).reduce((count, dateProfile) => count + dateProfile.venues.reduce((vc, venue) => vc + venue.rounds.length, 0), 0);
46958
- const itemValue = {
46959
- scheduledDatesCount: autoSchedulingAudit.scheduledDates?.length,
46960
- noTimeMatchUpIdsCount: getCount(autoSchedulingAudit?.noTimeMatchUpIds),
46961
- scheduledMatchUpIdsCount: getCount(autoSchedulingAudit?.scheduledMatchUpIds),
46962
- overLimitMatchUpIdsCount: getCount(autoSchedulingAudit?.overLimitMatchUpIds),
46963
- requestConflictsCount: getCount(autoSchedulingAudit?.requestConflicts),
46964
- profileRoundsCount,
46965
- };
46966
- const timeItem = {
46967
- itemType: AUTO_SCHEDULING_AUDIT,
46968
- itemValue,
46969
- };
46970
- for (const tournamentRecord of Object.values(tournamentRecords)) {
46971
- const tournamentId = tournamentRecord.tournamentId;
46972
- if (hasTopic(AUDIT)) {
46973
- addNotice({
46974
- payload: { type: AUTO_SCHEDULING_AUDIT, tournamentId, detail: itemValue },
46975
- topic: AUDIT,
46976
- });
46977
- }
46978
- else {
46979
- addTournamentTimeItem({ tournamentRecord, timeItem });
46980
- }
46981
- }
46982
- }
46983
-
46984
46999
  function jinnScheduler({ schedulingProfileModifications, checkPotentialRequestConflicts, scheduleCompletedMatchUps, schedulingProfileIssues, dateSchedulingProfiles, containedStructureIds, matchUpDependencies, matchUpDailyLimits, clearScheduleDates, tournamentRecords, schedulingProfile, personRequests, periodLength, matchUps, courts, dryRun, }) {
46985
47000
  const scheduleTimesRemaining = {};
46986
47001
  const skippedScheduleTimes = {};
@@ -54917,6 +54932,7 @@ var index$5 = {
54917
54932
  findVenue: findVenue,
54918
54933
  generateBookings: generateBookings,
54919
54934
  generateVirtualCourts: generateVirtualCourts,
54935
+ getMatchUpsToSchedule: getMatchUpsToSchedule,
54920
54936
  getPersonRequests: getPersonRequests,
54921
54937
  getProfileRounds: getProfileRounds,
54922
54938
  getScheduledRoundsDetails: getScheduledRoundsDetails,
@@ -56627,11 +56643,11 @@ function copyTournamentRecord(params) {
56627
56643
  const tournamentRecord = {
56628
56644
  participants: params.copyParticipants ? params.tournamentRecord.participants?.map(copyParticipant) ?? [] : [],
56629
56645
  parentOrganisation: makeDeepCopy({ ...params.tournamentRecord.parentOrganisation }, false, true),
56646
+ venues: makeDeepCopy(params.tournamentRecord.venues ?? [], false, true),
56630
56647
  extensions: filteredExtensions(params.tournamentRecord.extensions),
56631
56648
  timeItems: filteredTimeItems(params.tournamentRecord.timeItems),
56632
56649
  events: params.tournamentRecord.events?.map(copyEvent) ?? [],
56633
- weekdays: { ...params.tournamentRecord.weekdays },
56634
- venues: { ...params.tournamentRecord.venues },
56650
+ weekdays: [...(params.tournamentRecord.weekdays ?? [])],
56635
56651
  tournamentName: params.tournamentName,
56636
56652
  startDate: params.startDate,
56637
56653
  tournamentId: UUID(),