tods-competition-factory 0.64.2 → 0.65.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.
@@ -18057,9 +18057,9 @@ function getAvailableAdHocParticipantIds({
18057
18057
  drawPosition,
18058
18058
  participantId
18059
18059
  }) => roundDrawPositions.includes(drawPosition) && participantId).map(getParticipantId);
18060
- const enteredParticipantIds = drawDefinition.entries.filter(({
18060
+ const enteredParticipantIds = (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries.filter(({
18061
18061
  entryStatus
18062
- }) => [DIRECT_ACCEPTANCE, ORGANISER_ACCEPTANCE, WILDCARD].includes(entryStatus)).map(getParticipantId); // AdHoc available participants are those entered in the draw who are not assigned to the target round
18062
+ }) => [DIRECT_ACCEPTANCE, ORGANISER_ACCEPTANCE, WILDCARD].includes(entryStatus)).map(getParticipantId)) || []; // AdHoc available participants are those entered in the draw who are not assigned to the target round
18063
18063
 
18064
18064
  const availableParticipantIds = enteredParticipantIds.filter(participantId => !roundAssignedParticipantIds.includes(participantId));
18065
18065
  return availableParticipantIds;
@@ -28040,7 +28040,7 @@ const scheduleGovernor$1 = {
28040
28040
  };
28041
28041
 
28042
28042
  function factoryVersion() {
28043
- return '0.64.2';
28043
+ return '0.65.0';
28044
28044
  }
28045
28045
 
