tods-competition-factory 1.8.6 → 1.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -945,6 +945,10 @@ const INVALID_OBJECT = {
945
945
  message: "Invalid object",
946
946
  code: "ERR_INVALID_OBJECT"
947
947
  };
948
+ const INVALID_GENDER = {
949
+ message: "Invalid gender",
950
+ code: "ERR_INVALID_GENDER"
951
+ };
948
952
  const INVALID_CATEGORY = {
949
953
  message: "Invalid category",
950
954
  code: "ERR_INVALID_CATEGORY"
@@ -1062,6 +1066,7 @@ const errorConditionConstants = {
1062
1066
  INVALID_ENTRIES,
1063
1067
  INVALID_EVENT_TYPE,
1064
1068
  INVALID_GAME_SCORES,
1069
+ INVALID_GENDER,
1065
1070
  INVALID_MATCHUP_FORMAT,
1066
1071
  INVALID_MATCHUP_STATUS,
1067
1072
  INVALID_MATCHUP_STATUS_BYE,
@@ -2375,7 +2380,7 @@ const matchUpFormatCode = {
2375
2380
  };
2376
2381
 
2377
2382
  function factoryVersion() {
2378
- return "1.8.6";
2383
+ return "1.8.8";
2379
2384
  }
2380
2385
 
2381
2386
  function getObjectTieFormat(obj) {
@@ -2938,6 +2943,11 @@ function validateCollectionDefinition({
2938
2943
  }
2939
2944
  if (checkGender && referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) && referenceGender !== gender) {
2940
2945
  errors.push(`Invalid gender: ${gender}`);
2946
+ return decorateResult({
2947
+ context: { referenceGender, gender },
2948
+ result: { error: INVALID_GENDER },
2949
+ stack
2950
+ });
2941
2951
  }
2942
2952
  if (checkCategory && referenceCategory && category) {
2943
2953
  const result = categoryCanContain({
@@ -35135,326 +35145,6 @@ function getMatchUpDailyLimitsUpdate$1({ tournamentRecords }) {
35135
35145
  });
35136
35146
  }
35137
35147
 
35138
- const { stageOrder } = drawDefinitionConstants;
35139
- function getProfileRounds({
35140
- tournamentRecords,
35141
- schedulingProfile,
35142
- tournamentRecord,
35143
- withRoundId
35144
- }) {
35145
- if (tournamentRecord && !tournamentRecords) {
35146
- if (typeof tournamentRecord !== "object") {
35147
- return { error: INVALID_TOURNAMENT_RECORD };
35148
- } else {
35149
- tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
35150
- }
35151
- }
35152
- if (schedulingProfile) {
35153
- const profileValidity = validateSchedulingProfile({
35154
- tournamentRecords,
35155
- schedulingProfile
35156
- });
35157
- if (profileValidity.error)
35158
- return profileValidity;
35159
- }
35160
- if (!schedulingProfile && tournamentRecords) {
35161
- const result = getSchedulingProfile$1({ tournamentRecords });
35162
- if (result.error)
35163
- return result;
35164
- schedulingProfile = result.schedulingProfile;
35165
- }
35166
- if (!schedulingProfile)
35167
- return { error: NOT_FOUND };
35168
- const segmentedRounds = {};
35169
- const profileRounds = schedulingProfile.map(
35170
- ({ venues, scheduleDate }) => venues.map(
35171
- ({ rounds }) => rounds.map((round) => {
35172
- const roundRef = getRoundId(round);
35173
- if (roundRef.roundSegment?.segmentsCount) {
35174
- segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
35175
- }
35176
- return definedAttributes({
35177
- id: withRoundId ? roundRef.id : void 0,
35178
- scheduleDate,
35179
- ...roundRef
35180
- });
35181
- })
35182
- )
35183
- ).flat(Infinity);
35184
- return { profileRounds, segmentedRounds };
35185
- }
35186
- function getRoundId(obj) {
35187
- const {
35188
- containerStructureId,
35189
- roundSegment,
35190
- isRoundRobin,
35191
- tournamentId,
35192
- roundNumber,
35193
- structureId,
35194
- eventId,
35195
- drawId
35196
- } = obj;
35197
- const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
35198
- const id = [
35199
- tournamentId,
35200
- // 1
35201
- eventId,
35202
- // 2
35203
- drawId,
35204
- // 3
35205
- relevantStructureId,
35206
- // 4
35207
- roundNumber
35208
- // 5
35209
- ].join("|");
35210
- return definedAttributes({
35211
- id,
35212
- roundSegment,
35213
- tournamentId,
35214
- eventId,
35215
- drawId,
35216
- structureId: relevantStructureId,
35217
- roundNumber
35218
- });
35219
- }
35220
- function getRoundProfile(matchUps) {
35221
- const matchUpsCount = matchUps.length;
35222
- const byeCount = matchUps.filter(({ sides }) => sides?.some(({ bye }) => bye)).length || 0;
35223
- const completedCount = matchUps.filter(
35224
- ({ winningSide, matchUpStatus }) => winningSide || completedMatchUpStatuses.includes(matchUpStatus)
35225
- ).length || 0;
35226
- const scheduledCount = matchUps.filter(
35227
- ({ schedule }) => schedule?.scheduledDate && schedule?.scheduledTime
35228
- ).length || 0;
35229
- const consideredCount = matchUpsCount - byeCount;
35230
- const isComplete = consideredCount === completedCount;
35231
- const unscheduledCount = consideredCount - scheduledCount;
35232
- const incompleteCount = consideredCount - scheduledCount;
35233
- const isScheduled = consideredCount === scheduledCount;
35234
- return {
35235
- unscheduledCount,
35236
- incompleteCount,
35237
- scheduledCount,
35238
- completedCount,
35239
- matchUpsCount,
35240
- isScheduled,
35241
- isComplete,
35242
- byeCount
35243
- };
35244
- }
35245
- function getRounds({
35246
- excludeScheduleDateProfileRounds,
35247
- excludeScheduledRounds,
35248
- excludeCompletedRounds,
35249
- inContextMatchUps,
35250
- tournamentRecords,
35251
- schedulingProfile,
35252
- tournamentRecord,
35253
- withSplitRounds,
35254
- matchUpFilters,
35255
- withRoundId,
35256
- context
35257
- }) {
35258
- if (inContextMatchUps && !Array.isArray(
35259
- inContextMatchUps || typeof inContextMatchUps[0] !== "object"
35260
- )) {
35261
- return { error: INVALID_VALUES, inContextMatchUps };
35262
- }
35263
- if (tournamentRecord && !tournamentRecords) {
35264
- if (typeof tournamentRecord !== "object") {
35265
- return { error: INVALID_TOURNAMENT_RECORD };
35266
- } else {
35267
- tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
35268
- }
35269
- }
35270
- const noTournamentRecords = typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length;
35271
- const needsTournamentRecords = !inContextMatchUps || !schedulingProfile && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds);
35272
- if (needsTournamentRecords && noTournamentRecords)
35273
- return { error: MISSING_TOURNAMENT_RECORDS };
35274
- const events = Object.values(tournamentRecords ?? {}).map(({ events: events2 }) => events2).flat();
35275
- const { segmentedRounds, profileRounds } = tournamentRecords && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds) && getProfileRounds({ tournamentRecords, schedulingProfile }) || {};
35276
- const profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign(
35277
- {},
35278
- ...profileRounds.map((profile) => ({ [profile.id]: profile }))
35279
- );
35280
- const consideredMatchUps = inContextMatchUps || tournamentRecords && allCompetitionMatchUps({ tournamentRecords, matchUpFilters })?.matchUps || [];
35281
- const excludedRounds = [];
35282
- const rounds = consideredMatchUps && Object.values(
35283
- consideredMatchUps.reduce((rounds2, matchUp) => {
35284
- const id = getRoundId(matchUp).id;
35285
- const segmentsCount = segmentedRounds?.[id];
35286
- const matchUps = [...rounds2[id]?.matchUps ?? [], matchUp];
35287
- const {
35288
- containerStructureId,
35289
- stageSequence,
35290
- structureName,
35291
- tournamentId,
35292
- isRoundRobin,
35293
- matchUpType,
35294
- roundNumber,
35295
- roundOffset,
35296
- structureId,
35297
- eventName,
35298
- roundName,
35299
- drawName,
35300
- eventId,
35301
- drawId
35302
- } = matchUp;
35303
- const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
35304
- return {
35305
- ...rounds2,
35306
- [id]: {
35307
- id: withRoundId ? id : void 0,
35308
- structureId: relevantStructureId,
35309
- stageSequence,
35310
- segmentsCount,
35311
- structureName,
35312
- tournamentId,
35313
- matchUpType,
35314
- roundNumber,
35315
- roundOffset,
35316
- eventName,
35317
- roundName,
35318
- drawName,
35319
- matchUps,
35320
- eventId,
35321
- drawId
35322
- }
35323
- };
35324
- }, {})
35325
- ).map((round) => {
35326
- const { minFinishingSum, winnerFinishingPositionRange } = getFinishingPositionDetails(round.matchUps);
35327
- const segmentsCount = round.segmentsCount;
35328
- if (segmentsCount) {
35329
- const chunkSize = round.matchUps.length / segmentsCount;
35330
- const sortedMatchUps = chunkArray(
35331
- round.matchUps.sort((a, b) => a.roundPosition - b.roundPosition),
35332
- chunkSize
35333
- );
35334
- return sortedMatchUps.map((matchUps, i) => {
35335
- const {
35336
- unscheduledCount: unscheduledCount2,
35337
- incompleteCount: incompleteCount2,
35338
- matchUpsCount: matchUpsCount2,
35339
- isScheduled: isScheduled2,
35340
- isComplete: isComplete2,
35341
- byeCount: byeCount2
35342
- } = getRoundProfile(matchUps);
35343
- const roundTiming2 = getRoundTiming({
35344
- matchUps: round.matchUps,
35345
- tournamentRecords,
35346
- events,
35347
- round
35348
- });
35349
- return definedAttributes({
35350
- ...round,
35351
- ...context,
35352
- roundSegment: { segmentsCount, segmentNumber: i + 1 },
35353
- winnerFinishingPositionRange,
35354
- unscheduledCount: unscheduledCount2,
35355
- incompleteCount: incompleteCount2,
35356
- minFinishingSum,
35357
- matchUpsCount: matchUpsCount2,
35358
- isScheduled: isScheduled2,
35359
- roundTiming: roundTiming2,
35360
- isComplete: isComplete2,
35361
- byeCount: byeCount2,
35362
- matchUps
35363
- });
35364
- });
35365
- }
35366
- const {
35367
- unscheduledCount,
35368
- incompleteCount,
35369
- matchUpsCount,
35370
- isScheduled,
35371
- isComplete,
35372
- byeCount
35373
- } = getRoundProfile(round.matchUps);
35374
- const roundTiming = getRoundTiming({
35375
- matchUps: round.matchUps,
35376
- tournamentRecords,
35377
- events,
35378
- round
35379
- });
35380
- return definedAttributes({
35381
- ...round,
35382
- ...context,
35383
- winnerFinishingPositionRange,
35384
- unscheduledCount,
35385
- incompleteCount,
35386
- minFinishingSum,
35387
- matchUpsCount,
35388
- isScheduled,
35389
- roundTiming,
35390
- isComplete,
35391
- byeCount
35392
- });
35393
- }).flat().filter((round) => {
35394
- if (excludeScheduleDateProfileRounds) {
35395
- const scheduleDate = extractDate(excludeScheduleDateProfileRounds);
35396
- const roundId = withRoundId ? round.id : getRoundId(round).id;
35397
- if (scheduleDate && profileRoundsMap[roundId] && extractDate(profileRoundsMap[roundId].scheduleDate) === scheduleDate) {
35398
- return false;
35399
- }
35400
- }
35401
- const { isComplete, isScheduled } = round;
35402
- const keepComplete = !excludeCompletedRounds || !isComplete;
35403
- const keepScheduled = !excludeScheduledRounds || !isScheduled;
35404
- const keepRound = keepComplete && keepScheduled;
35405
- if (!keepRound)
35406
- excludedRounds.push(round);
35407
- return keepRound;
35408
- }).sort(roundSort) || [];
35409
- return { ...SUCCESS, rounds, excludedRounds };
35410
- }
35411
- function getRoundTiming({ round, matchUps, events, tournamentRecords }) {
35412
- const event = events.find((event2) => event2.eventId === round.eventId);
35413
- const { eventType, category, categoryType } = event || {};
35414
- const { categoryName, ageCategoryCode } = category || {};
35415
- const formatCounts = instanceCount(
35416
- matchUps.map(({ matchUpFormat }) => matchUpFormat)
35417
- );
35418
- let roundMinutes = 0;
35419
- Object.keys(formatCounts).forEach((matchUpFormat) => {
35420
- const formatCount = formatCounts[matchUpFormat];
35421
- const result = findMatchUpFormatTiming({
35422
- categoryName: categoryName || ageCategoryCode,
35423
- tournamentId: round.tournamentId,
35424
- eventId: round.eventId,
35425
- tournamentRecords,
35426
- matchUpFormat,
35427
- categoryType,
35428
- eventType
35429
- });
35430
- if (result.error)
35431
- return result;
35432
- const formatMinutes = result.averageMinutes * formatCount;
35433
- if (!isNaN(roundMinutes))
35434
- roundMinutes += formatMinutes;
35435
- return void 0;
35436
- });
35437
- return { roundMinutes };
35438
- }
35439
- function roundSort(a, b) {
35440
- return a.eventName.localeCompare(b.eventName) || a.eventId.localeCompare(b.eventId) || (stageOrder[a?.stage] || 0) - (stageOrder[b?.stage] || 0) || b.matchUpsCount - a.matchUpsCount || `${a.stageSequence}-${a.roundNumber}-${a.minFinishingSum}`.localeCompare(
35441
- `${b.stageSequence}-${b.roundNumber}-${b.minFinishingSum}`
35442
- );
35443
- }
35444
- function getFinishingPositionDetails(matchUps) {
35445
- return (matchUps || []).reduce(
35446
- (foo, matchUp) => {
35447
- const sum = (matchUp.finishingPositionRange?.winner || []).reduce(
35448
- (a, b) => a + b,
35449
- 0
35450
- );
35451
- const winnerFinishingPositionRange = (matchUp.finishingPositionRange?.winner || []).join("-") || "";
35452
- return !foo.minFinishingSum || sum < foo.minFinishingSum ? { minFinishingSum: sum, winnerFinishingPositionRange } : foo;
35453
- },
35454
- { minFinishingSum: 0, winnerFinishingPositionRange: "" }
35455
- );
35456
- }
35457
-
35458
35148
  function bulkUpdateCourtAssignments({
35459
35149
  tournamentRecords,
35460
35150
  courtAssignments,
@@ -35885,6 +35575,155 @@ function reorderUpcomingMatchUps(params) {
35885
35575
  }
35886
35576
  }
35887
35577
 
35578
+ function getRoundId(obj) {
35579
+ const {
35580
+ containerStructureId,
35581
+ roundSegment,
35582
+ isRoundRobin,
35583
+ tournamentId,
35584
+ roundNumber,
35585
+ structureId,
35586
+ eventId,
35587
+ drawId
35588
+ } = obj;
35589
+ const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
35590
+ const id = [
35591
+ tournamentId,
35592
+ // 1
35593
+ eventId,
35594
+ // 2
35595
+ drawId,
35596
+ // 3
35597
+ relevantStructureId,
35598
+ // 4
35599
+ roundNumber
35600
+ // 5
35601
+ ].join("|");
35602
+ return definedAttributes({
35603
+ structureId: relevantStructureId,
35604
+ roundSegment,
35605
+ tournamentId,
35606
+ roundNumber,
35607
+ eventId,
35608
+ drawId,
35609
+ id
35610
+ });
35611
+ }
35612
+ function getRoundTiming({ round, matchUps, events, tournamentRecords }) {
35613
+ const event = events.find((event2) => event2.eventId === round.eventId);
35614
+ const { eventType, category, categoryType } = event || {};
35615
+ const { categoryName, ageCategoryCode } = category || {};
35616
+ const formatCounts = instanceCount(
35617
+ matchUps.map(({ matchUpFormat }) => matchUpFormat)
35618
+ );
35619
+ let roundMinutes = 0;
35620
+ Object.keys(formatCounts).forEach((matchUpFormat) => {
35621
+ const formatCount = formatCounts[matchUpFormat];
35622
+ const result = findMatchUpFormatTiming({
35623
+ categoryName: categoryName || ageCategoryCode,
35624
+ tournamentId: round.tournamentId,
35625
+ eventId: round.eventId,
35626
+ tournamentRecords,
35627
+ matchUpFormat,
35628
+ categoryType,
35629
+ eventType
35630
+ });
35631
+ if (result.error)
35632
+ return result;
35633
+ const formatMinutes = result.averageMinutes * formatCount;
35634
+ if (!isNaN(roundMinutes))
35635
+ roundMinutes += formatMinutes;
35636
+ return void 0;
35637
+ });
35638
+ return { roundMinutes };
35639
+ }
35640
+ function getFinishingPositionDetails(matchUps) {
35641
+ return (matchUps || []).reduce(
35642
+ (foo, matchUp) => {
35643
+ const sum = (matchUp.finishingPositionRange?.winner || []).reduce(
35644
+ (a, b) => a + b,
35645
+ 0
35646
+ );
35647
+ const winnerFinishingPositionRange = (matchUp.finishingPositionRange?.winner || []).join("-") || "";
35648
+ return !foo.minFinishingSum || sum < foo.minFinishingSum ? { minFinishingSum: sum, winnerFinishingPositionRange } : foo;
35649
+ },
35650
+ { minFinishingSum: 0, winnerFinishingPositionRange: "" }
35651
+ );
35652
+ }
35653
+ function getRoundProfile(matchUps) {
35654
+ const matchUpsCount = matchUps.length;
35655
+ const byeCount = matchUps.filter(({ sides }) => sides?.some(({ bye }) => bye)).length || 0;
35656
+ const completedCount = matchUps.filter(
35657
+ ({ winningSide, matchUpStatus }) => winningSide || completedMatchUpStatuses.includes(matchUpStatus)
35658
+ ).length || 0;
35659
+ const scheduledCount = matchUps.filter(
35660
+ ({ schedule }) => schedule?.scheduledDate && schedule?.scheduledTime
35661
+ ).length || 0;
35662
+ const consideredCount = matchUpsCount - byeCount;
35663
+ const isComplete = consideredCount === completedCount;
35664
+ const unscheduledCount = consideredCount - scheduledCount;
35665
+ const incompleteCount = consideredCount - scheduledCount;
35666
+ const isScheduled = consideredCount === scheduledCount;
35667
+ return {
35668
+ unscheduledCount,
35669
+ incompleteCount,
35670
+ scheduledCount,
35671
+ completedCount,
35672
+ matchUpsCount,
35673
+ isScheduled,
35674
+ isComplete,
35675
+ byeCount
35676
+ };
35677
+ }
35678
+
35679
+ function getProfileRounds({
35680
+ tournamentRecords,
35681
+ schedulingProfile,
35682
+ tournamentRecord,
35683
+ withRoundId
35684
+ }) {
35685
+ if (tournamentRecord && !tournamentRecords) {
35686
+ if (typeof tournamentRecord !== "object") {
35687
+ return { error: INVALID_TOURNAMENT_RECORD };
35688
+ } else {
35689
+ tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
35690
+ }
35691
+ }
35692
+ if (schedulingProfile) {
35693
+ const profileValidity = validateSchedulingProfile({
35694
+ tournamentRecords,
35695
+ schedulingProfile
35696
+ });
35697
+ if (profileValidity.error)
35698
+ return profileValidity;
35699
+ }
35700
+ if (!schedulingProfile && tournamentRecords) {
35701
+ const result = getSchedulingProfile$1({ tournamentRecords });
35702
+ if (result.error)
35703
+ return result;
35704
+ schedulingProfile = result.schedulingProfile;
35705
+ }
35706
+ if (!schedulingProfile)
35707
+ return { error: NOT_FOUND };
35708
+ const segmentedRounds = {};
35709
+ const profileRounds = schedulingProfile.map(
35710
+ ({ venues, scheduleDate }) => venues.map(
35711
+ ({ rounds }) => rounds.map((round) => {
35712
+ const roundRef = getRoundId(round);
35713
+ if (roundRef.roundSegment?.segmentsCount) {
35714
+ segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
35715
+ }
35716
+ return definedAttributes({
35717
+ id: withRoundId ? roundRef.id : void 0,
35718
+ scheduleDate,
35719
+ ...roundRef
35720
+ });
35721
+ })
35722
+ )
35723
+ ).flat(Infinity);
35724
+ return { profileRounds, segmentedRounds };
35725
+ }
35726
+
35888
35727
  function addMatchUpScheduleItems$1(params) {
35889
35728
  return addMatchUpScheduleItems$2(params);
35890
35729
  }
@@ -36502,6 +36341,200 @@ function matchUpScheduleChange(params) {
36502
36341
  }
36503
36342
  }
36504
36343
 
36344
+ const { stageOrder } = drawDefinitionConstants;
36345
+ function roundSort(a, b) {
36346
+ return a.eventName.localeCompare(b.eventName) || a.eventId.localeCompare(b.eventId) || (stageOrder[a?.stage] || 0) - (stageOrder[b?.stage] || 0) || b.matchUpsCount - a.matchUpsCount || `${a.stageSequence}-${a.roundNumber}-${a.minFinishingSum}`.localeCompare(
36347
+ `${b.stageSequence}-${b.roundNumber}-${b.minFinishingSum}`
36348
+ );
36349
+ }
36350
+
36351
+ function getRounds({
36352
+ excludeScheduleDateProfileRounds,
36353
+ excludeScheduledRounds,
36354
+ excludeCompletedRounds,
36355
+ inContextMatchUps,
36356
+ tournamentRecords,
36357
+ schedulingProfile,
36358
+ tournamentRecord,
36359
+ withSplitRounds,
36360
+ matchUpFilters,
36361
+ scheduleDate,
36362
+ withRoundId,
36363
+ venueId,
36364
+ context
36365
+ }) {
36366
+ if (inContextMatchUps && !Array.isArray(
36367
+ inContextMatchUps || typeof inContextMatchUps[0] !== "object"
36368
+ )) {
36369
+ return { error: INVALID_VALUES, inContextMatchUps };
36370
+ }
36371
+ if (tournamentRecord && !tournamentRecords) {
36372
+ if (typeof tournamentRecord !== "object") {
36373
+ return { error: INVALID_TOURNAMENT_RECORD };
36374
+ } else {
36375
+ tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
36376
+ }
36377
+ }
36378
+ const noTournamentRecords = typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length;
36379
+ const needsTournamentRecords = venueId || scheduleDate || !inContextMatchUps || !schedulingProfile && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds);
36380
+ if (needsTournamentRecords && noTournamentRecords)
36381
+ return { error: MISSING_TOURNAMENT_RECORDS };
36382
+ const tournamentVenueIds = Object.assign(
36383
+ {},
36384
+ ...Object.values(tournamentRecords ?? {}).map(
36385
+ ({ venues = [], tournamentId }) => ({
36386
+ [tournamentId]: venues?.map(({ venueId: venueId2 }) => venueId2)
36387
+ })
36388
+ )
36389
+ );
36390
+ const events = Object.values(tournamentRecords ?? {}).map(
36391
+ ({ events: events2 = [], tournamentId, startDate, endDate }) => events2.map((event) => ({
36392
+ ...event,
36393
+ validVenueIds: tournamentVenueIds[tournamentId],
36394
+ startDate: event.startDate ?? startDate,
36395
+ endDate: event.endDate ?? endDate
36396
+ }))
36397
+ ).flat();
36398
+ const { segmentedRounds, profileRounds } = tournamentRecords && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds) && getProfileRounds({ tournamentRecords, schedulingProfile }) || {};
36399
+ const profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign(
36400
+ {},
36401
+ ...profileRounds.map((profile) => ({ [profile.id]: profile }))
36402
+ );
36403
+ const consideredMatchUps = inContextMatchUps || tournamentRecords && allCompetitionMatchUps({ tournamentRecords, matchUpFilters })?.matchUps || [];
36404
+ const excludedRounds = [];
36405
+ const rounds = consideredMatchUps && Object.values(
36406
+ consideredMatchUps.reduce((rounds2, matchUp) => {
36407
+ const id = getRoundId(matchUp).id;
36408
+ const segmentsCount = segmentedRounds?.[id];
36409
+ const matchUps = [...rounds2[id]?.matchUps ?? [], matchUp];
36410
+ const {
36411
+ containerStructureId,
36412
+ stageSequence,
36413
+ structureName,
36414
+ tournamentId,
36415
+ isRoundRobin,
36416
+ matchUpType,
36417
+ roundNumber,
36418
+ roundOffset,
36419
+ structureId,
36420
+ eventName,
36421
+ roundName,
36422
+ drawName,
36423
+ eventId,
36424
+ drawId
36425
+ } = matchUp;
36426
+ const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
36427
+ return {
36428
+ ...rounds2,
36429
+ [id]: {
36430
+ id: withRoundId ? id : void 0,
36431
+ structureId: relevantStructureId,
36432
+ stageSequence,
36433
+ segmentsCount,
36434
+ structureName,
36435
+ tournamentId,
36436
+ matchUpType,
36437
+ roundNumber,
36438
+ roundOffset,
36439
+ eventName,
36440
+ roundName,
36441
+ drawName,
36442
+ matchUps,
36443
+ eventId,
36444
+ drawId
36445
+ }
36446
+ };
36447
+ }, {})
36448
+ ).map((round) => {
36449
+ const { minFinishingSum, winnerFinishingPositionRange } = getFinishingPositionDetails(round.matchUps);
36450
+ const segmentsCount = round.segmentsCount;
36451
+ if (segmentsCount) {
36452
+ const chunkSize = round.matchUps.length / segmentsCount;
36453
+ const sortedMatchUps = chunkArray(
36454
+ round.matchUps.sort((a, b) => a.roundPosition - b.roundPosition),
36455
+ chunkSize
36456
+ );
36457
+ return sortedMatchUps.map((matchUps, i) => {
36458
+ const {
36459
+ unscheduledCount: unscheduledCount2,
36460
+ incompleteCount: incompleteCount2,
36461
+ matchUpsCount: matchUpsCount2,
36462
+ isScheduled: isScheduled2,
36463
+ isComplete: isComplete2,
36464
+ byeCount: byeCount2
36465
+ } = getRoundProfile(matchUps);
36466
+ const roundTiming2 = getRoundTiming({
36467
+ matchUps: round.matchUps,
36468
+ tournamentRecords,
36469
+ events,
36470
+ round
36471
+ });
36472
+ return definedAttributes({
36473
+ ...round,
36474
+ ...context,
36475
+ roundSegment: { segmentsCount, segmentNumber: i + 1 },
36476
+ winnerFinishingPositionRange,
36477
+ unscheduledCount: unscheduledCount2,
36478
+ incompleteCount: incompleteCount2,
36479
+ minFinishingSum,
36480
+ matchUpsCount: matchUpsCount2,
36481
+ isScheduled: isScheduled2,
36482
+ roundTiming: roundTiming2,
36483
+ isComplete: isComplete2,
36484
+ byeCount: byeCount2,
36485
+ matchUps
36486
+ });
36487
+ });
36488
+ }
36489
+ const {
36490
+ unscheduledCount,
36491
+ incompleteCount,
36492
+ matchUpsCount,
36493
+ isScheduled,
36494
+ isComplete,
36495
+ byeCount
36496
+ } = getRoundProfile(round.matchUps);
36497
+ const roundTiming = getRoundTiming({
36498
+ matchUps: round.matchUps,
36499
+ tournamentRecords,
36500
+ events,
36501
+ round
36502
+ });
36503
+ return definedAttributes({
36504
+ ...round,
36505
+ ...context,
36506
+ winnerFinishingPositionRange,
36507
+ unscheduledCount,
36508
+ incompleteCount,
36509
+ minFinishingSum,
36510
+ matchUpsCount,
36511
+ isScheduled,
36512
+ roundTiming,
36513
+ isComplete,
36514
+ byeCount
36515
+ });
36516
+ }).flat().filter((round) => {
36517
+ if (excludeScheduleDateProfileRounds) {
36518
+ const scheduleDate2 = extractDate(excludeScheduleDateProfileRounds);
36519
+ const roundId = withRoundId ? round.id : getRoundId(round).id;
36520
+ if (scheduleDate2 && profileRoundsMap[roundId] && extractDate(profileRoundsMap[roundId].scheduleDate) === scheduleDate2) {
36521
+ return false;
36522
+ }
36523
+ }
36524
+ const { isComplete, isScheduled } = round;
36525
+ const keepComplete = !excludeCompletedRounds || !isComplete;
36526
+ const keepScheduled = !excludeScheduledRounds || !isScheduled;
36527
+ const event = venueId || scheduleDate ? events?.find(({ eventId }) => eventId === round.eventId) : void 0;
36528
+ const validDate = !scheduleDate || event?.startDate && event?.endDate && new Date(scheduleDate) >= new Date(event?.startDate) && new Date(scheduleDate) <= new Date(event?.endDate);
36529
+ const validVenue = !venueId || event?.validVenueIds.includes(venueId);
36530
+ const keepRound = keepComplete && keepScheduled && validVenue && validDate;
36531
+ if (!keepRound)
36532
+ excludedRounds.push(round);
36533
+ return keepRound;
36534
+ }).sort(roundSort) || [];
36535
+ return { ...SUCCESS, rounds, excludedRounds };
36536
+ }
36537
+
36505
36538
  function addMatchUpScheduleItems(params) {
36506
36539
  const result = getDrawDefinition$1(params);
36507
36540
  if (result.error)
@@ -39107,13 +39140,14 @@ const competitionEngine = function() {
39107
39140
  const elapsed = Date.now() - start;
39108
39141
  const devContext = getDevContext();
39109
39142
  const log = { method: methodName };
39110
- const logErrors = typeof devContext.result === "object" && devContext.result.error;
39111
- if (![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
39143
+ const logError = result.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
39144
+ const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
39145
+ if (!exclude && ![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
39112
39146
  log.elapsed = elapsed;
39113
- if (logErrors || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName)) {
39147
+ if (!exclude && (logError || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName))) {
39114
39148
  log.params = params;
39115
39149
  }
39116
- if (logErrors || !logErrors && devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName)) {
39150
+ if (!exclude && (logError || devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName))) {
39117
39151
  log.result = result;
39118
39152
  }
39119
39153
  if (Object.keys(log).length > 1)
@@ -42293,8 +42327,8 @@ function getAvoidanceConflicts({ isRoundRobin, groupedParticipants }) {
42293
42327
  function getSwapOptions({
42294
42328
  positionedParticipants,
42295
42329
  potentialDrawPositions,
42296
- avoidanceConflicts,
42297
42330
  drawPositionGroups,
42331
+ avoidanceConflicts,
42298
42332
  isRoundRobin
42299
42333
  }) {
42300
42334
  return avoidanceConflicts.map((conflict) => {
@@ -53774,15 +53808,79 @@ function setTournamentStatus({ tournamentRecord, status }) {
53774
53808
 
53775
53809
  function addOnlineResource({
53776
53810
  tournamentRecord,
53777
- onlineResource
53811
+ onlineResource,
53812
+ organisationId,
53813
+ participantId,
53814
+ personId,
53815
+ courtId,
53816
+ venueId
53778
53817
  }) {
53779
53818
  if (!tournamentRecord)
53780
53819
  return { error: MISSING_TOURNAMENT_RECORD };
53781
- if (!onlineResource)
53820
+ if (!isObject(onlineResource))
53782
53821
  return { error: MISSING_VALUE };
53783
- if (!tournamentRecord.onlineResources)
53784
- tournamentRecord.onlineResources = [];
53785
- tournamentRecord.onlineResources.push(onlineResource);
53822
+ if (intersection(Object.keys(onlineResource), [
53823
+ "resourceSubType",
53824
+ "resourceType",
53825
+ "identifier"
53826
+ ]).length !== 3)
53827
+ return decorateResult({
53828
+ result: { error: INVALID_OBJECT },
53829
+ context: { onlineResource }
53830
+ });
53831
+ if (organisationId) {
53832
+ if (tournamentRecord.parentOrganisation?.parentOrganisationId !== organisationId) {
53833
+ return decorateResult({ result: { error: NOT_FOUND } });
53834
+ }
53835
+ if (!tournamentRecord.parentOrganisation.onlineResources)
53836
+ tournamentRecord.parentOrganisation.onlineResources = [];
53837
+ tournamentRecord.parentOrganisation.onlineResources.push(onlineResource);
53838
+ } else if (participantId || personId) {
53839
+ const participant = (tournamentRecord.participants ?? []).find(
53840
+ (p) => personId && p.person?.personId === personId || p.participantId === participantId
53841
+ );
53842
+ if (!participant) {
53843
+ if (personId) {
53844
+ return decorateResult({ result: { error: NOT_FOUND } });
53845
+ } else {
53846
+ return decorateResult({ result: { error: PARTICIPANT_NOT_FOUND } });
53847
+ }
53848
+ }
53849
+ if (personId) {
53850
+ if (participant.person?.personId !== personId) {
53851
+ return decorateResult({ result: { error: INVALID_PARTICIPANT } });
53852
+ }
53853
+ if (!participant.person.onlineResources)
53854
+ participant.person.onlineResources = [];
53855
+ participant.person.onlineResources.push(onlineResource);
53856
+ } else {
53857
+ if (!participant.onlineResources)
53858
+ participant.onlineResources = [];
53859
+ participant.onlineResources.push(onlineResource);
53860
+ }
53861
+ } else if (courtId) {
53862
+ const court = (tournamentRecord.venues ?? []).filter((v) => !venueId || v.venueId === venueId).flatMap(
53863
+ (v) => (v.courts ?? []).filter((c) => c.courtId === courtId)
53864
+ )?.[0];
53865
+ if (!court)
53866
+ return decorateResult({ result: { error: COURT_NOT_FOUND } });
53867
+ if (!court.onlineResources)
53868
+ court.onlineResources = [];
53869
+ court.onlineResources.push(onlineResource);
53870
+ } else if (venueId) {
53871
+ const venue = (tournamentRecord.venues ?? []).find(
53872
+ (v) => v.venueId === venueId
53873
+ );
53874
+ if (!venue)
53875
+ return decorateResult({ result: { error: VENUE_NOT_FOUND } });
53876
+ if (!venue.onlineResources)
53877
+ venue.onlineResources = [];
53878
+ venue.onlineResources.push(onlineResource);
53879
+ } else {
53880
+ if (!tournamentRecord.onlineResources)
53881
+ tournamentRecord.onlineResources = [];
53882
+ tournamentRecord.onlineResources.push(onlineResource);
53883
+ }
53786
53884
  return { ...SUCCESS };
53787
53885
  }
53788
53886
 
@@ -59981,13 +60079,14 @@ const tournamentEngine = (() => {
59981
60079
  const elapsed = Date.now() - start;
59982
60080
  const devContext = getDevContext();
59983
60081
  const log = { method: methodName };
59984
- const logErrors = typeof devContext.result === "object" && devContext.result.error;
59985
- if (![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
60082
+ const logError = result.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
60083
+ const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
60084
+ if (!exclude && ![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
59986
60085
  log.elapsed = elapsed;
59987
- if (logErrors || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName)) {
60086
+ if (!exclude && (logError || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName))) {
59988
60087
  log.params = params;
59989
60088
  }
59990
- if (logErrors || !logErrors && devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName)) {
60089
+ if (!exclude && (logError || devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName))) {
59991
60090
  log.result = result;
59992
60091
  }
59993
60092
  if (Object.keys(log).length > 1)