tods-competition-factory 1.8.45 → 1.9.0

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.
@@ -743,7 +743,7 @@ function getAccessorValue({ element, accessor }) {
743
743
  }
744
744
 
745
745
  function isObject(obj) {
746
- return typeof obj === "object";
746
+ return obj !== null && typeof obj === "object";
747
747
  }
748
748
  const extractAttributes = (accessor) => (element) => !accessor || typeof element !== "object" ? void 0 : Array.isArray(accessor) && accessor.map((a) => ({
749
749
  [a]: getAccessorValue({ element, accessor: a })?.value
@@ -1694,6 +1694,99 @@ function getScheduleTiming({
1694
1694
  return { scheduleTiming };
1695
1695
  }
1696
1696
 
1697
+ function getTimeItem({
1698
+ returnPreviousValues,
1699
+ itemSubTypes,
1700
+ itemType,
1701
+ element
1702
+ }) {
1703
+ if (!element)
1704
+ return { error: MISSING_VALUE, info: ELEMENT_REQUIRED };
1705
+ if (itemSubTypes && !Array.isArray(itemSubTypes))
1706
+ return { error: INVALID_VALUES, context: { itemSubTypes } };
1707
+ if (!Array.isArray(element.timeItems))
1708
+ return { error: MISSING_TIME_ITEMS };
1709
+ const filteredSorted = element.timeItems.filter((timeItem2) => timeItem2?.itemType === itemType).filter(
1710
+ (timeItem2) => !itemSubTypes?.length || itemSubTypes.some(
1711
+ (subType) => timeItem2?.itemSubTypes?.includes(subType)
1712
+ )
1713
+ ).sort((a, b) => {
1714
+ const aDate = new Date(a.createdAt || void 0).getTime();
1715
+ const bDate = new Date(b.createdAt || void 0).getTime();
1716
+ return aDate - bDate;
1717
+ });
1718
+ const timeItem = filteredSorted.pop();
1719
+ if (timeItem) {
1720
+ const result = { timeItem, ...SUCCESS };
1721
+ if (returnPreviousValues)
1722
+ Object.assign(result, { previousItems: filteredSorted });
1723
+ return result;
1724
+ } else {
1725
+ return { info: NOT_FOUND };
1726
+ }
1727
+ }
1728
+ function getEventTimeItem({
1729
+ returnPreviousValues,
1730
+ itemSubTypes,
1731
+ itemType,
1732
+ event
1733
+ }) {
1734
+ if (!event)
1735
+ return { error: MISSING_EVENT };
1736
+ if (!event.timeItems)
1737
+ return { info: NOT_FOUND };
1738
+ const { timeItem, previousItems, info } = getTimeItem({
1739
+ returnPreviousValues,
1740
+ element: event,
1741
+ itemSubTypes,
1742
+ itemType
1743
+ });
1744
+ return timeItem && { timeItem, previousItems } || { info };
1745
+ }
1746
+ function getTournamentTimeItem({
1747
+ returnPreviousValues,
1748
+ tournamentRecord,
1749
+ itemSubTypes,
1750
+ itemType
1751
+ }) {
1752
+ if (!tournamentRecord)
1753
+ return { error: MISSING_TOURNAMENT_RECORD };
1754
+ if (!tournamentRecord.timeItems)
1755
+ return { info: NOT_FOUND };
1756
+ const { timeItem, previousItems, info } = getTimeItem({
1757
+ element: tournamentRecord,
1758
+ returnPreviousValues,
1759
+ itemSubTypes,
1760
+ itemType
1761
+ });
1762
+ return timeItem && { timeItem, previousItems } || { info };
1763
+ }
1764
+
1765
+ const CHECK_IN = "CHECK_IN";
1766
+ const CHECK_OUT = "CHECK_OUT";
1767
+ const ASSIGN_VENUE = "SCHEDULE.ASSIGNMENT.VENUE";
1768
+ const ALLOCATE_COURTS = "SCHEDULE.ALLOCATION.COURTS";
1769
+ const ASSIGN_COURT = "SCHEDULE.ASSIGNMENT.COURT";
1770
+ const COURT_ORDER = "SCHEDULE.COURT.ORDER";
1771
+ const SCHEDULED_DATE = "SCHEDULE.DATE";
1772
+ const SCHEDULED_TIME = "SCHEDULE.TIME.SCHEDULED";
1773
+ const START_TIME = "SCHEDULE.TIME.START";
1774
+ const STOP_TIME = "SCHEDULE.TIME.STOP";
1775
+ const RESUME_TIME = "SCHEDULE.TIME.RESUME";
1776
+ const END_TIME = "SCHEDULE.TIME.END";
1777
+ const TIME_MODIFIERS = "SCHEDULE.TIME.MODIFIERS";
1778
+ const PUBLISH = "PUBLISH";
1779
+ const PUBLIC = "PUBLIC";
1780
+ const STATUS$1 = "STATUS";
1781
+
1782
+ function getEventPublishStatus({ event, status = PUBLIC }) {
1783
+ const itemType = `${PUBLISH}.${STATUS$1}`;
1784
+ return getEventTimeItem({
1785
+ itemType,
1786
+ event
1787
+ })?.timeItem?.itemValue?.[status];
1788
+ }
1789
+
1697
1790
  const SIGN_IN_STATUS = "SIGN_IN_STATUS";
1698
1791
  const INDIVIDUAL = ParticipantTypeEnum.Individual;
1699
1792
  const GROUP = ParticipantTypeEnum.Group;
@@ -3560,74 +3653,6 @@ function addIndividualParticipants({ participantMap, template }) {
3560
3653
  }
3561
3654
  }
3562
3655
 
3563
- function getTimeItem({
3564
- returnPreviousValues,
3565
- itemSubTypes,
3566
- itemType,
3567
- element
3568
- }) {
3569
- if (!element)
3570
- return { error: MISSING_VALUE, info: ELEMENT_REQUIRED };
3571
- if (itemSubTypes && !Array.isArray(itemSubTypes))
3572
- return { error: INVALID_VALUES, context: { itemSubTypes } };
3573
- if (!Array.isArray(element.timeItems))
3574
- return { error: MISSING_TIME_ITEMS };
3575
- const filteredSorted = element.timeItems.filter((timeItem2) => timeItem2?.itemType === itemType).filter(
3576
- (timeItem2) => !itemSubTypes?.length || itemSubTypes.some(
3577
- (subType) => timeItem2?.itemSubTypes?.includes(subType)
3578
- )
3579
- ).sort((a, b) => {
3580
- const aDate = new Date(a.createdAt || void 0).getTime();
3581
- const bDate = new Date(b.createdAt || void 0).getTime();
3582
- return aDate - bDate;
3583
- });
3584
- const timeItem = filteredSorted.pop();
3585
- if (timeItem) {
3586
- const result = { timeItem, ...SUCCESS };
3587
- if (returnPreviousValues)
3588
- Object.assign(result, { previousItems: filteredSorted });
3589
- return result;
3590
- } else {
3591
- return { info: NOT_FOUND };
3592
- }
3593
- }
3594
- function getEventTimeItem({
3595
- returnPreviousValues,
3596
- itemSubTypes,
3597
- itemType,
3598
- event
3599
- }) {
3600
- if (!event)
3601
- return { error: MISSING_EVENT };
3602
- if (!event.timeItems)
3603
- return { info: NOT_FOUND };
3604
- const { timeItem, previousItems, info } = getTimeItem({
3605
- returnPreviousValues,
3606
- element: event,
3607
- itemSubTypes,
3608
- itemType
3609
- });
3610
- return timeItem && { timeItem, previousItems } || { info };
3611
- }
3612
- function getTournamentTimeItem({
3613
- returnPreviousValues,
3614
- tournamentRecord,
3615
- itemSubTypes,
3616
- itemType
3617
- }) {
3618
- if (!tournamentRecord)
3619
- return { error: MISSING_TOURNAMENT_RECORD };
3620
- if (!tournamentRecord.timeItems)
3621
- return { info: NOT_FOUND };
3622
- const { timeItem, previousItems, info } = getTimeItem({
3623
- element: tournamentRecord,
3624
- returnPreviousValues,
3625
- itemSubTypes,
3626
- itemType
3627
- });
3628
- return timeItem && { timeItem, previousItems } || { info };
3629
- }
3630
-
3631
3656
  const SINGLES_MATCHUP = "SINGLES";
3632
3657
  const SINGLES$1 = "SINGLES";
3633
3658
  const DOUBLES_MATCHUP = "DOUBLES";
@@ -5528,23 +5553,6 @@ function getVenueData({ tournamentRecord, venueId }) {
5528
5553
  return { ...SUCCESS, venueData: makeDeepCopy(venueData, false, true) };
5529
5554
  }
5530
5555
 
5531
- const CHECK_IN = "CHECK_IN";
5532
- const CHECK_OUT = "CHECK_OUT";
5533
- const ASSIGN_VENUE = "SCHEDULE.ASSIGNMENT.VENUE";
5534
- const ALLOCATE_COURTS = "SCHEDULE.ALLOCATION.COURTS";
5535
- const ASSIGN_COURT = "SCHEDULE.ASSIGNMENT.COURT";
5536
- const COURT_ORDER = "SCHEDULE.COURT.ORDER";
5537
- const SCHEDULED_DATE = "SCHEDULE.DATE";
5538
- const SCHEDULED_TIME = "SCHEDULE.TIME.SCHEDULED";
5539
- const START_TIME = "SCHEDULE.TIME.START";
5540
- const STOP_TIME = "SCHEDULE.TIME.STOP";
5541
- const RESUME_TIME = "SCHEDULE.TIME.RESUME";
5542
- const END_TIME = "SCHEDULE.TIME.END";
5543
- const TIME_MODIFIERS = "SCHEDULE.TIME.MODIFIERS";
5544
- const PUBLISH = "PUBLISH";
5545
- const PUBLIC = "PUBLIC";
5546
- const STATUS$1 = "STATUS";
5547
-
5548
5556
  function getTimeStamp(item) {
5549
5557
  return !item.createdAt ? 0 : new Date(item.createdAt).getTime();
5550
5558
  }
@@ -5762,8 +5770,10 @@ function getMatchUpScheduleDetails({
5762
5770
  scheduleVisibilityFilters,
5763
5771
  afterRecoveryTimes,
5764
5772
  tournamentRecord,
5773
+ usePublishState,
5765
5774
  scheduleTiming,
5766
5775
  matchUpFormat,
5776
+ publishStatus,
5767
5777
  matchUpType,
5768
5778
  matchUp,
5769
5779
  event
@@ -5880,15 +5890,36 @@ function getMatchUpScheduleDetails({
5880
5890
  });
5881
5891
  } else {
5882
5892
  schedule = definedAttributes({
5883
- time,
5893
+ milliseconds,
5884
5894
  startTime,
5885
5895
  endTime,
5886
- milliseconds
5896
+ time
5887
5897
  });
5888
5898
  }
5889
- const hasCompletedStatus = matchUp.matchUpStatus && completedMatchUpStatuses.includes(matchUp.matchUpStatus);
5890
5899
  const { scheduledDate } = scheduledMatchUpDate({ matchUp });
5891
5900
  const { scheduledTime } = scheduledMatchUpTime({ matchUp });
5901
+ if (usePublishState && publishStatus?.displaySettings?.draws) {
5902
+ const drawSettings = publishStatus.displaySettings.draws;
5903
+ const scheduleDetails = (drawSettings?.[matchUp.drawId] ?? drawSettings?.default)?.scheduleDetails;
5904
+ if (scheduleDetails) {
5905
+ const scheduleAttributes = (scheduleDetails.find(
5906
+ (details) => scheduledDate && details.dates?.includes(scheduledDate)
5907
+ ) ?? scheduleDetails.find((details) => !details.dates?.length))?.attributes;
5908
+ if (scheduleAttributes) {
5909
+ const template = Object.assign(
5910
+ {},
5911
+ ...Object.keys(schedule).map((key) => ({ [key]: true })),
5912
+ // overwrite with publishStatus attributes
5913
+ scheduleAttributes
5914
+ );
5915
+ schedule = attributeFilter({
5916
+ source: schedule,
5917
+ template
5918
+ });
5919
+ }
5920
+ }
5921
+ }
5922
+ const hasCompletedStatus = matchUp.matchUpStatus && completedMatchUpStatuses.includes(matchUp.matchUpStatus);
5892
5923
  const endDate = hasCompletedStatus && (extractDate(endTime) || extractDate(scheduledDate) || extractDate(scheduledTime)) || void 0;
5893
5924
  return { schedule, endDate };
5894
5925
  }
@@ -6970,6 +7001,7 @@ function getAllStructureMatchUps({
6970
7001
  policyDefinitions,
6971
7002
  tournamentRecord,
6972
7003
  seedAssignments,
7004
+ usePublishState,
6973
7005
  contextFilters,
6974
7006
  contextContent,
6975
7007
  matchUpFilters,
@@ -6977,6 +7009,7 @@ function getAllStructureMatchUps({
6977
7009
  scheduleTiming,
6978
7010
  contextProfile,
6979
7011
  drawDefinition,
7012
+ publishStatus,
6980
7013
  context = {},
6981
7014
  exitProfiles,
6982
7015
  matchUpsMap,
@@ -7085,6 +7118,8 @@ function getAllStructureMatchUps({
7085
7118
  roundNamingProfile,
7086
7119
  initialRoundOfPlay,
7087
7120
  appliedPolicies,
7121
+ usePublishState,
7122
+ publishStatus,
7088
7123
  isRoundRobin,
7089
7124
  roundProfile,
7090
7125
  matchUp,
@@ -7154,6 +7189,8 @@ function getAllStructureMatchUps({
7154
7189
  tieDrawPositions,
7155
7190
  appliedPolicies: appliedPolicies2,
7156
7191
  isCollectionBye,
7192
+ usePublishState: usePublishState2,
7193
+ publishStatus: publishStatus2,
7157
7194
  matchUpTieId,
7158
7195
  isRoundRobin: isRoundRobin2,
7159
7196
  roundProfile: roundProfile2,
@@ -7179,8 +7216,10 @@ function getAllStructureMatchUps({
7179
7216
  scheduleVisibilityFilters: scheduleVisibilityFilters2,
7180
7217
  afterRecoveryTimes,
7181
7218
  tournamentRecord,
7219
+ usePublishState: usePublishState2,
7182
7220
  scheduleTiming,
7183
7221
  matchUpFormat,
7222
+ publishStatus: publishStatus2,
7184
7223
  matchUpType,
7185
7224
  matchUp,
7186
7225
  event: event2
@@ -7303,7 +7342,7 @@ function getAllStructureMatchUps({
7303
7342
  Object.assign(matchUpWithContext, makeDeepCopy({ sides }, true, true));
7304
7343
  }
7305
7344
  if (tournamentParticipants && matchUpWithContext.sides) {
7306
- const participantAttributes = policyDefinitions?.[POLICY_TYPE_PARTICIPANT];
7345
+ const participantAttributes = appliedPolicies2?.[POLICY_TYPE_PARTICIPANT];
7307
7346
  const getMappedParticipant = (participantId) => {
7308
7347
  const participant = participantMap?.[participantId]?.participant;
7309
7348
  return participant && attributeFilter({
@@ -7419,6 +7458,8 @@ function getAllStructureMatchUps({
7419
7458
  additionalContext: additionalContext2,
7420
7459
  appliedPolicies: appliedPolicies2,
7421
7460
  isCollectionBye: isCollectionBye2,
7461
+ usePublishState: usePublishState2,
7462
+ publishStatus: publishStatus2,
7422
7463
  matchUpTieId: matchUpTieId2,
7423
7464
  isRoundRobin: isRoundRobin2,
7424
7465
  roundProfile: roundProfile2,
@@ -7456,11 +7497,13 @@ function getStructureMatchUps({
7456
7497
  afterRecoveryTimes,
7457
7498
  policyDefinitions,
7458
7499
  tournamentRecord,
7500
+ usePublishState,
7459
7501
  matchUpFilters,
7460
7502
  contextFilters,
7461
7503
  contextContent,
7462
7504
  participantMap,
7463
7505
  scheduleTiming,
7506
+ publishStatus,
7464
7507
  contextProfile,
7465
7508
  drawDefinition,
7466
7509
  exitProfiles,
@@ -7481,13 +7524,15 @@ function getStructureMatchUps({
7481
7524
  afterRecoveryTimes,
7482
7525
  policyDefinitions,
7483
7526
  tournamentRecord,
7484
- drawDefinition,
7527
+ usePublishState,
7485
7528
  matchUpFilters,
7486
7529
  contextFilters,
7487
- contextProfile,
7488
7530
  contextContent,
7489
7531
  participantMap,
7490
7532
  scheduleTiming,
7533
+ publishStatus,
7534
+ contextProfile,
7535
+ drawDefinition,
7491
7536
  exitProfiles,
7492
7537
  matchUpsMap,
7493
7538
  structure,
@@ -7583,12 +7628,14 @@ function getDrawMatchUps(params) {
7583
7628
  afterRecoveryTimes,
7584
7629
  policyDefinitions,
7585
7630
  tournamentRecord,
7631
+ usePublishState,
7586
7632
  contextFilters,
7587
- contextProfile,
7588
- drawDefinition,
7589
7633
  matchUpFilters,
7590
7634
  scheduleTiming,
7591
7635
  participantMap,
7636
+ publishStatus,
7637
+ contextProfile,
7638
+ drawDefinition,
7592
7639
  nextMatchUps,
7593
7640
  inContext,
7594
7641
  context,
@@ -7643,9 +7690,11 @@ function getDrawMatchUps(params) {
7643
7690
  afterRecoveryTimes,
7644
7691
  policyDefinitions,
7645
7692
  tournamentRecord,
7693
+ usePublishState,
7694
+ contextContent,
7646
7695
  participantMap,
7647
7696
  scheduleTiming,
7648
- contextContent,
7697
+ publishStatus,
7649
7698
  contextProfile,
7650
7699
  drawDefinition,
7651
7700
  exitProfiles,
@@ -7962,9 +8011,10 @@ function tournamentMatchUps(params) {
7962
8011
  useParticipantMap,
7963
8012
  tournamentRecord,
7964
8013
  inContext = true,
8014
+ usePublishState,
7965
8015
  contextFilters,
7966
- contextProfile,
7967
8016
  matchUpFilters,
8017
+ contextProfile,
7968
8018
  nextMatchUps,
7969
8019
  context
7970
8020
  } = params;
@@ -8002,6 +8052,7 @@ function tournamentMatchUps(params) {
8002
8052
  afterRecoveryTimes,
8003
8053
  policyDefinitions,
8004
8054
  tournamentRecord,
8055
+ usePublishState,
8005
8056
  contextFilters,
8006
8057
  contextProfile,
8007
8058
  contextContent,
@@ -8047,9 +8098,10 @@ function eventMatchUps(params) {
8047
8098
  policyDefinitions,
8048
8099
  useParticipantMap,
8049
8100
  tournamentRecord,
8101
+ usePublishState,
8050
8102
  contextFilters,
8051
- contextProfile,
8052
8103
  matchUpFilters,
8104
+ contextProfile,
8053
8105
  nextMatchUps,
8054
8106
  tournamentId,
8055
8107
  inContext,
@@ -8092,6 +8144,7 @@ function eventMatchUps(params) {
8092
8144
  contextProfile,
8093
8145
  event
8094
8146
  });
8147
+ const publishStatus = getEventPublishStatus({ event });
8095
8148
  const drawDefinitions = event.drawDefinitions ?? [];
8096
8149
  const eventResult = drawDefinitions.reduce((results, drawDefinition) => {
8097
8150
  const drawMatchUpsResult = getDrawMatchUps({
@@ -8103,12 +8156,14 @@ function eventMatchUps(params) {
8103
8156
  afterRecoveryTimes,
8104
8157
  policyDefinitions,
8105
8158
  tournamentRecord,
8106
- drawDefinition,
8159
+ usePublishState,
8107
8160
  contextContent,
8108
8161
  contextFilters,
8109
- contextProfile,
8110
8162
  matchUpFilters,
8111
8163
  participantMap,
8164
+ publishStatus,
8165
+ contextProfile,
8166
+ drawDefinition,
8112
8167
  nextMatchUps,
8113
8168
  inContext,
8114
8169
  event
@@ -8134,12 +8189,14 @@ function drawMatchUps({
8134
8189
  policyDefinitions,
8135
8190
  useParticipantMap,
8136
8191
  tournamentRecord,
8192
+ usePublishState,
8137
8193
  contextFilters,
8138
- contextProfile,
8139
8194
  contextContent,
8140
- drawDefinition,
8141
8195
  matchUpFilters,
8142
8196
  participantMap,
8197
+ publishStatus,
8198
+ contextProfile,
8199
+ drawDefinition,
8143
8200
  nextMatchUps,
8144
8201
  tournamentId,
8145
8202
  inContext,
@@ -8190,12 +8247,14 @@ function drawMatchUps({
8190
8247
  afterRecoveryTimes,
8191
8248
  policyDefinitions,
8192
8249
  tournamentRecord,
8250
+ usePublishState,
8193
8251
  participantMap,
8194
- drawDefinition,
8195
- matchUpFilters,
8252
+ contextContent,
8196
8253
  contextFilters,
8254
+ matchUpFilters,
8255
+ publishStatus,
8197
8256
  contextProfile,
8198
- contextContent,
8257
+ drawDefinition,
8199
8258
  nextMatchUps,
8200
8259
  inContext,
8201
8260
  event
@@ -10836,6 +10895,11 @@ function getMatchUpDailyLimits({
10836
10895
  return { matchUpDailyLimits: dailyLimits };
10837
10896
  }
10838
10897
 
10898
+ function getDrawPublishStatus({ drawDetails, drawId }) {
10899
+ const details = drawDetails?.[drawId]?.publishingDetail;
10900
+ return details?.published;
10901
+ }
10902
+
10839
10903
  function scheduledSortedMatchUps({
10840
10904
  schedulingProfile,
10841
10905
  matchUps = []
@@ -10977,6 +11041,7 @@ function competitionMatchUps({
10977
11041
  participantsProfile,
10978
11042
  tournamentRecords,
10979
11043
  policyDefinitions,
11044
+ usePublishState,
10980
11045
  matchUpFilters,
10981
11046
  contextFilters,
10982
11047
  nextMatchUps,
@@ -10992,6 +11057,7 @@ function competitionMatchUps({
10992
11057
  participantsProfile,
10993
11058
  policyDefinitions,
10994
11059
  tournamentRecord,
11060
+ usePublishState,
10995
11061
  matchUpFilters,
10996
11062
  contextFilters,
10997
11063
  nextMatchUps,
@@ -11037,11 +11103,10 @@ function competitionScheduleMatchUps(params) {
11037
11103
  status = PUBLIC,
11038
11104
  sortCourtsData
11039
11105
  } = params;
11040
- const timeItem = usePublishState ? getTournamentTimeItem({
11106
+ const tournamentPublishStatus = usePublishState ? getTournamentTimeItem({
11041
11107
  tournamentRecord: tournamentRecords[activeTournamentId ?? getTournamentId()],
11042
11108
  itemType: `${PUBLISH}.${STATUS$1}`
11043
- }).timeItem : void 0;
11044
- const publishStatus = timeItem?.itemValue?.[status];
11109
+ }).timeItem?.itemValue?.[status] : void 0;
11045
11110
  const allCompletedMatchUps = alwaysReturnCompleted ? competitionMatchUps({
11046
11111
  ...params,
11047
11112
  matchUpFilters: {
@@ -11050,7 +11115,7 @@ function competitionScheduleMatchUps(params) {
11050
11115
  },
11051
11116
  contextFilters: params.contextFilters
11052
11117
  }).completedMatchUps : [];
11053
- if (usePublishState && (!publishStatus || !Object.keys(publishStatus).length)) {
11118
+ if (usePublishState && (!tournamentPublishStatus || !Object.keys(tournamentPublishStatus).length)) {
11054
11119
  return {
11055
11120
  completedMatchUps: allCompletedMatchUps,
11056
11121
  dateMatchUps: [],
@@ -11058,7 +11123,12 @@ function competitionScheduleMatchUps(params) {
11058
11123
  venues
11059
11124
  };
11060
11125
  }
11061
- const publishedDrawIds = usePublishState ? getCompetitionPublishedDrawIds({ tournamentRecords }).drawIds : void 0;
11126
+ let publishedDrawIds, detailsMap;
11127
+ if (usePublishState) {
11128
+ ({ drawIds: publishedDrawIds, detailsMap } = getCompetitionPublishedDrawDetails({
11129
+ tournamentRecords
11130
+ }));
11131
+ }
11062
11132
  if (publishedDrawIds?.length) {
11063
11133
  if (!params.contextFilters)
11064
11134
  params.contextFilters = {};
@@ -11070,34 +11140,34 @@ function competitionScheduleMatchUps(params) {
11070
11140
  );
11071
11141
  }
11072
11142
  }
11073
- if (publishStatus?.eventIds?.length) {
11143
+ if (tournamentPublishStatus?.eventIds?.length) {
11074
11144
  if (!params.matchUpFilters)
11075
11145
  params.matchUpFilters = {};
11076
11146
  if (params.matchUpFilters?.eventIds) {
11077
11147
  if (!params.matchUpFilters.eventIds.length) {
11078
- params.matchUpFilters.eventIds = publishStatus.eventIds;
11148
+ params.matchUpFilters.eventIds = tournamentPublishStatus.eventIds;
11079
11149
  } else {
11080
11150
  params.matchUpFilters.eventIds = params.matchUpFilters.eventIds.filter(
11081
- (eventId) => publishStatus.eventIds.includes(eventId)
11151
+ (eventId) => tournamentPublishStatus.eventIds.includes(eventId)
11082
11152
  );
11083
11153
  }
11084
11154
  } else {
11085
- params.matchUpFilters.eventIds = publishStatus.eventIds;
11155
+ params.matchUpFilters.eventIds = tournamentPublishStatus.eventIds;
11086
11156
  }
11087
11157
  }
11088
- if (publishStatus?.scheduledDates?.length) {
11158
+ if (tournamentPublishStatus?.scheduledDates?.length) {
11089
11159
  if (!params.matchUpFilters)
11090
11160
  params.matchUpFilters = {};
11091
11161
  if (params.matchUpFilters.scheduledDates) {
11092
11162
  if (!params.matchUpFilters.scheduledDates.length) {
11093
- params.matchUpFilters.scheduledDates = publishStatus.scheduledDates;
11163
+ params.matchUpFilters.scheduledDates = tournamentPublishStatus.scheduledDates;
11094
11164
  } else {
11095
11165
  params.matchUpFilters.scheduledDates = params.matchUpFilters.scheduledDates.filter(
11096
- (scheduledDate) => publishStatus.scheduledDates.includes(scheduledDate)
11166
+ (scheduledDate) => tournamentPublishStatus.scheduledDates.includes(scheduledDate)
11097
11167
  );
11098
11168
  }
11099
11169
  } else {
11100
- params.matchUpFilters.scheduledDates = publishStatus.scheduledDates;
11170
+ params.matchUpFilters.scheduledDates = tournamentPublishStatus.scheduledDates;
11101
11171
  }
11102
11172
  }
11103
11173
  if (alwaysReturnCompleted) {
@@ -11116,10 +11186,48 @@ function competitionScheduleMatchUps(params) {
11116
11186
  matchUpFilters: params.matchUpFilters,
11117
11187
  contextFilters: params.contextFilters
11118
11188
  });
11119
- const relevantMatchUps = [
11189
+ let relevantMatchUps = [
11120
11190
  ...upcomingMatchUps ?? [],
11121
11191
  ...pendingMatchUps ?? []
11122
11192
  ];
11193
+ if (detailsMap && Object.keys(detailsMap).length) {
11194
+ relevantMatchUps = relevantMatchUps.filter((matchUp) => {
11195
+ const { drawId, structureId, stage } = matchUp;
11196
+ if (!detailsMap[drawId])
11197
+ return false;
11198
+ if (detailsMap[drawId].stageDetails) {
11199
+ const stageKeys = Object.keys(detailsMap[drawId].stageDetails);
11200
+ const unpublishedStages = stageKeys.filter(
11201
+ (stage2) => !detailsMap[drawId].stageDetails[stage2].published
11202
+ );
11203
+ const publishedStages = stageKeys.filter(
11204
+ (stage2) => detailsMap[drawId].stageDetails[stage2].published
11205
+ );
11206
+ if (unpublishedStages.length && unpublishedStages.includes(stage))
11207
+ return false;
11208
+ if (publishedStages.length && publishedStages.includes(stage))
11209
+ return true;
11210
+ return unpublishedStages.length && !unpublishedStages.includes(stage) && !publishedStages.length;
11211
+ }
11212
+ if (detailsMap[drawId].structureDetails) {
11213
+ const structureIdKeys = Object.keys(
11214
+ detailsMap[drawId].structureDetails
11215
+ );
11216
+ const unpublishedStructureIds = structureIdKeys.filter(
11217
+ (structureId2) => !detailsMap[drawId].structureDetails[structureId2].published
11218
+ );
11219
+ const publishedStructureIds = structureIdKeys.filter(
11220
+ (structureId2) => detailsMap[drawId].structureDetails[structureId2].published
11221
+ );
11222
+ if (unpublishedStructureIds.length && unpublishedStructureIds.includes(structureId))
11223
+ return false;
11224
+ if (publishedStructureIds.length && publishedStructureIds.includes(structureId))
11225
+ return true;
11226
+ return unpublishedStructureIds.length && !unpublishedStructureIds.includes(structureId) && !publishedStructureIds.length;
11227
+ }
11228
+ return true;
11229
+ });
11230
+ }
11123
11231
  const dateMatchUps = sortDateMatchUps ? scheduledSortedMatchUps({ matchUps: relevantMatchUps, schedulingProfile }) : relevantMatchUps;
11124
11232
  const courtsData = courts?.map((court) => {
11125
11233
  const matchUps = getCourtMatchUps(court);
@@ -11130,11 +11238,11 @@ function competitionScheduleMatchUps(params) {
11130
11238
  };
11131
11239
  });
11132
11240
  const result = {
11133
- courtsData,
11134
11241
  completedMatchUps: alwaysReturnCompleted ? allCompletedMatchUps : completedMatchUps,
11135
11242
  // completed matchUps for the filter date
11136
11243
  dateMatchUps,
11137
11244
  // all incomplete matchUps for the filter date
11245
+ courtsData,
11138
11246
  groupInfo,
11139
11247
  venues
11140
11248
  };
@@ -11158,26 +11266,28 @@ function competitionScheduleMatchUps(params) {
11158
11266
  }) : courtMatchUps;
11159
11267
  }
11160
11268
  }
11161
- function getCompetitionPublishedDrawIds({
11269
+ function getCompetitionPublishedDrawDetails({
11162
11270
  tournamentRecords
11163
11271
  }) {
11164
11272
  const drawIds = [];
11273
+ const detailsMap = {};
11165
11274
  for (const tournamentRecord of Object.values(tournamentRecords)) {
11166
11275
  for (const event of tournamentRecord.events ?? []) {
11167
- const { timeItem } = getEventTimeItem({
11168
- itemType: `${PUBLISH}.${STATUS$1}`,
11169
- event
11170
- });
11171
- const pubState = timeItem?.itemValue?.[PUBLIC];
11172
- if (pubState?.drawIds?.length) {
11173
- drawIds.push(...pubState.drawIds);
11174
- } else {
11175
- const eventDrawIds = (event.drawDefinitions ?? []).map(({ drawId }) => drawId).filter(Boolean);
11176
- drawIds.push(...eventDrawIds);
11276
+ const eventPubStatus = getEventPublishStatus({ event });
11277
+ const drawDetails = eventPubStatus?.drawDetails;
11278
+ if (isObject(drawDetails)) {
11279
+ Object.assign(detailsMap, drawDetails);
11280
+ drawIds.push(
11281
+ ...Object.keys(drawDetails).filter(
11282
+ (drawId) => getDrawPublishStatus({ drawId, drawDetails })
11283
+ )
11284
+ );
11285
+ } else if (eventPubStatus?.drawIds?.length) {
11286
+ drawIds.push(...eventPubStatus.drawIds);
11177
11287
  }
11178
11288
  }
11179
11289
  }
11180
- return { drawIds };
11290
+ return { drawIds, detailsMap };
11181
11291
  }
11182
11292
 
11183
11293
  const { stageOrder } = drawDefinitionConstants;
@@ -11865,13 +11975,8 @@ function getMatchUpDependencies(params) {
11865
11975
  }
11866
11976
 
11867
11977
  function getEventPublishStatuses({ event }) {
11868
- const itemType = `${PUBLISH}.${STATUS$1}`;
11869
- const { timeItem } = getTimeItem({
11870
- element: event,
11871
- itemType
11872
- });
11873
- if (timeItem?.itemValue?.PUBLIC) {
11874
- const { drawIds: publishedDrawIds = [], seeding } = timeItem.itemValue.PUBLIC || {};
11978
+ const eventPubStatus = getEventPublishStatus({ event });
11979
+ if (eventPubStatus) {
11875
11980
  const publishedSeeding = {
11876
11981
  published: void 0,
11877
11982
  // seeding can be present for all entries in an event when no flights have been defined
@@ -11879,9 +11984,13 @@ function getEventPublishStatuses({ event }) {
11879
11984
  drawIds: []
11880
11985
  // seeding can be specific to drawIds
11881
11986
  };
11882
- if (seeding) {
11883
- Object.assign(publishedSeeding, timeItem.itemValue.PUBLIC.seeding);
11987
+ if (eventPubStatus.seeding) {
11988
+ Object.assign(publishedSeeding, eventPubStatus.seeding);
11884
11989
  }
11990
+ const { drawDetails, drawIds } = eventPubStatus;
11991
+ const publishedDrawIds = drawDetails && Object.keys(drawDetails).filter(
11992
+ (drawId) => getDrawPublishStatus({ drawDetails, drawId })
11993
+ ) || drawIds || [];
11885
11994
  return {
11886
11995
  publishedDrawIds,
11887
11996
  publishedSeeding
@@ -11967,6 +12076,10 @@ function getEventSeedAssignments({
11967
12076
  return eventSeedAssignments;
11968
12077
  }
11969
12078
 
12079
+ function stringSort(a, b) {
12080
+ return (a || "").localeCompare(b || "");
12081
+ }
12082
+
11970
12083
  function processEventEntry({
11971
12084
  convertExtensions,
11972
12085
  seedAssignments,
@@ -12597,6 +12710,15 @@ function getParticipantEntries(params) {
12597
12710
  individualParticipantIds?.forEach(addDrawEntry);
12598
12711
  }
12599
12712
  }
12713
+ const stages = (drawDefinition?.structures ?? []).reduce(
12714
+ (stages2, structure) => {
12715
+ if (!stages2.includes(structure.stage))
12716
+ stages2.push(structure.stage);
12717
+ return stages2;
12718
+ },
12719
+ []
12720
+ );
12721
+ const linksCount = (drawDefinition?.links ?? []).length;
12600
12722
  derivedDrawInfo[drawId] = {
12601
12723
  qualifyingPositionAssignments,
12602
12724
  qualifyingSeedAssignments,
@@ -12606,11 +12728,13 @@ function getParticipantEntries(params) {
12606
12728
  orderedStructureIds,
12607
12729
  mainSeedingMap,
12608
12730
  flightNumber,
12731
+ linksCount,
12609
12732
  drawOrder,
12610
12733
  drawName,
12611
12734
  drawType,
12612
12735
  drawSize,
12613
- drawId
12736
+ drawId,
12737
+ stages
12614
12738
  // qualifyingDrawSize,
12615
12739
  };
12616
12740
  }
@@ -12827,7 +12951,7 @@ function getParticipantEntries(params) {
12827
12951
  const itemIsPrior = consideredMinutes >= scheduledMinutes;
12828
12952
  const timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference) ? minutesDifference <= scheduledMinutesDifference : itemIsPrior && timeStringMinutes(consideredItem.scheduledTime) < timeStringMinutes(notBeforeTime);
12829
12953
  if (timeOverlap && !(bothPotential && sameDraw) && itemIsPrior) {
12830
- const key = [scheduleItem.matchUpId, consideredItem.matchUpId].sort().join("|");
12954
+ const key = [scheduleItem.matchUpId, consideredItem.matchUpId].sort(stringSort).join("|");
12831
12955
  participantAggregator.scheduleConflicts[key] = {
12832
12956
  priorScheduledMatchUpId: scheduleItem.matchUpId,
12833
12957
  matchUpIdWithConflict: consideredItem.matchUpId
@@ -14909,7 +15033,9 @@ function getDrawData(params) {
14909
15033
  policyDefinitions,
14910
15034
  tournamentRecord,
14911
15035
  inContext = true,
15036
+ usePublishState,
14912
15037
  drawDefinition,
15038
+ publishStatus,
14913
15039
  noDeepCopy,
14914
15040
  sortConfig,
14915
15041
  context,
@@ -14981,6 +15107,8 @@ function getDrawData(params) {
14981
15107
  tournamentParticipants,
14982
15108
  policyDefinitions,
14983
15109
  tournamentRecord,
15110
+ usePublishState,
15111
+ publishStatus,
14984
15112
  drawDefinition,
14985
15113
  inContext,
14986
15114
  structure,
@@ -15094,11 +15222,7 @@ function getEventData(params) {
15094
15222
  return { error: MISSING_EVENT };
15095
15223
  const { eventId } = event;
15096
15224
  const { tournamentId, endDate } = tournamentRecord;
15097
- const { timeItem } = getEventTimeItem({
15098
- itemType: `${PUBLISH}.${STATUS$1}`,
15099
- event
15100
- });
15101
- const publishStatus = timeItem?.itemValue?.[status];
15225
+ const publishStatus = getEventPublishStatus({ event, status });
15102
15226
  const { participants: tournamentParticipants } = getParticipants({
15103
15227
  withGroupings: true,
15104
15228
  withEvents: false,
@@ -15107,9 +15231,51 @@ function getEventData(params) {
15107
15231
  // order is important!!
15108
15232
  tournamentRecord
15109
15233
  });
15110
- const stageFilter = ({ stage }) => !usePublishState || !publishStatus?.stages?.length || publishStatus.stages.includes(stage);
15111
- const structureFilter = ({ structureId }) => !usePublishState || !publishStatus?.structureIds?.length || publishStatus.structureIds.includes(structureId);
15112
- const drawFilter = ({ drawId }) => !usePublishState || !publishStatus?.drawIds?.length || publishStatus.drawIds.includes(drawId);
15234
+ const stageFilter = ({ stage, drawId }) => {
15235
+ if (!usePublishState)
15236
+ return true;
15237
+ const stageDetails = publishStatus?.drawDetails?.[drawId]?.stageDetails;
15238
+ if (!stageDetails || !Object.keys(stageDetails).length)
15239
+ return true;
15240
+ return stageDetails[stage]?.published;
15241
+ };
15242
+ const structureFilter = ({ structureId, drawId }) => {
15243
+ if (!usePublishState)
15244
+ return true;
15245
+ const structureDetails = publishStatus?.drawDetails?.[drawId]?.structureDetails;
15246
+ if (!structureDetails || !Object.keys(structureDetails).length)
15247
+ return true;
15248
+ return structureDetails[structureId]?.published;
15249
+ };
15250
+ const drawFilter = ({ drawId }) => {
15251
+ if (!usePublishState)
15252
+ return true;
15253
+ if (publishStatus.drawDetails) {
15254
+ return publishStatus.drawDetails[drawId]?.publishingDetail?.published;
15255
+ } else if (publishStatus.drawIds) {
15256
+ return publishStatus.drawIds.includes(drawId);
15257
+ }
15258
+ return true;
15259
+ };
15260
+ const roundLimitMapper = ({ drawId, structure }) => {
15261
+ if (!usePublishState)
15262
+ return structure;
15263
+ const roundLimit = publishStatus?.drawDetails?.[drawId]?.structureDetails?.[structure.structureId]?.roundLimit;
15264
+ if (isConvertableInteger(roundLimit)) {
15265
+ const roundNumbers = generateRange(1, roundLimit + 1);
15266
+ const roundMatchUps = {};
15267
+ const roundProfile = {};
15268
+ for (const roundNumber of roundNumbers) {
15269
+ if (structure.roundMatchUps[roundNumber]) {
15270
+ roundMatchUps[roundNumber] = structure.roundMatchUps[roundNumber];
15271
+ roundProfile[roundNumber] = structure.roundProfile[roundNumber];
15272
+ }
15273
+ }
15274
+ structure.roundMatchUps = roundMatchUps;
15275
+ structure.roundProfile = roundProfile;
15276
+ }
15277
+ return structure;
15278
+ };
15113
15279
  const drawDefinitions = event.drawDefinitions || [];
15114
15280
  const drawsData = drawDefinitions.filter(drawFilter).map(
15115
15281
  (drawDefinition) => (({ drawInfo, structures }) => ({
@@ -15123,15 +15289,24 @@ function getEventData(params) {
15123
15289
  noDeepCopy: true,
15124
15290
  policyDefinitions,
15125
15291
  tournamentRecord,
15292
+ usePublishState,
15126
15293
  drawDefinition,
15294
+ publishStatus,
15127
15295
  sortConfig,
15128
15296
  event
15129
15297
  })
15130
15298
  )
15131
- ).map(({ structures, ...drawData }) => ({
15132
- ...drawData,
15133
- structures: structures?.filter(structureFilter)?.filter(stageFilter)
15134
- })).filter((drawData) => drawData.structures?.length);
15299
+ ).map(({ structures, ...drawData }) => {
15300
+ const filteredStructures = structures?.filter(
15301
+ ({ stage, structureId }) => structureFilter({ structureId, drawId: drawData.drawId }) && stageFilter({ stage, drawId: drawData.drawId })
15302
+ ).map(
15303
+ (structure) => roundLimitMapper({ drawId: drawData.drawId, structure })
15304
+ );
15305
+ return {
15306
+ ...drawData,
15307
+ structures: filteredStructures
15308
+ };
15309
+ }).filter((drawData) => drawData.structures?.length);
15135
15310
  const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
15136
15311
  const venues = tournamentRecord.venues || [];
15137
15312
  const venuesData = venues.map(
@@ -15177,10 +15352,7 @@ function getEventData(params) {
15177
15352
  eventInfo,
15178
15353
  drawsData
15179
15354
  };
15180
- eventData.eventInfo.publish = {
15181
- createdAt: timeItem?.createdAt,
15182
- state: timeItem?.itemValue
15183
- };
15355
+ eventData.eventInfo.publish = publishStatus;
15184
15356
  return { ...SUCCESS, eventData };
15185
15357
  }
15186
15358