28046
28046
  function attachPolicies$2({
@@ -34633,7 +34633,7 @@ function getAssignedParticipantIds({
34633
34633
  function refreshEntryPositions({
34634
34634
  entries = []
34635
34635
  } = {}) {
34636
- const stagedEntries = entries.reduce((stages, entry) => {
34636
+ const stagedEntries = entries.filter(Boolean).reduce((stages, entry) => {
34637
34637
  const {
34638
34638
  entryStage,
34639
34639
  entryStatus
@@ -34845,6 +34845,8 @@ function modifyEntriesStatus({
34845
34845
  return true;
34846
34846
  });
34847
34847
  (_event$drawDefinition4 = event.drawDefinitions) === null || _event$drawDefinition4 === void 0 ? void 0 : _event$drawDefinition4.every(drawDefinition => {
34848
+ var _drawDefinition$entri2;
34849
+
34848
34850
  const result = updateEntryStatus(drawDefinition.entries);
34849
34851
 
34850
34852
  if (result.error) {
@@ -34852,7 +34854,7 @@ function modifyEntriesStatus({
34852
34854
  return false;
34853
34855
  }
34854
34856
 
34855
- drawDefinition.entries = drawDefinition.entries.filter(({
34857
+ drawDefinition.entries = (_drawDefinition$entri2 = drawDefinition.entries) === null || _drawDefinition$entri2 === void 0 ? void 0 : _drawDefinition$entri2.filter(({
34856
34858
  participantId
34857
34859
  }) => !participantIds.includes(participantId));
34858
34860
  return true;
@@ -35189,8 +35191,8 @@ function participantInEntries({
35189
35191
  function addDrawEntry({
35190
35192
  entryStatus = DIRECT_ACCEPTANCE,
35191
35193
  entryStage = MAIN,
35192
- entryPosition,
35193
35194
  drawDefinition,
35195
+ entryPosition,
35194
35196
  participantId,
35195
35197
  participant
35196
35198
  }) {
@@ -35222,7 +35224,7 @@ function addDrawEntry({
35222
35224
  };
35223
35225
  }
35224
35226
 
35225
- participantId = participantId || participant && participant.participantId;
35227
+ participantId = participantId || (participant === null || participant === void 0 ? void 0 : participant.participantId);
35226
35228
  if (!participantId) return {
35227
35229
  error: MISSING_PARTICIPANT_ID
35228
35230
  };
@@ -35344,7 +35346,7 @@ function addDrawEntries$1({
35344
35346
  };
35345
35347
  }
35346
35348
 
35347
- participantIds.forEach(participantId => {
35349
+ participantIds.filter(Boolean).forEach(participantId => {
35348
35350
  const entry = Object.assign({
35349
35351
  participantId
35350
35352
  }, {
@@ -50868,222 +50870,6 @@ function generateFlights({
50868
50870
  };
50869
50871
  }
50870
50872
 
50871
- function modifyTournamentRecord({
50872
- matchUpStatusProfile,
50873
- completeAllMatchUps,
50874
- participantsProfile,
50875
- autoEntryPositions,
50876
- randomWinningSide,
50877
- tournamentRecord,
50878
- eventProfiles,
50879
- uuids
50880
- }) {
50881
- if (!tournamentRecord) return {
50882
- error: MISSING_TOURNAMENT_RECORD
50883
- };
50884
- const allUniqueParticipantIds = [];
50885
- const drawIds = [];
50886
- eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
50887
- const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
50888
-
50889
- if (event !== null && event !== void 0 && event.gender) {
50890
- eventProfile.gender = event.gender;
50891
- }
50892
- });
50893
- const result = addTournamentParticipants({
50894
- startDate: tournamentRecord.startDate,
50895
- participantsProfile,
50896
- tournamentRecord,
50897
- eventProfiles,
50898
- // drawProfiles,
50899
- uuids
50900
- });
50901
- if (!result.success) return result;
50902
-
50903
- if (eventProfiles) {
50904
- for (const eventProfile of eventProfiles) {
50905
- let {
50906
- ratingsParameters
50907
- } = eventProfile;
50908
- const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
50909
- if (!event) return {
50910
- error: EVENT_NOT_FOUND
50911
- };
50912
- const {
50913
- gender,
50914
- category,
50915
- eventType
50916
- } = event;
50917
- const {
50918
- drawProfiles
50919
- } = eventProfile;
50920
- const eventParticipantType = eventType === SINGLES ? INDIVIDUAL : eventType === DOUBLES ? PAIR : eventType;
50921
-
50922
- if (drawProfiles) {
50923
- const {
50924
- stageParticipantsCount,
50925
- uniqueParticipantsCount,
50926
- uniqueParticipantStages
50927
- } = getStageParticipantsCount({
50928
- drawProfiles,
50929
- category,
50930
- gender
50931
- });
50932
- const {
50933
- uniqueDrawParticipants = [],
50934
- uniqueParticipantIds = []
50935
- } = uniqueParticipantStages ? generateEventParticipants({
50936
- event: {
50937
- eventType,
50938
- category,
50939
- gender
50940
- },
50941
- uniqueParticipantsCount,
50942
- participantsProfile,
50943
- ratingsParameters,
50944
- tournamentRecord,
50945
- eventProfile,
50946
- uuids
50947
- }) : {};
50948
- allUniqueParticipantIds.push(...uniqueParticipantIds);
50949
- const {
50950
- stageParticipants
50951
- } = getStageParticipants({
50952
- targetParticipants: tournamentRecord.participants || [],
50953
- allUniqueParticipantIds,
50954
- stageParticipantsCount,
50955
- eventParticipantType
50956
- });
50957
- let result = generateFlights({
50958
- uniqueDrawParticipants,
50959
- autoEntryPositions,
50960
- stageParticipants,
50961
- tournamentRecord,
50962
- drawProfiles,
50963
- category,
50964
- gender,
50965
- event
50966
- });
50967
- if (result.error) return result;
50968
- result = generateFlightDrawDefinitions({
50969
- matchUpStatusProfile,
50970
- completeAllMatchUps,
50971
- randomWinningSide,
50972
- tournamentRecord,
50973
- drawProfiles,
50974
- event
50975
- });
50976
- if (result.error) return result;
50977
- drawIds.push(...result.drawIds);
50978
- }
50979
- }
50980
- }
50981
-
50982
- return { ...SUCCESS,
50983
- drawIds
50984
- };
50985
- }
50986
-
50987
- const amendsGovernor = {
50988
- anonymizeTournamentRecord,
50989
- modifyTournamentRecord
50990
- };
50991
-
50992
- function generateSchedulingProfile({
50993
- schedulingProfile,
50994
- tournamentRecord
50995
- }) {
50996
- if (typeof schedulingProfile !== 'object') return {
50997
- error: INVALID_VALUES
50998
- };
50999
- const containedStructures = getContainedStructures({
51000
- tournamentRecord
51001
- }).containedStructures;
51002
- const {
51003
- matchUps
51004
- } = allTournamentMatchUps({
51005
- tournamentRecord
51006
- });
51007
- const {
51008
- tournamentId
51009
- } = tournamentRecord;
51010
- const scheduledRounds = [];
51011
-
51012
- for (const dateProfile of schedulingProfile) {
51013
- const {
51014
- scheduleDate,
51015
- venues = []
51016
- } = dateProfile;
51017
-
51018
- for (const venue of venues) {
51019
- const {
51020
- rounds,
51021
- venueId
51022
- } = venue;
51023
-
51024
- for (const round of rounds) {
51025
- const {
51026
- drawId,
51027
- winnerFinishingPositionRange,
51028
- roundSegment
51029
- } = round;
51030
- const targetMatchUps = matchUps.filter(matchUp => {
51031
- var _matchUp$finishingPos;
51032
-
51033
- const targetRange = (winnerFinishingPositionRange === null || winnerFinishingPositionRange === void 0 ? void 0 : winnerFinishingPositionRange.indexOf('-')) > 0 && winnerFinishingPositionRange.split('-').map(x => +x);
51034
- const range = (_matchUp$finishingPos = matchUp.finishingPositionRange) === null || _matchUp$finishingPos === void 0 ? void 0 : _matchUp$finishingPos.winner;
51035
- const target = matchUp.drawId === drawId && (!round.roundNumber || matchUp.roundNumber === round.roundNumber) && (!range || !targetRange || intersection(range, targetRange).length === 2);
51036
- return target;
51037
- });
51038
- const targetMatchUp = targetMatchUps[0];
51039
-
51040
- if (targetMatchUp) {
51041
- const {
51042
- eventId,
51043
- roundNumber,
51044
- drawName,
51045
- structureName,
51046
- roundName
51047
- } = targetMatchUp;
51048
- let structureId = targetMatchUp.structureId;
51049
-
51050
- if (roundNumber && !winnerFinishingPositionRange) {
51051
- structureId = Object.keys(containedStructures).find(containingStructureId => containedStructures[containingStructureId].includes(structureId));
51052
- }
51053
-
51054
- const roundToSchedule = {
51055
- tournamentId,
51056
- eventId,
51057
- drawId,
51058
- structureId,
51059
- roundNumber,
51060
- roundSegment
51061
- };
51062
- let result = addSchedulingProfileRound({
51063
- tournamentRecords: {
51064
- [tournamentId]: tournamentRecord
51065
- },
51066
- scheduleDate,
51067
- venueId,
51068
- round: roundToSchedule
51069
- });
51070
- if (result.error) return result;
51071
- scheduledRounds.push({
51072
- drawName,
51073
- structureName,
51074
- roundName,
51075
- ...roundToSchedule
51076
- });
51077
- }
51078
- }
51079
- }
51080
- }
51081
-
51082
- return {
51083
- scheduledRounds
51084
- };
51085
- }
51086
-
51087
50873
  function generateEventWithFlights({
51088
50874
  allUniqueParticipantIds,
51089
50875
  matchUpStatusProfile,
@@ -51648,6 +51434,322 @@ function generateVenues({
51648
51434
  return venueIds;
51649
51435
  }
51650
51436
 
51437
+ function modifyTournamentRecord({
51438
+ ratingsParameters: ratingsParameters$1 = ratingsParameters,
51439
+ matchUpStatusProfile,
51440
+ completeAllMatchUps,
51441
+ participantsProfile,
51442
+ autoEntryPositions,
51443
+ randomWinningSide,
51444
+ schedulingProfile,
51445
+ tournamentRecord,
51446
+ eventProfiles,
51447
+ venueProfiles,
51448
+ autoSchedule,
51449
+ drawProfiles,
51450
+ goesTo,
51451
+ uuids
51452
+ }) {
51453
+ if (!tournamentRecord) return {
51454
+ error: MISSING_TOURNAMENT_RECORD
51455
+ };
51456
+ const allUniqueParticipantIds = [];
51457
+ const eventIds = [];
51458
+ const drawIds = [];
51459
+ eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
51460
+ const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
51461
+
51462
+ if (event !== null && event !== void 0 && event.gender) {
51463
+ eventProfile.gender = event.gender;
51464
+ }
51465
+ });
51466
+ const result = addTournamentParticipants({
51467
+ startDate: tournamentRecord.startDate,
51468
+ participantsProfile,
51469
+ tournamentRecord,
51470
+ eventProfiles,
51471
+ drawProfiles,
51472
+ uuids
51473
+ });
51474
+ if (!result.success) return result;
51475
+
51476
+ if (eventProfiles) {
51477
+ for (const eventProfile of eventProfiles) {
51478
+ let {
51479
+ ratingsParameters
51480
+ } = eventProfile;
51481
+ const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
51482
+
51483
+ if (!event) {
51484
+ const {
51485
+ error,
51486
+ eventId,
51487
+ drawIds: generatedDrawIds,
51488
+ uniqueParticipantIds
51489
+ } = generateEventWithFlights({
51490
+ startDate: tournamentRecord.startDate,
51491
+ allUniqueParticipantIds,
51492
+ matchUpStatusProfile,
51493
+ participantsProfile,
51494
+ completeAllMatchUps,
51495
+ autoEntryPositions,
51496
+ randomWinningSide,
51497
+ ratingsParameters,
51498
+ tournamentRecord,
51499
+ eventProfile,
51500
+ uuids
51501
+ });
51502
+ if (error) return {
51503
+ error
51504
+ };
51505
+ if (generatedDrawIds) drawIds.push(...generatedDrawIds);
51506
+ eventIds.push(eventId);
51507
+ if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51508
+ } else {
51509
+ const {
51510
+ gender,
51511
+ category,
51512
+ eventType
51513
+ } = event;
51514
+ const {
51515
+ drawProfiles
51516
+ } = eventProfile;
51517
+ const eventParticipantType = eventType === SINGLES ? INDIVIDUAL : eventType === DOUBLES ? PAIR : eventType;
51518
+
51519
+ if (drawProfiles) {
51520
+ const {
51521
+ stageParticipantsCount,
51522
+ uniqueParticipantsCount,
51523
+ uniqueParticipantStages
51524
+ } = getStageParticipantsCount({
51525
+ drawProfiles,
51526
+ category,
51527
+ gender
51528
+ });
51529
+ const {
51530
+ uniqueDrawParticipants = [],
51531
+ uniqueParticipantIds = []
51532
+ } = uniqueParticipantStages ? generateEventParticipants({
51533
+ event: {
51534
+ eventType,
51535
+ category,
51536
+ gender
51537
+ },
51538
+ uniqueParticipantsCount,
51539
+ participantsProfile,
51540
+ ratingsParameters,
51541
+ tournamentRecord,
51542
+ eventProfile,
51543
+ uuids
51544
+ }) : {};
51545
+ allUniqueParticipantIds.push(...uniqueParticipantIds);
51546
+ const {
51547
+ stageParticipants
51548
+ } = getStageParticipants({
51549
+ targetParticipants: tournamentRecord.participants || [],
51550
+ allUniqueParticipantIds,
51551
+ stageParticipantsCount,
51552
+ eventParticipantType
51553
+ });
51554
+ let result = generateFlights({
51555
+ uniqueDrawParticipants,
51556
+ autoEntryPositions,
51557
+ stageParticipants,
51558
+ tournamentRecord,
51559
+ drawProfiles,
51560
+ category,
51561
+ gender,
51562
+ event
51563
+ });
51564
+ if (result.error) return result;
51565
+ result = generateFlightDrawDefinitions({
51566
+ matchUpStatusProfile,
51567
+ completeAllMatchUps,
51568
+ randomWinningSide,
51569
+ tournamentRecord,
51570
+ drawProfiles,
51571
+ event
51572
+ });
51573
+ if (result.error) return result;
51574
+ drawIds.push(...result.drawIds);
51575
+ }
51576
+ }
51577
+ }
51578
+ }
51579
+
51580
+ if (drawProfiles) {
51581
+ for (const drawProfile of drawProfiles) {
51582
+ const {
51583
+ drawId,
51584
+ eventId,
51585
+ event,
51586
+ error,
51587
+ uniqueParticipantIds
51588
+ } = generateEventWithDraw({
51589
+ startDate: tournamentRecord.startDate,
51590
+ allUniqueParticipantIds,
51591
+ matchUpStatusProfile,
51592
+ participantsProfile,
51593
+ completeAllMatchUps,
51594
+ autoEntryPositions,
51595
+ randomWinningSide,
51596
+ ratingsParameters: ratingsParameters$1,
51597
+ tournamentRecord,
51598
+ drawProfile,
51599
+ goesTo,
51600
+ uuids
51601
+ });
51602
+ if (error) return {
51603
+ error
51604
+ };
51605
+ const result = addEvent({
51606
+ tournamentRecord,
51607
+ event
51608
+ });
51609
+ if (result.error) return result;
51610
+ if (drawId) drawIds.push(drawId);
51611
+ eventIds.push(eventId);
51612
+ if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51613
+ }
51614
+ }
51615
+
51616
+ const venueIds = venueProfiles !== null && venueProfiles !== void 0 && venueProfiles.length ? generateVenues({
51617
+ tournamentRecord,
51618
+ venueProfiles
51619
+ }) : [];
51620
+ let scheduledRounds;
51621
+ let schedulerResult = {};
51622
+
51623
+ if (schedulingProfile) {
51624
+ const result = generateScheduleTimes({
51625
+ schedulingProfile,
51626
+ tournamentRecord
51627
+ });
51628
+ if (result.error) return result;
51629
+ scheduledRounds = result.scheduledRounds;
51630
+
51631
+ if (autoSchedule) {
51632
+ const {
51633
+ tournamentId
51634
+ } = tournamentRecord;
51635
+ const tournamentRecords = {
51636
+ [tournamentId]: tournamentRecord
51637
+ };
51638
+ schedulerResult = scheduleProfileRounds({
51639
+ tournamentRecords
51640
+ });
51641
+ }
51642
+ }
51643
+
51644
+ return { ...SUCCESS,
51645
+ drawIds,
51646
+ eventIds,
51647
+ venueIds,
51648
+ scheduledRounds,
51649
+ schedulerResult
51650
+ };
51651
+ }
51652
+
51653
+ const amendsGovernor = {
51654
+ anonymizeTournamentRecord,
51655
+ modifyTournamentRecord
51656
+ };
51657
+
51658
+ function generateSchedulingProfile({
51659
+ schedulingProfile,
51660
+ tournamentRecord
51661
+ }) {
51662
+ if (typeof schedulingProfile !== 'object') return {
51663
+ error: INVALID_VALUES
51664
+ };
51665
+ const containedStructures = getContainedStructures({
51666
+ tournamentRecord
51667
+ }).containedStructures;
51668
+ const {
51669
+ matchUps
51670
+ } = allTournamentMatchUps({
51671
+ tournamentRecord
51672
+ });
51673
+ const {
51674
+ tournamentId
51675
+ } = tournamentRecord;
51676
+ const scheduledRounds = [];
51677
+
51678
+ for (const dateProfile of schedulingProfile) {
51679
+ const {
51680
+ scheduleDate,
51681
+ venues = []
51682
+ } = dateProfile;
51683
+
51684
+ for (const venue of venues) {
51685
+ const {
51686
+ rounds,
51687
+ venueId
51688
+ } = venue;
51689
+
51690
+ for (const round of rounds) {
51691
+ const {
51692
+ drawId,
51693
+ winnerFinishingPositionRange,
51694
+ roundSegment
51695
+ } = round;
51696
+ const targetMatchUps = matchUps.filter(matchUp => {
51697
+ var _matchUp$finishingPos;
51698
+
51699
+ const targetRange = (winnerFinishingPositionRange === null || winnerFinishingPositionRange === void 0 ? void 0 : winnerFinishingPositionRange.indexOf('-')) > 0 && winnerFinishingPositionRange.split('-').map(x => +x);
51700
+ const range = (_matchUp$finishingPos = matchUp.finishingPositionRange) === null || _matchUp$finishingPos === void 0 ? void 0 : _matchUp$finishingPos.winner;
51701
+ const target = matchUp.drawId === drawId && (!round.roundNumber || matchUp.roundNumber === round.roundNumber) && (!range || !targetRange || intersection(range, targetRange).length === 2);
51702
+ return target;
51703
+ });
51704
+ const targetMatchUp = targetMatchUps[0];
51705
+
51706
+ if (targetMatchUp) {
51707
+ const {
51708
+ eventId,
51709
+ roundNumber,
51710
+ drawName,
51711
+ structureName,
51712
+ roundName
51713
+ } = targetMatchUp;
51714
+ let structureId = targetMatchUp.structureId;
51715
+
51716
+ if (roundNumber && !winnerFinishingPositionRange) {
51717
+ structureId = Object.keys(containedStructures).find(containingStructureId => containedStructures[containingStructureId].includes(structureId));
51718
+ }
51719
+
51720
+ const roundToSchedule = {
51721
+ tournamentId,
51722
+ eventId,
51723
+ drawId,
51724
+ structureId,
51725
+ roundNumber,
51726
+ roundSegment
51727
+ };
51728
+ let result = addSchedulingProfileRound({
51729
+ tournamentRecords: {
51730
+ [tournamentId]: tournamentRecord
51731
+ },
51732
+ scheduleDate,
51733
+ venueId,
51734
+ round: roundToSchedule
51735
+ });
51736
+ if (result.error) return result;
51737
+ scheduledRounds.push({
51738
+ drawName,
51739
+ structureName,
51740
+ roundName,
51741
+ ...roundToSchedule
51742
+ });
51743
+ }
51744
+ }
51745
+ }
51746
+ }
51747
+
51748
+ return {
51749
+ scheduledRounds
51750
+ };
51751
+ }
51752
+
51651
51753
  /**
51652
51754
  *
51653
51755
  * Generate a complete tournamentRecord from the following attributes