tods-competition-factory 1.8.9 → 1.8.11

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.
@@ -209,10 +209,6 @@ const POLICY_NOT_FOUND = {
209
209
  message: "Policy not found",
210
210
  code: "ERR_NOT_FOUND_POLICY"
211
211
  };
212
- const MISSING_SCORING_POLICY = {
213
- message: "Missing scoring policy / matchUpFormats",
214
- code: "ERR_MISSING_POLICY_SCORING_MATCHUP_FORMATS"
215
- };
216
212
  const MISSING_COURT_ID = {
217
213
  message: "Missing courtId",
218
214
  code: "ERR_MISSING_COURT_ID"
@@ -237,10 +233,6 @@ const MISSING_PARTICIPANT = {
237
233
  message: "Missing participant",
238
234
  code: "ERR_MISSING_PARTICIPANT"
239
235
  };
240
- const MISSING_PARTICIPANTS = {
241
- message: "Missing participants",
242
- code: "ERR_MISSING_PARTICIPANTS"
243
- };
244
236
  const MISSING_PARTICIPANT_ID = {
245
237
  message: "Missing participantId",
246
238
  code: "ERR_MISSING_PARTICIPANT_ID"
@@ -289,14 +281,6 @@ const INVALID_SCALE_ITEM = {
289
281
  message: "Invalid scaleItem",
290
282
  code: "ERR_INVALID_SCALE_ITEM"
291
283
  };
292
- const SCALE_ITEM_NOT_FOUND = {
293
- message: "No scaleItem found",
294
- code: "ERR_NOT_FOUND_SCALE_ITEM"
295
- };
296
- const INVALID_OBJECT = {
297
- message: "Invalid object",
298
- code: "ERR_INVALID_OBJECT"
299
- };
300
284
  const INVALID_VALUES = {
301
285
  message: "Invalid values",
302
286
  code: "ERR_INVALID_VALUES"
@@ -853,70 +837,17 @@ function UUID() {
853
837
  }
854
838
 
855
839
  const APPLIED_POLICIES = "appliedPolicies";
856
- const AUDIT_POSITION_ACTIONS = "positionActions";
857
840
  const CONTEXT = "context";
858
- const DELEGATED_OUTCOME = "delegatedOutcome";
859
841
  const DISABLED = "disabled";
860
842
  const DISABLE_LINKS = "disableLinks";
861
- const DISABLE_AUTO_CALC = "disableAutoCalc";
862
- const DRAW_DELETIONS = "drawDeletions";
863
- const DRAW_PROFILE = "drawProfile";
864
- const ENTRY_PROFILE = "entryProfile";
865
- const EVENT_PROFILE = "eventProfile";
866
- const FACTORY = "factory";
867
843
  const FLIGHT_PROFILE = "flightProfile";
868
- const GROUPING_ATTRIBUTE = "groupingAttribute";
869
844
  const LINEUPS = "lineUps";
870
845
  const LINKED_TOURNAMENTS = "linkedTournamentsIds";
871
- const MATCHUP_HISTORY = "matchUpHistory";
872
- const PARTICIPANT_REPRESENTATIVES = "participantRepresentatives";
873
- const PERSON_REQUESTS = "personRequests";
874
- const RANKING_POINTS = "rankingPoints";
875
846
  const ROUND_TARGET = "roundTarget";
876
847
  const SCHEDULE_LIMITS = "scheduleLimits";
877
848
  const SCHEDULE_TIMING = "scheduleTiming";
878
849
  const SCHEDULING_PROFILE = "schedulingProfile";
879
- const STATUS_DETAIL = "statusDetail";
880
- const SUB_ORDER = "subOrder";
881
850
  const TALLY = "tally";
882
- const TIE_FORMAT_MODIFICATIONS = "tieFormatModification";
883
- const extensionConstants = {
884
- APPLIED_POLICIES,
885
- AUDIT_POSITION_ACTIONS,
886
- CONTEXT,
887
- // used to capture, e.g. context in which a venue was added
888
- DELEGATED_OUTCOME,
889
- DISABLED,
890
- DISABLE_LINKS,
891
- DISABLE_AUTO_CALC,
892
- DRAW_DELETIONS,
893
- DRAW_PROFILE,
894
- ENTRY_PROFILE,
895
- // used for drawGeneration; not relevant for anonymized tournaments
896
- EVENT_PROFILE,
897
- FLIGHT_PROFILE,
898
- GROUPING_ATTRIBUTE,
899
- // for generating teams; not relevant for anonymized tournaments
900
- LINEUPS,
901
- LINKED_TOURNAMENTS,
902
- MATCHUP_HISTORY,
903
- PARTICIPANT_REPRESENTATIVES,
904
- PERSON_REQUESTS,
905
- RANKING_POINTS,
906
- // for attaching points awarded to tournamentRecord
907
- ROUND_TARGET,
908
- SCHEDULE_LIMITS,
909
- SCHEDULE_TIMING,
910
- SCHEDULING_PROFILE,
911
- STATUS_DETAIL,
912
- // attached to event.entries
913
- SUB_ORDER,
914
- TALLY,
915
- TIE_FORMAT_MODIFICATIONS,
916
- // for auditing, not important when anonymized
917
- FACTORY
918
- // used for capturing versioning of factory and other TODS document processors
919
- };
920
851
 
921
852
  function getAppliedPolicies({
922
853
  onlySpecifiedPolicyTypes = false,
@@ -976,7 +907,7 @@ function getPolicyDefinitions({
976
907
  if (policy)
977
908
  policyDefinitions[policyType] = policy;
978
909
  }
979
- return Object.keys(policyDefinitions).length ? { policyDefinitions } : { error: POLICY_NOT_FOUND };
910
+ return Object.keys(policyDefinitions).length ? { policyDefinitions } : { info: POLICY_NOT_FOUND.message };
980
911
  }
981
912
 
982
913
  const RANKING = "RANKING";
@@ -1723,7 +1654,7 @@ function findPolicy({
1723
1654
  structure,
1724
1655
  event
1725
1656
  });
1726
- return appliedPolicies?.[policyType] ? { policy: appliedPolicies[policyType] } : { error: POLICY_NOT_FOUND };
1657
+ return appliedPolicies?.[policyType] ? { policy: appliedPolicies[policyType] } : { info: POLICY_NOT_FOUND?.message };
1727
1658
  }
1728
1659
 
1729
1660
  function getScheduleTiming({
@@ -5812,7 +5743,6 @@ function matchUpEndTime({ matchUp }) {
5812
5743
 
5813
5744
  const SINGLES = "SINGLES";
5814
5745
  const TEAM = "TEAM";
5815
- const TEAM_EVENT = "TEAM";
5816
5746
 
5817
5747
  function getMatchUpScheduleDetails({
5818
5748
  scheduleVisibilityFilters,
@@ -8791,6 +8721,199 @@ function getMatchUpFormatTimingUpdate({ tournamentRecords }) {
8791
8721
  });
8792
8722
  }
8793
8723
 
8724
+ const FORMAT_STANDARD = "SET3-S:6/TB7";
8725
+
8726
+ const ADULT = "ADULT";
8727
+ const JUNIOR = "JUNIOR";
8728
+ const WHEELCHAIR = "WHEELCHAIR";
8729
+ const POLICY_SCHEDULING_DEFAULT = {
8730
+ [POLICY_TYPE_SCHEDULING]: {
8731
+ defaultTimes: {
8732
+ averageTimes: [{ categoryNames: [], minutes: { default: 90 } }],
8733
+ recoveryTimes: [{ minutes: { [DOUBLES]: 30, default: 60 } }]
8734
+ },
8735
+ defaultDailyLimits: {
8736
+ [SINGLES$1]: 2,
8737
+ [DOUBLES]: 2,
8738
+ total: 3
8739
+ },
8740
+ matchUpAverageTimes: [
8741
+ {
8742
+ matchUpFormatCodes: [FORMAT_STANDARD],
8743
+ // Best of 3 tiebreak sets
8744
+ averageTimes: [
8745
+ {
8746
+ categoryNames: [],
8747
+ minutes: { default: 90 }
8748
+ },
8749
+ {
8750
+ categoryTypes: [WHEELCHAIR],
8751
+ minutes: { default: 120 }
8752
+ }
8753
+ ]
8754
+ },
8755
+ {
8756
+ matchUpFormatCodes: ["SET3-S:6/TB7-F:TB10"],
8757
+ // Two tiebreak sets, 10-point match tiebreak at one set all
8758
+ averageTimes: [{ categoryNames: [], minutes: { default: 85 } }]
8759
+ },
8760
+ {
8761
+ matchUpFormatCodes: ["SET3-S:6/TB7-F:TB7"],
8762
+ // Two tiebreak sets, 7-point match tiebreak at one set all
8763
+ averageTimes: [{ categoryNames: [], minutes: { default: 70 } }]
8764
+ },
8765
+ {
8766
+ matchUpFormatCodes: ["SET3-S:4NOAD-F:TB7"],
8767
+ // Two short sets to 4 with deciding game at 3-3, 7-point match tiebreak at one set all
8768
+ averageTimes: [{ categoryNames: [], minutes: { default: 55 } }]
8769
+ },
8770
+ {
8771
+ matchUpFormatCodes: ["SET3-S:4/TB7"],
8772
+ // Best of 3 sets to 4
8773
+ averageTimes: [{ categoryNames: [], minutes: { default: 60 } }]
8774
+ },
8775
+ {
8776
+ matchUpFormatCodes: ["SET3-S:4/TB7-F:TB7"],
8777
+ // Two short sets to 4, 7-point match tiebreak at one set all
8778
+ averageTimes: [{ categoryNames: [], minutes: { default: 50 } }]
8779
+ },
8780
+ {
8781
+ matchUpFormatCodes: ["SET3-S:4/TB7-F:TB10"],
8782
+ // Two short sets to 4, 10-point match tiebreak at one set all
8783
+ averageTimes: [{ categoryNames: [], minutes: { default: 55 } }]
8784
+ },
8785
+ {
8786
+ matchUpFormatCodes: ["SET3-S:4/TB5@3"],
8787
+ // Two out of three short sets to 4 with 5-point tiebreak at 3 games all
8788
+ averageTimes: [{ categoryNames: [], minutes: { default: 45 } }]
8789
+ },
8790
+ {
8791
+ matchUpFormatCodes: [
8792
+ "SET1-S:8/TB7",
8793
+ "SET1-S:8/TB7@7"
8794
+ ],
8795
+ averageTimes: [{ categoryNames: [], minutes: { default: 40 } }]
8796
+ },
8797
+ {
8798
+ matchUpFormatCodes: ["SET1-S:5/TB9@4"],
8799
+ // One no advantage set to 5, tiebreak to 9 at 4-4
8800
+ averageTimes: [{ categoryNames: [], minutes: { default: 30 } }]
8801
+ },
8802
+ {
8803
+ matchUpFormatCodes: ["SET1-S:6/TB7"],
8804
+ // One standard tiebreak set to 6, 7-point tiebreak at 6 games all
8805
+ averageTimes: [{ categoryNames: [], minutes: { default: 30 } }]
8806
+ },
8807
+ {
8808
+ matchUpFormatCodes: ["SET1-S:6NOAD"],
8809
+ // One set to 6 with deciding game at 5 games all
8810
+ averageTimes: [{ categoryNames: [], minutes: { default: 30 } }]
8811
+ },
8812
+ {
8813
+ matchUpFormatCodes: [
8814
+ "SET1-S:4/TB7",
8815
+ "SET1-S:4/TB5@3",
8816
+ "SET3-S:TB10",
8817
+ "SET1-S:T20"
8818
+ ],
8819
+ averageTimes: [{ categoryNames: [], minutes: { default: 20 } }]
8820
+ },
8821
+ {
8822
+ matchUpFormatCodes: ["SET1-S:4NOAD"],
8823
+ // One short set to 4, deciding game is played at 3 games all
8824
+ averageTimes: [{ categoryNames: [], minutes: { default: 20 } }]
8825
+ },
8826
+ {
8827
+ matchUpFormatCodes: ["SET1-S:TB10"],
8828
+ // One 10-point tiebreak game
8829
+ averageTimes: [{ categoryNames: [], minutes: { default: 10 } }]
8830
+ }
8831
+ ],
8832
+ matchUpRecoveryTimes: [
8833
+ {
8834
+ matchUpFormatCodes: [
8835
+ "SET3-S:6/TB7",
8836
+ "SET3-S:6/TB7-F:TB10",
8837
+ "SET3-S:6/TB7-F:TB7"
8838
+ ],
8839
+ recoveryTimes: [
8840
+ {
8841
+ categoryTypes: [ADULT, WHEELCHAIR],
8842
+ minutes: { default: 60, [DOUBLES]: 30 }
8843
+ },
8844
+ {
8845
+ categoryTypes: [JUNIOR],
8846
+ minutes: { default: 60, [DOUBLES]: 60 }
8847
+ }
8848
+ ]
8849
+ },
8850
+ {
8851
+ matchUpFormatCodes: [
8852
+ "SET3-S:4/TB7-F:TB7",
8853
+ "SET3-S:4/TB7-F:TB10",
8854
+ "SET3-S:4NOAD-F:TB7",
8855
+ "SET3-S:4/TB7",
8856
+ "SET3-S:4/TB5@3"
8857
+ ],
8858
+ recoveryTimes: [
8859
+ {
8860
+ categoryTypes: [ADULT, WHEELCHAIR],
8861
+ minutes: { default: 30 }
8862
+ },
8863
+ {
8864
+ categoryTypes: [JUNIOR],
8865
+ minutes: { default: 60 }
8866
+ }
8867
+ ]
8868
+ },
8869
+ {
8870
+ matchUpFormatCodes: [
8871
+ "SET1-S:8/TB7",
8872
+ "SET1-S:8/TB7@7",
8873
+ "SET1-S:5/TB9@4",
8874
+ "SET1-S:6/TB7",
8875
+ "SET1-S:6NOAD",
8876
+ "SET1-S:4/TB7",
8877
+ "SET1-S:4NOAD",
8878
+ "SET3-S:TB10",
8879
+ "SET1-S:T20"
8880
+ ],
8881
+ recoveryTimes: [
8882
+ {
8883
+ categoryNames: [],
8884
+ minutes: { default: 30 }
8885
+ }
8886
+ ]
8887
+ },
8888
+ {
8889
+ matchUpFormatCodes: ["SET1-S:4/TB5@3"],
8890
+ // One short set to 4, 5-point tiebreak at 3 games all
8891
+ recoveryTimes: [
8892
+ {
8893
+ categoryTypes: [ADULT, JUNIOR],
8894
+ minutes: { default: 30 }
8895
+ },
8896
+ {
8897
+ categoryTypes: [WHEELCHAIR],
8898
+ minutes: { default: 15 }
8899
+ }
8900
+ ]
8901
+ },
8902
+ {
8903
+ matchUpFormatCodes: ["SET1-S:TB10"],
8904
+ // One 10-point tiebreak game
8905
+ recoveryTimes: [
8906
+ {
8907
+ categoryNames: [],
8908
+ minutes: { default: 15 }
8909
+ }
8910
+ ]
8911
+ }
8912
+ ],
8913
+ matchUpDailyLimits: []
8914
+ }
8915
+ };
8916
+
8794
8917
  function getEventMatchUpFormatTiming$1({
8795
8918
  tournamentRecord,
8796
8919
  matchUpFormats,
@@ -8804,6 +8927,7 @@ function getEventMatchUpFormatTiming$1({
8804
8927
  if (!event)
8805
8928
  return { error: MISSING_EVENT };
8806
8929
  let matchUpFormatDefinitions = [];
8930
+ let info;
8807
8931
  if (!matchUpFormats?.length) {
8808
8932
  const { policy } = findPolicy({
8809
8933
  policyType: POLICY_TYPE_SCORING,
@@ -8817,20 +8941,19 @@ function getEventMatchUpFormatTiming$1({
8817
8941
  name: SCHEDULE_TIMING,
8818
8942
  event
8819
8943
  });
8944
+ let matchUpAverageTimes, matchUpRecoveryTimes;
8820
8945
  if (extension?.value) {
8821
- matchUpFormatDefinitions = unique(
8822
- [
8823
- ...(extension.value.matchUpAverageTimes || []).map(
8824
- (at) => at.matchUpFormatCodes
8825
- ),
8826
- ...(extension.value.matchUpRecoveryTimes || []).map(
8827
- (at) => at.matchUpFormatCodes
8828
- )
8829
- ].flat()
8830
- ).map((matchUpFormat) => ({ matchUpFormat }));
8946
+ ({ matchUpAverageTimes, matchUpRecoveryTimes } = extension.value);
8831
8947
  } else {
8832
- return { error: MISSING_SCORING_POLICY };
8948
+ ({ matchUpAverageTimes, matchUpRecoveryTimes } = POLICY_SCHEDULING_DEFAULT[POLICY_TYPE_SCHEDULING]);
8833
8949
  }
8950
+ matchUpFormatDefinitions = unique(
8951
+ [
8952
+ ...(matchUpAverageTimes || []).map((at) => at.matchUpFormatCodes),
8953
+ ...(matchUpRecoveryTimes || []).map((at) => at.matchUpFormatCodes)
8954
+ ].flat()
8955
+ ).map((matchUpFormat) => ({ matchUpFormat }));
8956
+ info = "default scheduling policy in use";
8834
8957
  }
8835
8958
  } else {
8836
8959
  const uniqueMatchUpFormats = [];
@@ -8845,7 +8968,7 @@ function getEventMatchUpFormatTiming$1({
8845
8968
  }).filter(Boolean);
8846
8969
  }
8847
8970
  const { eventType, eventId, category } = event;
8848
- const categoryName = category?.categoryName || category?.ageCategoryCode || eventId;
8971
+ const categoryName = category?.categoryName ?? category?.ageCategoryCode ?? eventId;
8849
8972
  if (!eventId)
8850
8973
  return { error: MISSING_EVENT };
8851
8974
  const eventMatchUpFormatTiming = matchUpFormatDefinitions.map(
@@ -8858,17 +8981,14 @@ function getEventMatchUpFormatTiming$1({
8858
8981
  eventType,
8859
8982
  event
8860
8983
  });
8861
- return Object.assign(
8862
- {},
8863
- {
8864
- ...timing,
8865
- description,
8866
- matchUpFormat
8867
- }
8868
- );
8984
+ return {
8985
+ matchUpFormat,
8986
+ description,
8987
+ ...timing
8988
+ };
8869
8989
  }
8870
8990
  );
8871
- return { eventMatchUpFormatTiming };
8991
+ return definedAttributes({ eventMatchUpFormatTiming, info });
8872
8992
  }
8873
8993
 
8874
8994
  function getEventMatchUpFormatTiming({
@@ -11248,7 +11368,7 @@ function participantScaleItem({
11248
11368
  return { error: INVALID_VALUES };
11249
11369
  if (!participant.timeItems)
11250
11370
  participant.timeItems = [];
11251
- if (participant && Array.isArray(participant.timeItems)) {
11371
+ if (Array.isArray(participant.timeItems)) {
11252
11372
  const { accessor, scaleType, eventType, scaleName } = scaleAttributes;
11253
11373
  const filterType = [SCALE, scaleType, eventType, scaleName].join(".");
11254
11374
  const filteredTimeItems = participant.timeItems.filter((timeItem2) => timeItem2?.itemType === filterType).filter((timeItem2) => !requireTimeStamp || timeItem2?.itemDate).sort(
@@ -11268,12 +11388,10 @@ function participantScaleItem({
11268
11388
  scaleName: scaleName2,
11269
11389
  scaleType: scaleType2
11270
11390
  };
11271
- return { scaleItem };
11272
- } else {
11273
- return { error: SCALE_ITEM_NOT_FOUND };
11391
+ return { ...SUCCESS, scaleItem };
11274
11392
  }
11275
11393
  }
11276
- return { error: MISSING_PARTICIPANT };
11394
+ return { ...SUCCESS, scaleItem: void 0 };
11277
11395
  }
11278
11396
 
11279
11397
  function addFinishingRounds({
@@ -11838,7 +11956,7 @@ function addStructureParticipation({
11838
11956
 
11839
11957
  function processSides(params) {
11840
11958
  const {
11841
- withScheduleTimes,
11959
+ withScheduleItems,
11842
11960
  scheduleAnalysis,
11843
11961
  withTeamMatchUps,
11844
11962
  participantMap,
@@ -11948,7 +12066,7 @@ function processSides(params) {
11948
12066
  stage
11949
12067
  });
11950
12068
  }
11951
- if (scheduleAnalysis || withScheduleTimes) {
12069
+ if (scheduleAnalysis || withScheduleItems) {
11952
12070
  addScheduleItem({
11953
12071
  participantMap,
11954
12072
  participantId: participantId2,
@@ -12094,7 +12212,6 @@ function getParticipantEntries(params) {
12094
12212
  participantMap,
12095
12213
  withPotentialMatchUps,
12096
12214
  withRankingProfile,
12097
- withScheduleTimes,
12098
12215
  withScheduleItems,
12099
12216
  scheduleAnalysis,
12100
12217
  withTeamMatchUps,
@@ -12105,8 +12222,6 @@ function getParticipantEntries(params) {
12105
12222
  withEvents,
12106
12223
  withDraws
12107
12224
  } = params;
12108
- if (withScheduleItems)
12109
- console.log({ withScheduleItems });
12110
12225
  const targetParticipantIds = participantFilters?.participantIds;
12111
12226
  const getRelevantParticipantIds = (participantId) => {
12112
12227
  const relevantParticipantIds = [participantId];
@@ -12124,7 +12239,7 @@ function getParticipantEntries(params) {
12124
12239
  withDraws: withDraws || withRankingProfile,
12125
12240
  withPotentialMatchUps,
12126
12241
  withRankingProfile,
12127
- withScheduleTimes,
12242
+ withScheduleItems,
12128
12243
  scheduleAnalysis,
12129
12244
  withTeamMatchUps,
12130
12245
  withStatistics,
@@ -12444,7 +12559,7 @@ function getParticipantEntries(params) {
12444
12559
  matchUpType: matchUpType2
12445
12560
  });
12446
12561
  }
12447
- if (Array.isArray(potentialParticipants) && (nextMatchUps || !!scheduleAnalysis || withScheduleTimes)) {
12562
+ if (Array.isArray(potentialParticipants) && (nextMatchUps || !!scheduleAnalysis || withScheduleItems)) {
12448
12563
  const potentialParticipantIds = potentialParticipants.flat().map(extractAttributes("participantId")).filter(Boolean);
12449
12564
  potentialParticipantIds?.forEach((participantId) => {
12450
12565
  const relevantParticipantIds = getRelevantParticipantIds(participantId);
@@ -12459,7 +12574,7 @@ function getParticipantEntries(params) {
12459
12574
  drawId
12460
12575
  });
12461
12576
  });
12462
- if (!!scheduleAnalysis || withScheduleTimes) {
12577
+ if (!!scheduleAnalysis || withScheduleItems) {
12463
12578
  addScheduleItem({
12464
12579
  potential: true,
12465
12580
  participantMap,
@@ -12568,13 +12683,18 @@ function getParticipantEntries(params) {
12568
12683
  const notBeforeTime = typeChange ? typeChangeTimeAfterRecovery || timeAfterRecovery : timeAfterRecovery;
12569
12684
  const sameDraw = scheduleItem.drawId === consideredItem.drawId;
12570
12685
  const bothPotential = potentialMatchUps[scheduleItem.matchUpId] && potentialMatchUps[consideredItem.matchUpId];
12571
- const nextMinutes = timeStringMinutes(consideredItem.scheduledTime);
12572
- const minutesDifference = Math.abs(nextMinutes - scheduledMinutes);
12573
- const timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference) ? minutesDifference <= scheduledMinutesDifference : timeStringMinutes(notBeforeTime) > timeStringMinutes(consideredItem.scheduledTime);
12574
- if (timeOverlap && !(bothPotential && sameDraw)) {
12686
+ const consideredMinutes = timeStringMinutes(
12687
+ consideredItem.scheduledTime
12688
+ );
12689
+ const minutesDifference = Math.abs(
12690
+ consideredMinutes - scheduledMinutes
12691
+ );
12692
+ const itemIsPrior = consideredMinutes > scheduledMinutes;
12693
+ const timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference) ? minutesDifference <= scheduledMinutesDifference : itemIsPrior && timeStringMinutes(consideredItem.scheduledTime) < timeStringMinutes(notBeforeTime);
12694
+ if (timeOverlap && !(bothPotential && sameDraw) && itemIsPrior) {
12575
12695
  participantAggregator.scheduleConflicts.push({
12576
- priorScheduledMatchUpId: consideredItem.matchUpId,
12577
- matchUpIdWithConflict: scheduleItem.matchUpId
12696
+ priorScheduledMatchUpId: scheduleItem.matchUpId,
12697
+ matchUpIdWithConflict: consideredItem.matchUpId
12578
12698
  });
12579
12699
  }
12580
12700
  }
@@ -12673,6 +12793,7 @@ function getParticipants(params) {
12673
12793
  ({
12674
12794
  potentialMatchUps,
12675
12795
  scheduleConflicts,
12796
+ scheduleItems,
12676
12797
  participant,
12677
12798
  statistics,
12678
12799
  opponents,
@@ -12698,7 +12819,8 @@ function getParticipants(params) {
12698
12819
  matchUps: withMatchUps || withRankingProfile ? Object.values(matchUps2) : void 0,
12699
12820
  opponents: withOpponents ? participantOpponents : void 0,
12700
12821
  potentialMatchUps: nextMatchUps ? Object.values(potentialMatchUps) : void 0,
12701
- statistics: withStatistics ? Object.values(statistics) : void 0
12822
+ statistics: withStatistics ? Object.values(statistics) : void 0,
12823
+ scheduleItems: withScheduleItems ? scheduleItems : void 0
12702
12824
  },
12703
12825
  false,
12704
12826
  false,
@@ -12729,1108 +12851,6 @@ function getParticipants(params) {
12729
12851
  };
12730
12852
  }
12731
12853
 
12732
- function getDerivedPositionAssignments({
12733
- derivedDrawInfo,
12734
- participantId,
12735
- drawId
12736
- }) {
12737
- const mainPositionAssignment = derivedDrawInfo[drawId]?.mainPositionAssignments?.find(
12738
- (assignment) => assignment.participantId === participantId
12739
- );
12740
- const qualifyingPositionAssignment = derivedDrawInfo[drawId]?.qualifyingPositionAssignments?.find(
12741
- (assignment) => assignment.participantId === participantId
12742
- );
12743
- const positionAssignments = {};
12744
- if (mainPositionAssignment) {
12745
- const { participantId: participantId2, ...props } = mainPositionAssignment;
12746
- if (participantId2)
12747
- positionAssignments[MAIN] = { ...props };
12748
- }
12749
- if (qualifyingPositionAssignment) {
12750
- const { participantId: participantId2, ...props } = qualifyingPositionAssignment;
12751
- if (participantId2)
12752
- positionAssignments[QUALIFYING] = { ...props };
12753
- }
12754
- return Object.keys(positionAssignments).length ? positionAssignments : void 0;
12755
- }
12756
-
12757
- function getRelevantParticipantIdsMap({
12758
- processParticipantId,
12759
- // optional method which is passed each participantId
12760
- tournamentRecords,
12761
- tournamentRecord
12762
- }) {
12763
- if (typeof tournamentRecord !== "object" && typeof tournamentRecords !== "object")
12764
- return { error: MISSING_TOURNAMENT_RECORD };
12765
- const allParticipants = tournamentRecords ? Object.values(tournamentRecords).map((tournamentRecord2) => tournamentRecord2?.participants || []).flat() : tournamentRecord?.participants || [];
12766
- const relevantParticipantIdsMap = Object.assign(
12767
- {},
12768
- ...allParticipants.map(
12769
- ({ participantId, participantType, individualParticipantIds }) => {
12770
- typeof processParticipantId === "function" && processParticipantId(participantId);
12771
- const individualParticipantIdObjects = (individualParticipantIds || []).map((relevantParticipantId) => ({
12772
- participantType: INDIVIDUAL,
12773
- relevantParticipantId
12774
- }));
12775
- return {
12776
- [participantId]: individualParticipantIdObjects.concat({
12777
- relevantParticipantId: participantId,
12778
- participantType
12779
- })
12780
- };
12781
- }
12782
- )
12783
- );
12784
- return { relevantParticipantIdsMap };
12785
- }
12786
-
12787
- function getDerivedSeedAssignments({
12788
- derivedDrawInfo,
12789
- participantId,
12790
- drawId
12791
- }) {
12792
- const mainSeedAssignment = derivedDrawInfo[drawId]?.mainSeedAssignments?.find(
12793
- (assignment) => assignment.participantId === participantId
12794
- );
12795
- const qualifyingSeedAssignment = derivedDrawInfo[drawId]?.qualifyingSeedAssignments?.find(
12796
- (assignment) => assignment.participantId === participantId
12797
- );
12798
- const seedAssignments = {};
12799
- if (mainSeedAssignment) {
12800
- const { participantId: participantId2, ...props } = mainSeedAssignment;
12801
- if (participantId2)
12802
- seedAssignments[MAIN] = { ...props };
12803
- }
12804
- if (qualifyingSeedAssignment) {
12805
- const { participantId: participantId2, ...props } = qualifyingSeedAssignment;
12806
- if (participantId2)
12807
- seedAssignments[QUALIFYING] = { ...props };
12808
- }
12809
- return Object.keys(seedAssignments).length ? seedAssignments : void 0;
12810
- }
12811
-
12812
- const hasSchedule = ({
12813
- scheduleAttributes = ["scheduledDate", "scheduledTime"],
12814
- schedule = {}
12815
- }) => {
12816
- const matchUpScheduleKeys = Object.keys(schedule).filter((key) => scheduleAttributes.includes(key)).filter((key) => schedule[key]);
12817
- return !!matchUpScheduleKeys.length;
12818
- };
12819
-
12820
- function participantScheduledMatchUps({
12821
- scheduleAttributes = ["scheduledDate", "scheduledTime"],
12822
- matchUps = []
12823
- }) {
12824
- if (!validMatchUps(matchUps))
12825
- return { error: MISSING_MATCHUPS };
12826
- if (!Array.isArray(scheduleAttributes))
12827
- return { error: INVALID_VALUES };
12828
- const scheduledMatchUps = matchUps.filter(Boolean).filter(({ schedule }) => hasSchedule({ schedule, scheduleAttributes })).reduce((dateMatchUps, matchUp) => {
12829
- const { schedule } = matchUp;
12830
- const date = extractDate(schedule?.scheduledDate);
12831
- const time = extractTime(schedule?.scheduledTime);
12832
- if (date && time) {
12833
- if (dateMatchUps[date]) {
12834
- dateMatchUps[date].push(matchUp);
12835
- } else {
12836
- dateMatchUps[date] = [matchUp];
12837
- }
12838
- }
12839
- return dateMatchUps;
12840
- }, {});
12841
- const dates = Object.keys(scheduledMatchUps);
12842
- dates.forEach((date) => {
12843
- scheduledMatchUps[date].sort(
12844
- (a, b) => timeSort(
12845
- extractTime(a.schedule?.scheduledTime),
12846
- extractTime(b.schedule?.scheduledTime)
12847
- )
12848
- );
12849
- });
12850
- return { scheduledMatchUps };
12851
- }
12852
-
12853
- function annotateParticipant(params) {
12854
- const {
12855
- withScaleValues = true,
12856
- eventsPublishStatuses,
12857
- withEvents = true,
12858
- withDraws = true,
12859
- participantIdMap,
12860
- scheduleAnalysis,
12861
- derivedDrawInfo,
12862
- usePublishState,
12863
- withStatistics,
12864
- withOpponents,
12865
- withMatchUps,
12866
- withSeeding,
12867
- participant,
12868
- withISO2,
12869
- withIOC
12870
- } = params;
12871
- const scheduleConflicts = [];
12872
- const scheduleItems = [];
12873
- if (withIOC || withISO2)
12874
- addNationalityCode({ participant, withIOC, withISO2 });
12875
- if (withScaleValues) {
12876
- const { ratings, rankings } = getScaleValues({ participant });
12877
- participant.rankings = rankings;
12878
- participant.ratings = ratings;
12879
- }
12880
- const participantId = participant?.participantId;
12881
- if (!participantId || !participantIdMap[participantId])
12882
- return {};
12883
- const {
12884
- potentialMatchUps,
12885
- opponents,
12886
- matchUps,
12887
- events,
12888
- losses,
12889
- draws,
12890
- wins
12891
- } = participantIdMap[participantId];
12892
- const denominator = wins + losses;
12893
- const numerator = wins;
12894
- const statValue = denominator && numerator / denominator;
12895
- const winRatioStat = {
12896
- statCode: WIN_RATIO,
12897
- denominator,
12898
- numerator,
12899
- statValue
12900
- };
12901
- const participantDraws = Object.values(draws);
12902
- const participantEvents = Object.values(events);
12903
- if (withDraws && participantDraws) {
12904
- participant.draws = participantDraws;
12905
- for (const participantDraw of participantDraws) {
12906
- const publishedSeeding = eventsPublishStatuses[participantDraw.eventId]?.publishedSeeding;
12907
- const seedingPublished = !usePublishState || publishedSeeding?.published && (publishedSeeding?.drawIds?.length === 0 || publishedSeeding?.drawIds?.includes(participantDraw.drawId));
12908
- if (seedingPublished) {
12909
- const seedAssignments = getDerivedSeedAssignments({
12910
- drawId: participantDraw.drawId,
12911
- derivedDrawInfo,
12912
- participantId
12913
- });
12914
- if (seedAssignments) {
12915
- participantDraw.seedAssignments = seedAssignments;
12916
- }
12917
- }
12918
- }
12919
- }
12920
- if (withEvents && participantEvents) {
12921
- participant.events = participantEvents;
12922
- if (withSeeding) {
12923
- const seedingScales = Object.assign(
12924
- {},
12925
- ...(participant.timeItems || []).filter(({ itemType }) => itemType.split(".")[1] === SEEDING).map(({ itemType: seedingScaleName, itemValue: seedValue }) => ({
12926
- [seedingScaleName]: seedValue
12927
- }))
12928
- );
12929
- for (const participantEvent of participantEvents) {
12930
- const getScaleAccessor = (scaleName) => [SCALE, SEEDING, participantEvent.eventType, scaleName].join(".");
12931
- const publishedSeeding = eventsPublishStatuses[participantEvent.eventId]?.publishedSeeding;
12932
- const eventSeedingScaleNames = (publishedSeeding?.stageSeedingScaleNames && Object.values(publishedSeeding?.stageSeedingScaleNames) || Array.isArray(publishedSeeding?.seedingScaleNames) && publishedSeeding.seedingScaleNames || []).map(getScaleAccessor);
12933
- const publishedEventSeedingScaleNames = intersection(
12934
- Object.keys(seedingScales),
12935
- eventSeedingScaleNames
12936
- );
12937
- const eventSeedingPublished = !!(!usePublishState || !Object.keys(seedingScales).length && !publishedSeeding?.drawIds?.length || publishedEventSeedingScaleNames.length);
12938
- if (eventSeedingPublished && publishedEventSeedingScaleNames.length) {
12939
- if (publishedSeeding?.stageSeedingScaleNames) {
12940
- const scaleValues = Object.keys(
12941
- publishedSeeding.stageSeedingScaleNames
12942
- ).map((key) => {
12943
- const accessor = getScaleAccessor(
12944
- publishedSeeding.stageSeedingScaleNames[key]
12945
- );
12946
- const scaleValue = seedingScales[accessor];
12947
- return [key, scaleValue];
12948
- }).filter((pair) => pair[1]).map((pair) => ({ [pair[0]]: { seedValue: pair[1] } }));
12949
- const seedAssignments = Object.assign({}, ...scaleValues);
12950
- participantEvent.seedAssignments = seedAssignments;
12951
- } else if (publishedEventSeedingScaleNames) {
12952
- const seedValues = publishedEventSeedingScaleNames.map(
12953
- (scaleName) => seedingScales[scaleName]
12954
- );
12955
- participantEvent.seedValue = seedValues.pop();
12956
- }
12957
- } else if (!usePublishState && typeof withSeeding === "object") {
12958
- const scaleValues = Object.keys(withSeeding).map((key) => {
12959
- const accessor = getScaleAccessor(withSeeding[key]);
12960
- const scaleValue = seedingScales[accessor];
12961
- return [key, scaleValue];
12962
- }).filter((pair) => pair[1]).map((pair) => ({ [pair[0]]: { seedValue: pair[1] } }));
12963
- const seedAssignments = Object.assign({}, ...scaleValues);
12964
- participantEvent.seedAssignments = seedAssignments;
12965
- } else {
12966
- const { categoryName, ageCategoryCode } = participantEvent.category || {};
12967
- let scaleItem;
12968
- for (const scaleName of [
12969
- participantEvent.eventId,
12970
- ageCategoryCode,
12971
- categoryName
12972
- ]) {
12973
- const scaleAttributes = {
12974
- eventType: participantEvent.eventType,
12975
- scaleType: SEEDING,
12976
- scaleName
12977
- };
12978
- const result = participantScaleItem({
12979
- scaleAttributes,
12980
- participant
12981
- });
12982
- if (result.scaleItem) {
12983
- scaleItem = result.scaleItem;
12984
- break;
12985
- }
12986
- }
12987
- if (scaleItem) {
12988
- const seedValue = scaleItem.scaleValue;
12989
- const seedingPublished = !usePublishState || publishedSeeding?.published && (publishedSeeding?.drawIds?.length === 0 || publishedSeeding?.drawIds?.includes(
12990
- participantEvent.drawId
12991
- ));
12992
- if (seedingPublished) {
12993
- participantEvent.seedValue = seedValue;
12994
- }
12995
- }
12996
- }
12997
- if (participantEvent.drawIds?.length) {
12998
- for (const flightDrawId of participantEvent.drawIds || []) {
12999
- const drawSeedPublishingDisabled = publishedSeeding?.drawIds?.length && !publishedSeeding?.drawIds?.includes(flightDrawId);
13000
- if (eventSeedingPublished && !drawSeedPublishingDisabled) {
13001
- const seedAssignments = getDerivedSeedAssignments({
13002
- drawId: flightDrawId,
13003
- derivedDrawInfo,
13004
- participantId
13005
- });
13006
- if (seedAssignments && participantEvent.seedAssignments) {
13007
- for (const key of Object.keys(
13008
- participantEvent.seedAssignments
13009
- )) {
13010
- participantEvent.seedAssignments[key] = seedAssignments[key];
13011
- }
13012
- } else {
13013
- participantEvent.seedAssignments = seedAssignments;
13014
- }
13015
- }
13016
- }
13017
- }
13018
- }
13019
- }
13020
- }
13021
- const participantOpponents = Object.values(opponents).flat();
13022
- if (withOpponents && participantOpponents?.length) {
13023
- participant.opponents = participantOpponents;
13024
- participantDraws?.forEach((draw) => {
13025
- draw.opponents = participantOpponents.filter(
13026
- (opponent) => opponent.drawId === draw.drawId
13027
- );
13028
- });
13029
- }
13030
- const participantPotentialMatchUps = Object.values(potentialMatchUps);
13031
- const participantMatchUps = Object.values(matchUps);
13032
- if (withMatchUps) {
13033
- participant.potentialMatchUps = participantPotentialMatchUps;
13034
- participant.matchUps = participantMatchUps;
13035
- }
13036
- const allParticipantMatchUps = participantMatchUps.concat(
13037
- participantPotentialMatchUps
13038
- );
13039
- const scheduledMatchUps = participantScheduledMatchUps({
13040
- matchUps: allParticipantMatchUps
13041
- })?.scheduledMatchUps || [];
13042
- const { scheduledMinutesDifference } = scheduleAnalysis || {};
13043
- const dates = Object.keys(scheduledMatchUps);
13044
- dates.forEach((date) => {
13045
- scheduledMatchUps[date].filter(Boolean).forEach((matchUp, i) => {
13046
- const {
13047
- schedule: {
13048
- scheduledTime,
13049
- timeAfterRecovery,
13050
- typeChangeTimeAfterRecovery
13051
- },
13052
- matchUpStatus,
13053
- roundPosition,
13054
- structureName,
13055
- matchUpType,
13056
- roundNumber,
13057
- matchUpId,
13058
- drawId,
13059
- score
13060
- } = matchUp;
13061
- scheduleItems.push({
13062
- ...matchUp.schedule,
13063
- scheduledTime: extractTime(matchUp.schedule?.scheduledTime),
13064
- roundPosition,
13065
- structureName,
13066
- matchUpType,
13067
- roundNumber,
13068
- matchUpId,
13069
- drawId
13070
- });
13071
- const ignoreMatchUp = matchUpStatus === BYE || [WALKOVER$1, DEFAULTED].includes(matchUpStatus) && !scoreHasValue({ score });
13072
- if (scheduledTime && !ignoreMatchUp) {
13073
- const scheduledMinutes = timeStringMinutes(scheduledTime);
13074
- const matchUpsToConsider = scheduledMatchUps[date].slice(i + 1);
13075
- for (const consideredMatchUp of matchUpsToConsider) {
13076
- const ignoreMatchUp2 = consideredMatchUp.matchUpStatus === BYE || [WALKOVER$1, DEFAULTED].includes(consideredMatchUp.matchUpStatus) && !scoreHasValue(consideredMatchUp);
13077
- if (!ignoreMatchUp2 && consideredMatchUp.schedule?.scheduledTime) {
13078
- const typeChange = matchUp.matchUpType !== consideredMatchUp.matchUpType;
13079
- const notBeforeTime = typeChange ? typeChangeTimeAfterRecovery || timeAfterRecovery : timeAfterRecovery;
13080
- const sameDraw = matchUp.drawId === consideredMatchUp.drawId;
13081
- const bothPotential = matchUp.potential && consideredMatchUp.potential;
13082
- const nextMinutes = timeStringMinutes(
13083
- consideredMatchUp.schedule?.scheduledTime
13084
- );
13085
- const minutesDifference = nextMinutes - scheduledMinutes;
13086
- const timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference) ? minutesDifference <= scheduledMinutesDifference : timeStringMinutes(notBeforeTime) > timeStringMinutes(consideredMatchUp.schedule?.scheduledTime);
13087
- if (timeOverlap && !(bothPotential && sameDraw)) {
13088
- scheduleConflicts.push({
13089
- priorScheduledMatchUpId: consideredMatchUp.matchUpId,
13090
- matchUpIdWithConflict: matchUpId
13091
- });
13092
- }
13093
- }
13094
- }
13095
- }
13096
- });
13097
- });
13098
- if (withStatistics)
13099
- participant.statistics = [winRatioStat];
13100
- return { scheduleConflicts, scheduleItems };
13101
- }
13102
-
13103
- function getDrawDetails({
13104
- eventEntries,
13105
- sortConfig,
13106
- event
13107
- }) {
13108
- const derivedInfo = {};
13109
- const drawDetails = Object.assign(
13110
- {},
13111
- ...(event.drawDefinitions ?? []).map((drawDefinition) => {
13112
- const entriesMap = Object.assign(
13113
- {},
13114
- ...(eventEntries ?? []).filter((entry) => entry.participantId).map((entry) => ({ [entry.participantId]: entry })),
13115
- ...drawDefinition.entries.filter((entry) => entry.participantId).map((entry) => ({ [entry.participantId]: entry }))
13116
- );
13117
- const drawEntries = Object.values(entriesMap);
13118
- const mainStructure = getDrawStructures({
13119
- stageSequence: 1,
13120
- drawDefinition,
13121
- stage: MAIN
13122
- })?.structures?.[0];
13123
- const mainPositionAssignments = mainStructure && getPositionAssignments({
13124
- structure: mainStructure
13125
- })?.positionAssignments;
13126
- const drawSize = mainPositionAssignments?.length;
13127
- const qualifyingStructure = getDrawStructures({
13128
- stageSequence: 1,
13129
- stage: QUALIFYING,
13130
- drawDefinition
13131
- })?.structures?.[0];
13132
- const qualifyingPositionAssignments = mainStructure && getPositionAssignments({
13133
- structure: qualifyingStructure
13134
- })?.positionAssignments;
13135
- const qualifyingDrawSize = qualifyingPositionAssignments?.length;
13136
- const mainSeedAssignments = mainStructure?.seedAssignments;
13137
- const qualifyingSeedAssignments = qualifyingStructure?.seedAssignments;
13138
- const orderedStructureIds = (drawDefinition.structures || []).sort((a, b) => structureSort(a, b, sortConfig)).map(({ structureId, structures }) => {
13139
- return [
13140
- structureId,
13141
- ...(structures || []).map(({ structureId: structureId2 }) => structureId2)
13142
- ];
13143
- }).flat(Infinity);
13144
- const flightNumber = event?._flightProfile?.flights?.find(
13145
- (flight) => flight.drawId === drawDefinition.drawId
13146
- )?.flightNumber;
13147
- derivedInfo[drawDefinition.drawId] = {
13148
- qualifyingPositionAssignments,
13149
- qualifyingSeedAssignments,
13150
- mainPositionAssignments,
13151
- mainSeedAssignments,
13152
- orderedStructureIds,
13153
- qualifyingDrawSize,
13154
- flightNumber,
13155
- drawSize
13156
- };
13157
- return {
13158
- [drawDefinition.drawId]: {
13159
- drawType: drawDefinition.drawType,
13160
- drawEntries
13161
- }
13162
- };
13163
- })
13164
- );
13165
- return { derivedInfo, drawDetails };
13166
- }
13167
-
13168
- function processMatchUp({
13169
- relevantParticipantIdsMap,
13170
- participantFilters,
13171
- participantIdMap,
13172
- derivedDrawInfo,
13173
- eventDrawsCount,
13174
- drawDetails,
13175
- eventType,
13176
- matchUp
13177
- }) {
13178
- const {
13179
- collectionId,
13180
- collectionPosition,
13181
- drawId,
13182
- drawName,
13183
- eventId,
13184
- eventName,
13185
- finishingRound,
13186
- finishingPositionRange,
13187
- processCodes,
13188
- loserTo,
13189
- matchUpId,
13190
- matchUpType,
13191
- matchUpFormat,
13192
- matchUpStatus,
13193
- matchUpStatusCodes,
13194
- matchUpTieId,
13195
- roundName,
13196
- roundNumber,
13197
- roundPosition,
13198
- score,
13199
- sides,
13200
- stage,
13201
- stageSequence,
13202
- schedule,
13203
- structureName,
13204
- structureId,
13205
- tieFormat,
13206
- tieMatchUps,
13207
- tournamentId,
13208
- winnerTo,
13209
- winningSide
13210
- } = matchUp;
13211
- const targetParticipantIds = participantFilters?.participantIds;
13212
- const getRelevantParticipantIds = (participantId) => {
13213
- const relevantParticipantIds = participantId && relevantParticipantIdsMap[participantId] || [];
13214
- relevantParticipantIds.push(participantId);
13215
- return relevantParticipantIds.some(
13216
- (obj) => !targetParticipantIds || targetParticipantIds.includes(obj.relevantParticipantId)
13217
- ) ? relevantParticipantIds : [];
13218
- };
13219
- const { winner, loser } = finishingPositionRange || {};
13220
- const doublesTieParticipants = tieMatchUps?.length && tieMatchUps.filter(({ matchUpType: matchUpType2 }) => matchUpType2 === DOUBLES_MATCHUP).map(
13221
- ({ sides: sides2 }) => sides2.map(
13222
- ({ sideNumber, participantId, participant }) => sideNumber && participantId && {
13223
- sideNumber,
13224
- participantId,
13225
- participant
13226
- }
13227
- )
13228
- ).flat().filter(Boolean) || [];
13229
- if (eventType === TEAM_EVENT && matchUpType === DOUBLES_MATCHUP) {
13230
- const participants = (matchUp.sides?.filter(Boolean) || []).map(
13231
- ({ sideNumber, participantId, participant }) => sideNumber && participantId && {
13232
- sideNumber,
13233
- participantId,
13234
- participant
13235
- }
13236
- ).filter(Boolean);
13237
- doublesTieParticipants.push(...participants);
13238
- }
13239
- sides?.forEach((params) => {
13240
- const { participantId, sideNumber } = params;
13241
- if (!participantId)
13242
- return;
13243
- const { drawType, drawEntries } = drawDetails[drawId];
13244
- const participantScore = sideNumber === 1 ? score?.scoreStringSide1 : score?.scoreStringSide2;
13245
- const participantWon = winningSide && sideNumber === winningSide;
13246
- const opponent = matchUp.sides.find(
13247
- (side) => side.sideNumber === 3 - sideNumber
13248
- );
13249
- const opponentParticipantId = opponent?.participantId;
13250
- const relevantOpponents = opponentParticipantId && relevantParticipantIdsMap[opponentParticipantId] || [];
13251
- const finishingPositionRange2 = participantWon ? winner : loser;
13252
- const drawEntry = drawEntries.find(
13253
- (entry) => entry.participantId === participantId
13254
- );
13255
- const relevantParticipantIds = getRelevantParticipantIds(participantId);
13256
- const addedPairParticipantIds = [];
13257
- doublesTieParticipants?.filter((participant) => participant.sideNumber === sideNumber).forEach((p) => {
13258
- const participantId2 = p.participantId;
13259
- if (participantId2 && !addedPairParticipantIds.includes(participantId2)) {
13260
- relevantParticipantIds.push({
13261
- relevantParticipantId: participantId2,
13262
- participantType: PAIR
13263
- });
13264
- addedPairParticipantIds.push(participantId2);
13265
- }
13266
- });
13267
- const filteredRelevantParticipantIds = relevantParticipantIds.filter(
13268
- (opponent2) => {
13269
- return eventType !== TEAM_EVENT || eventType === TEAM_EVENT && [DOUBLES_MATCHUP, TEAM_MATCHUP].includes(matchUpType) && [PAIR, TEAM_PARTICIPANT].includes(opponent2.participantType) || eventType === TEAM_EVENT && [SINGLES_MATCHUP, DOUBLES_MATCHUP].includes(matchUpType) && [INDIVIDUAL].includes(opponent2.participantType);
13270
- }
13271
- );
13272
- filteredRelevantParticipantIds?.forEach(
13273
- ({ relevantParticipantId, participantType }) => {
13274
- const { entryStage, entryStatus, entryPosition } = drawEntry || {};
13275
- if (!participantIdMap[relevantParticipantId])
13276
- return;
13277
- if (!participantIdMap[relevantParticipantId].draws[drawId]) {
13278
- const positionAssignments = getDerivedPositionAssignments({
13279
- participantId: relevantParticipantId,
13280
- derivedDrawInfo,
13281
- drawId
13282
- });
13283
- const seedAssignments = getDerivedSeedAssignments({
13284
- participantId: relevantParticipantId,
13285
- derivedDrawInfo,
13286
- drawId
13287
- });
13288
- participantIdMap[relevantParticipantId].draws[drawId] = definedAttributes({
13289
- qualifyingDrawSize: derivedDrawInfo[drawId]?.qualifyingDrawSize,
13290
- drawSize: derivedDrawInfo[drawId]?.drawSize,
13291
- partnerParticipantIds: [],
13292
- positionAssignments,
13293
- seedAssignments,
13294
- entryPosition,
13295
- entryStatus,
13296
- entryStage,
13297
- drawName,
13298
- drawType,
13299
- eventId,
13300
- drawId
13301
- });
13302
- }
13303
- if (!participantIdMap[relevantParticipantId].events[eventId]) {
13304
- participantIdMap[relevantParticipantId].events[eventId] = {
13305
- partnerParticipantIds: [],
13306
- drawIds: [],
13307
- eventName,
13308
- eventId
13309
- };
13310
- }
13311
- const eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
13312
- if (eventDrawIds && !eventDrawIds?.includes(drawId)) {
13313
- participantIdMap[relevantParticipantId].events[eventId].drawIds.push(
13314
- drawId
13315
- );
13316
- }
13317
- let partnerParticipantId;
13318
- if (participantType === INDIVIDUAL && matchUpType === DOUBLES_MATCHUP) {
13319
- const relevantParticipantInfo = filteredRelevantParticipantIds.find(
13320
- (participantInfo) => {
13321
- return participantInfo.relevantParticipantId !== relevantParticipantId && participantInfo.participantType === INDIVIDUAL;
13322
- }
13323
- );
13324
- partnerParticipantId = relevantParticipantInfo?.relevantParticipantId;
13325
- }
13326
- const filteredRelevantOpponents = relevantOpponents?.filter(
13327
- (opponent2) => matchUpType === TEAM_MATCHUP && participantType === TEAM_PARTICIPANT && opponent2.participantType === TEAM_PARTICIPANT || matchUpType === SINGLES_MATCHUP && opponent2.participantType === INDIVIDUAL || matchUpType === DOUBLES_MATCHUP && (participantType === INDIVIDUAL ? [INDIVIDUAL, PAIR].includes(opponent2.participantType) : (
13328
- // for PAIR participants only show PAIR opponenents
13329
- opponent2.participantType === PAIR
13330
- ))
13331
- ) || [];
13332
- filteredRelevantOpponents.forEach(
13333
- ({
13334
- relevantParticipantId: opponentParticipantId2,
13335
- participantType: opponentParticipantType
13336
- }) => {
13337
- if (!participantIdMap[relevantParticipantId].opponents) {
13338
- participantIdMap[relevantParticipantId].opponents = {};
13339
- }
13340
- participantIdMap[relevantParticipantId].opponents[opponentParticipantId2] = {
13341
- eventId,
13342
- drawId,
13343
- matchUpId,
13344
- participantType: opponentParticipantType,
13345
- participantId: opponentParticipantId2
13346
- };
13347
- }
13348
- );
13349
- const opponentParticipantInfo = filteredRelevantOpponents.map(
13350
- ({ relevantParticipantId: relevantParticipantId2, participantType: participantType2 }) => ({
13351
- participantId: relevantParticipantId2,
13352
- participantType: participantType2
13353
- })
13354
- );
13355
- const includeMatchUp = matchUpType !== TEAM_MATCHUP && [INDIVIDUAL, PAIR].includes(participantType) || matchUpType === TEAM_MATCHUP && participantType === TEAM_PARTICIPANT;
13356
- if (includeMatchUp)
13357
- participantIdMap[relevantParticipantId].matchUps[matchUpId] = definedAttributes({
13358
- collectionId,
13359
- collectionPosition,
13360
- drawId,
13361
- eventId,
13362
- eventType,
13363
- eventDrawsCount,
13364
- finishingRound,
13365
- finishingPositionRange: finishingPositionRange2,
13366
- loserTo,
13367
- matchUpId,
13368
- matchUpType,
13369
- matchUpFormat,
13370
- matchUpStatus,
13371
- matchUpStatusCodes,
13372
- matchUpTieId,
13373
- opponentParticipantInfo,
13374
- participantWon,
13375
- partnerParticipantId,
13376
- perspectiveScoreString: participantScore,
13377
- processCodes,
13378
- roundName,
13379
- roundNumber,
13380
- roundPosition,
13381
- schedule,
13382
- score,
13383
- sides,
13384
- stage,
13385
- stageSequence,
13386
- structureName,
13387
- structureId,
13388
- tieFormat,
13389
- tournamentId,
13390
- winnerTo,
13391
- winningSide
13392
- });
13393
- if (partnerParticipantId) {
13394
- participantIdMap[relevantParticipantId].events[eventId].partnerParticipantIds.push(partnerParticipantId);
13395
- participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantIds.push(partnerParticipantId);
13396
- participantIdMap[relevantParticipantId].events[eventId].partnerParticipantId = partnerParticipantId;
13397
- participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantId = partnerParticipantId;
13398
- }
13399
- if (winningSide) {
13400
- if (participantWon) {
13401
- participantIdMap[relevantParticipantId].wins++;
13402
- } else {
13403
- participantIdMap[relevantParticipantId].losses++;
13404
- }
13405
- }
13406
- }
13407
- );
13408
- });
13409
- if (Array.isArray(matchUp.potentialParticipants)) {
13410
- const potentialParticipantIds = getParticipantIds(
13411
- matchUp.potentialParticipants.flat()
13412
- );
13413
- potentialParticipantIds?.forEach((participantId) => {
13414
- const relevantParticipantIds = getRelevantParticipantIds(participantId);
13415
- relevantParticipantIds?.forEach(({ relevantParticipantId }) => {
13416
- participantIdMap[relevantParticipantId].potentialMatchUps[matchUpId] = definedAttributes({
13417
- drawId,
13418
- eventId,
13419
- eventType,
13420
- matchUpId,
13421
- matchUpType,
13422
- matchUpFormat,
13423
- roundName,
13424
- roundNumber,
13425
- roundPosition,
13426
- schedule,
13427
- tieFormat,
13428
- structureName,
13429
- tournamentId,
13430
- potential: true
13431
- });
13432
- });
13433
- });
13434
- }
13435
- }
13436
-
13437
- function addParticipantContext(params) {
13438
- const participantIdsWithConflicts = [];
13439
- const eventsPublishStatuses = {};
13440
- const derivedDrawInfo = {};
13441
- const participantIdMap = {};
13442
- const initializeParticipantId = (participantId) => {
13443
- if (!participantIdMap[participantId])
13444
- participantIdMap[participantId] = {
13445
- groupParticipantIds: [],
13446
- teamParticipantIds: [],
13447
- pairParticipantIds: [],
13448
- potentialMatchUps: {},
13449
- scheduleItems: [],
13450
- opponents: {},
13451
- matchUps: {},
13452
- events: {},
13453
- groups: [],
13454
- teams: [],
13455
- draws: {},
13456
- losses: 0,
13457
- wins: 0
13458
- };
13459
- };
13460
- const { tournamentRecord, participantFilters, allTournamentParticipants } = params;
13461
- const { relevantParticipantIdsMap } = getRelevantParticipantIdsMap({
13462
- processParticipantId: initializeParticipantId,
13463
- tournamentRecord
13464
- });
13465
- const targetParticipantIds = participantFilters?.participantIds;
13466
- const getRelevantParticipantIds = (participantId) => {
13467
- const relevantParticipantIds = participantId && relevantParticipantIdsMap[participantId] || [];
13468
- relevantParticipantIds.push(participantId);
13469
- return relevantParticipantIds.some(
13470
- (obj) => !targetParticipantIds || targetParticipantIds.includes(obj.relevantParticipantId)
13471
- ) ? relevantParticipantIds : [];
13472
- };
13473
- params.withGroupings && allTournamentParticipants.forEach((participant) => {
13474
- if (participant.participantType === GROUP) {
13475
- const groupParticipantId = participant.participantId;
13476
- participant?.individualParticipantIds?.forEach((participantId) => {
13477
- if (!participantIdMap[participantId].groupParticipantIds.includes(
13478
- groupParticipantId
13479
- )) {
13480
- participantIdMap[participantId].groupParticipantIds.push(
13481
- groupParticipantId
13482
- );
13483
- participantIdMap[participantId].groups.push({
13484
- participantRoleResponsibilities: participant.participantRoleResponsibilities,
13485
- participantOtherName: participant.participantOtherName,
13486
- participantName: participant.participantName,
13487
- participantId: participant.participantId
13488
- });
13489
- }
13490
- });
13491
- }
13492
- if (participant.participantType === TEAM$1) {
13493
- const teamParticipantId = participant.participantId;
13494
- participant?.individualParticipantIds?.forEach((participantId) => {
13495
- if (!participantIdMap[participantId]?.teamParticipantIds?.includes(
13496
- teamParticipantId
13497
- )) {
13498
- participantIdMap[participantId]?.teamParticipantIds.push(
13499
- teamParticipantId
13500
- );
13501
- participantIdMap[participantId]?.teams.push({
13502
- participantRoleResponsibilities: participant.participantRoleResponsibilities,
13503
- participantOtherName: participant.participantOtherName,
13504
- participantName: participant.participantName,
13505
- participantId: participant.participantId,
13506
- teamId: participant.teamId
13507
- });
13508
- }
13509
- });
13510
- }
13511
- if (participant.participantType === PAIR) {
13512
- const pairParticipantId = participant.participantId;
13513
- participant?.individualParticipantIds?.forEach((participantId) => {
13514
- if (participantIdMap[participantId] && !participantIdMap[participantId].pairParticipantIds.includes(
13515
- pairParticipantId
13516
- )) {
13517
- participantIdMap[participantId].pairParticipantIds.push(
13518
- pairParticipantId
13519
- );
13520
- }
13521
- });
13522
- }
13523
- });
13524
- if (params.withMatchUps) {
13525
- getMatchUpDependencies({ tournamentRecord });
13526
- }
13527
- if (params.withScheduleItems || params.scheduleAnalysis || params.withStatistics || params.withOpponents || params.withMatchUps || params.withSeeding || params.withEvents || params.withDraws) {
13528
- params.tournamentEvents?.forEach((rawEvent) => {
13529
- const event = makeDeepCopy(rawEvent, true, true);
13530
- const flightProfile = getFlightProfile({ event }).flightProfile;
13531
- const eventDrawsCount = flightProfile?.flights?.length || event.drawDefinitions?.length || 0;
13532
- (event.drawDefinitions || []).forEach((drawDefinition, i) => {
13533
- if (event?.eventType === TEAM$1) {
13534
- const { extension } = findExtension$2({
13535
- element: rawEvent.drawDefinitions[i],
13536
- // rawEvent because deepCopy has converted extensions
13537
- name: LINEUPS
13538
- });
13539
- if (extension)
13540
- drawDefinition.extensions = [extension];
13541
- }
13542
- });
13543
- const { eventId, eventName, eventType, category } = event;
13544
- const eventInfo = { eventId, eventName, eventType, category };
13545
- const extensionKeys = event && Object.keys(event).filter((key) => key.startsWith("_"));
13546
- extensionKeys?.forEach(
13547
- (extensionKey) => eventInfo[extensionKey] = event[extensionKey]
13548
- );
13549
- const eventEntries = event.entries || [];
13550
- const itemType = `${PUBLISH}.${STATUS$1}`;
13551
- const { timeItem } = getEventTimeItem({
13552
- itemType,
13553
- event
13554
- });
13555
- if (timeItem?.itemValue?.PUBLIC) {
13556
- const { drawIds: publishedDrawIds = [], seeding } = timeItem.itemValue.PUBLIC || {};
13557
- const publishedSeeding = {
13558
- published: void 0,
13559
- // seeding can be present for all entries in an event when no flights have been defined
13560
- seedingScaleNames: [],
13561
- drawIds: []
13562
- // seeding can be specific to drawIds
13563
- };
13564
- if (seeding)
13565
- Object.assign(publishedSeeding, timeItem.itemValue.PUBLIC.seeding);
13566
- eventsPublishStatuses[eventId] = {
13567
- publishedDrawIds,
13568
- publishedSeeding
13569
- };
13570
- }
13571
- const disallowedConstants = [
13572
- ...Object.values(extensionConstants)
13573
- ];
13574
- const disallowedKeys = disallowedConstants.map(
13575
- (constant) => `_${constant}`
13576
- );
13577
- const filteredEventInfo = eventInfo && Object.keys(eventInfo).filter((key) => !disallowedKeys.includes(key)).reduce((obj, key) => {
13578
- obj[key] = eventInfo[key];
13579
- return obj;
13580
- }, {});
13581
- eventEntries?.filter((entry) => entry?.participantId).forEach((entry) => {
13582
- const { participantId, entryStage, entryStatus, entryPosition } = entry;
13583
- const relevantParticipantIds = getRelevantParticipantIds(participantId);
13584
- relevantParticipantIds?.forEach(({ relevantParticipantId }) => {
13585
- if (!participantIdMap[relevantParticipantId])
13586
- initializeParticipantId(relevantParticipantId);
13587
- participantIdMap[relevantParticipantId].events[eventId] = {
13588
- ...filteredEventInfo,
13589
- partnerParticipantIds: [],
13590
- entryPosition,
13591
- entryStatus,
13592
- entryStage,
13593
- drawIds: [],
13594
- eventId
13595
- };
13596
- });
13597
- });
13598
- const addDrawData = ({ drawEntry, drawId }) => {
13599
- const { participantId, entryStage, entryStatus, entryPosition } = drawEntry;
13600
- const relevantParticipantIds = getRelevantParticipantIds(participantId);
13601
- relevantParticipantIds?.forEach(({ relevantParticipantId }) => {
13602
- if (!participantIdMap[relevantParticipantId].events[eventId]) {
13603
- participantIdMap[relevantParticipantId].events[eventId] = {
13604
- ...filteredEventInfo,
13605
- partnerParticipantIds: [],
13606
- entryPosition,
13607
- entryStatus,
13608
- entryStage,
13609
- drawIds: [],
13610
- eventId
13611
- };
13612
- }
13613
- if (!participantIdMap[relevantParticipantId].draws[drawId]) {
13614
- const positionAssignments = getDerivedPositionAssignments({
13615
- participantId: relevantParticipantId,
13616
- derivedDrawInfo,
13617
- drawId
13618
- });
13619
- const seedAssignments = getDerivedSeedAssignments({
13620
- participantId: relevantParticipantId,
13621
- derivedDrawInfo,
13622
- drawId
13623
- });
13624
- participantIdMap[relevantParticipantId].draws[drawId] = definedAttributes({
13625
- qualifyingDrawSize: derivedDrawInfo[drawId]?.qualifyingDrawSize,
13626
- drawSize: derivedDrawInfo[drawId]?.drawSize,
13627
- partnerParticipantIds: [],
13628
- positionAssignments,
13629
- eventDrawsCount,
13630
- seedAssignments,
13631
- entryPosition,
13632
- entryStatus,
13633
- entryStage,
13634
- eventId,
13635
- drawId
13636
- });
13637
- }
13638
- const eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
13639
- if (eventDrawIds && !eventDrawIds?.includes(drawId)) {
13640
- participantIdMap[relevantParticipantId].events[eventId].drawIds.push(drawId);
13641
- }
13642
- });
13643
- };
13644
- const drawIdsWithDefinitions = event.drawDefinitions?.map(({ drawId }) => drawId) || [];
13645
- eventInfo._flightProfile?.flights?.forEach((flight) => {
13646
- const { drawId, drawEntries } = flight;
13647
- if (!drawIdsWithDefinitions.includes(drawId)) {
13648
- drawEntries?.forEach(
13649
- (drawEntry) => addDrawData({ drawEntry, drawId })
13650
- );
13651
- }
13652
- });
13653
- const { drawDetails, derivedInfo } = getDrawDetails({
13654
- eventEntries,
13655
- event
13656
- });
13657
- Object.assign(derivedDrawInfo, derivedInfo);
13658
- if (event.eventType === TEAM$1 || // for TEAM events some individual attributes can only be derived by processing
13659
- params.withScheduleItems || params.scheduleAnalysis || params.withStatistics || params.withOpponents || params.withMatchUps || params.withDraws) {
13660
- const matchUps = allEventMatchUps({
13661
- afterRecoveryTimes: params.scheduleAnalysis,
13662
- participants: allTournamentParticipants,
13663
- nextMatchUps: true,
13664
- tournamentRecord,
13665
- inContext: true,
13666
- event
13667
- })?.matchUps;
13668
- matchUps?.forEach(
13669
- (matchUp) => processMatchUp({
13670
- relevantParticipantIdsMap,
13671
- participantFilters,
13672
- participantIdMap,
13673
- derivedDrawInfo,
13674
- eventDrawsCount,
13675
- drawDetails,
13676
- eventType,
13677
- matchUp
13678
- })
13679
- );
13680
- }
13681
- });
13682
- }
13683
- params.tournamentParticipants?.forEach((participant) => {
13684
- const { scheduleConflicts, scheduleItems } = annotateParticipant({
13685
- ...params,
13686
- eventsPublishStatuses,
13687
- participantIdMap,
13688
- derivedDrawInfo,
13689
- participant
13690
- });
13691
- if (params.withSignInStatus) {
13692
- const { timeItem } = getTimeItem({
13693
- itemType: SIGN_IN_STATUS,
13694
- element: participant
13695
- });
13696
- participant.signedIn = timeItem?.itemValue === SIGNED_IN;
13697
- }
13698
- if (params.withScheduleItems) {
13699
- participant.scheduleItems = scheduleItems;
13700
- }
13701
- if (params.scheduleAnalysis) {
13702
- participant.scheduleConflicts = scheduleConflicts;
13703
- if (scheduleConflicts?.length && !participantIdsWithConflicts.includes(participant.participantId)) {
13704
- participantIdsWithConflicts.push(participant.participantId);
13705
- }
13706
- }
13707
- if (params.withGroupings !== false) {
13708
- const participantAttributes = participantIdMap[participant.participantId];
13709
- participant.groupParticipantIds = participantAttributes?.groupParticipantIds;
13710
- participant.pairParticipantIds = participantAttributes?.pairParticipantIds;
13711
- participant.teamParticipantIds = participantAttributes?.teamParticipantIds;
13712
- participant.groups = participantAttributes?.groups;
13713
- participant.teams = participantAttributes?.teams;
13714
- }
13715
- if (params.withTeamMatchUps) ;
13716
- });
13717
- return { participantIdsWithConflicts, eventsPublishStatuses };
13718
- }
13719
-
13720
- function getTournamentParticipants(params) {
13721
- const {
13722
- participantFilters = {},
13723
- convertExtensions,
13724
- policyDefinitions,
13725
- withScheduleItems,
13726
- scheduleAnalysis,
13727
- withSignInStatus,
13728
- withTeamMatchUps,
13729
- // not implemented
13730
- tournamentRecord,
13731
- usePublishState,
13732
- withScaleValues,
13733
- withStatistics,
13734
- withGroupings,
13735
- withOpponents,
13736
- withMatchUps,
13737
- withSeeding,
13738
- withEvents,
13739
- withDraws,
13740
- inContext,
13741
- withISO2,
13742
- withIOC
13743
- } = params;
13744
- if (!tournamentRecord)
13745
- return { error: MISSING_TOURNAMENT_RECORD };
13746
- if (!tournamentRecord.participants)
13747
- return { error: MISSING_PARTICIPANTS };
13748
- const allTournamentParticipants = tournamentRecord.participants.map(
13749
- // (participant) => makeDeepCopy(participant, convertExtensions, true)
13750
- (participant) => makeDeepCopy(participant, convertExtensions)
13751
- // removed until Mongo/Mongoose issues resolved
13752
- );
13753
- if (typeof participantFilters !== "object")
13754
- return { error: INVALID_OBJECT, participantFilters };
13755
- if (inContext) {
13756
- allTournamentParticipants?.forEach((participant) => {
13757
- if ([PAIR, TEAM$2, GROUP].includes(participant.participantType)) {
13758
- participant.individualParticipants = participant.individualParticipantIds?.map((participantId) => {
13759
- const targetParticipant = tournamentRecord.participants.find(
13760
- (p) => p.participantId === participantId
13761
- );
13762
- const individualParticipant = makeDeepCopy(
13763
- targetParticipant,
13764
- convertExtensions,
13765
- true
13766
- );
13767
- if (withScaleValues) {
13768
- const { ratings, rankings } = getScaleValues({
13769
- participant: individualParticipant
13770
- });
13771
- individualParticipant.ratings = ratings;
13772
- individualParticipant.rankings = rankings;
13773
- }
13774
- if (withIOC || withISO2)
13775
- addNationalityCode({
13776
- participant: individualParticipant,
13777
- withISO2,
13778
- withIOC
13779
- });
13780
- return individualParticipant;
13781
- });
13782
- }
13783
- });
13784
- }
13785
- let tournamentParticipants = participantFilters ? filterParticipants({
13786
- participants: allTournamentParticipants,
13787
- participantFilters,
13788
- tournamentRecord
13789
- }) : allTournamentParticipants;
13790
- let participantIdsWithConflicts, eventsPublishStatuses;
13791
- const addContext = withScheduleItems || withSignInStatus || scheduleAnalysis || withScaleValues || withStatistics || withGroupings || withOpponents || withMatchUps || withSeeding || withEvents || withDraws || withISO2 || withIOC;
13792
- if (addContext) {
13793
- const result = addParticipantContext({
13794
- tournamentEvents: tournamentRecord.events,
13795
- allTournamentParticipants,
13796
- tournamentParticipants,
13797
- participantFilters,
13798
- withScheduleItems,
13799
- withSignInStatus,
13800
- tournamentRecord,
13801
- scheduleAnalysis,
13802
- withTeamMatchUps,
13803
- usePublishState,
13804
- withScaleValues,
13805
- withStatistics,
13806
- withGroupings,
13807
- withOpponents,
13808
- withMatchUps,
13809
- withSeeding,
13810
- withEvents,
13811
- withDraws,
13812
- withISO2,
13813
- withIOC
13814
- });
13815
- participantIdsWithConflicts = result?.participantIdsWithConflicts;
13816
- eventsPublishStatuses = result?.eventsPublishStatuses;
13817
- }
13818
- const participantAttributes = policyDefinitions?.[POLICY_TYPE_PARTICIPANT];
13819
- if (participantAttributes?.participant) {
13820
- tournamentParticipants = tournamentParticipants.map(
13821
- (participant) => attributeFilter({
13822
- template: participantAttributes.participant,
13823
- source: participant
13824
- })
13825
- );
13826
- }
13827
- return {
13828
- participantIdsWithConflicts,
13829
- tournamentParticipants,
13830
- eventsPublishStatuses
13831
- };
13832
- }
13833
-
13834
12854
  function deepMerge(existing, incoming, arrayMerge) {
13835
12855
  if (!existing && incoming)
13836
12856
  return incoming;
@@ -13871,15 +12891,19 @@ function getCompetitionParticipants(params) {
13871
12891
  let competitionParticipants = [];
13872
12892
  const participantIdsWithConflicts = [];
13873
12893
  const competitionParticipantIds = [];
12894
+ const mappedMatchUps = {};
13874
12895
  for (const tournamentRecord of Object.values(tournamentRecords)) {
13875
12896
  const {
13876
- tournamentParticipants,
13877
- participantIdsWithConflicts: idsWithConflicts
13878
- } = getTournamentParticipants({
12897
+ participants,
12898
+ participantIdsWithConflicts: idsWithConflicts,
12899
+ mappedMatchUps: matchUpsMap
12900
+ } = getParticipants({
13879
12901
  tournamentRecord,
13880
12902
  ...params
13881
12903
  });
13882
- for (const tournamentParticipant of tournamentParticipants) {
12904
+ if (matchUpsMap)
12905
+ Object.assign(mappedMatchUps, matchUpsMap);
12906
+ for (const tournamentParticipant of participants ?? []) {
13883
12907
  const { participantId } = tournamentParticipant;
13884
12908
  if (!competitionParticipantIds.includes(participantId)) {
13885
12909
  competitionParticipantIds.push(participantId);
@@ -13895,13 +12919,18 @@ function getCompetitionParticipants(params) {
13895
12919
  participantIdsWithConflicts.push(participantId);
13896
12920
  });
13897
12921
  }
13898
- return { competitionParticipants, participantIdsWithConflicts, ...SUCCESS };
12922
+ return {
12923
+ competitionParticipants,
12924
+ participantIdsWithConflicts,
12925
+ mappedMatchUps,
12926
+ ...SUCCESS
12927
+ };
13899
12928
  }
13900
12929
  function publicFindParticipant({
13901
- policyDefinitions,
13902
12930
  tournamentRecords,
12931
+ policyDefinitions,
12932
+ contextProfile,
13903
12933
  participantId,
13904
- inContext,
13905
12934
  personId
13906
12935
  }) {
13907
12936
  if (!tournamentRecords)
@@ -13911,15 +12940,15 @@ function publicFindParticipant({
13911
12940
  let participant, tournamentId;
13912
12941
  for (const tournamentRecord of Object.values(tournamentRecords)) {
13913
12942
  tournamentId = tournamentRecord.tournamentId;
13914
- const { tournamentParticipants } = getTournamentParticipants({
12943
+ const participants = getParticipants({
13915
12944
  policyDefinitions,
13916
- tournamentRecord,
13917
- inContext
13918
- });
12945
+ tournamentRecord
12946
+ }).participants ?? [];
13919
12947
  participant = findParticipant({
13920
- tournamentParticipants,
12948
+ tournamentParticipants: participants,
13921
12949
  internalUse: true,
13922
12950
  policyDefinitions,
12951
+ contextProfile,
13923
12952
  participantId,
13924
12953
  personId
13925
12954
  });
@@ -13934,14 +12963,12 @@ function getParticipantScaleItem({
13934
12963
  policyDefinitions,
13935
12964
  scaleAttributes,
13936
12965
  participantId,
13937
- inContext,
13938
12966
  personId
13939
12967
  }) {
13940
12968
  let result = publicFindParticipant({
13941
12969
  tournamentRecords,
13942
12970
  policyDefinitions,
13943
12971
  participantId,
13944
- inContext,
13945
12972
  personId
13946
12973
  });
13947
12974
  if (result.error)