tods-competition-factory 0.93.2 → 0.94.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.
@@ -249,7 +249,7 @@ const matchUpFormatCode = {
249
249
  };
250
250
 
251
251
  function factoryVersion() {
252
- return '0.93.2';
252
+ return '0.94.0';
253
253
  }
254
254
 
255
255
  const FORMAT_STANDARD = 'SET3-S:6/TB7'; // Best of 3 Tiebreak Sets to 6
@@ -1321,13 +1321,6 @@ const validTimeString = /^((0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?)([.,]
1321
1321
  const dateValidation = /^([0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]))([ T](0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?)?([.,][0-9]{3})?Z?$/;
1322
1322
  const timeValidation = /^([0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]))?([ T]?(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?)?([.,][0-9]{3})?Z?$/;
1323
1323
 
1324
- /*
1325
- import {
1326
- INVALID_DATE,
1327
- INVALID_TIME_ZONE,
1328
- } from '../constants/errorConditionConstants';
1329
- */
1330
-
1331
1324
  function isDateObject(value) {
1332
1325
  if (typeof value !== 'object' || Array.isArray(value)) {
1333
1326
  return false;
@@ -1398,15 +1391,18 @@ function isDate(dateArg) {
1398
1391
  return t && !isNaN(t.valueOf());
1399
1392
  }
1400
1393
  function dateRange(startDt, endDt) {
1401
- const startDate = new Date(startDt);
1402
- const endDate = new Date(endDt);
1394
+ if (!isValidDateString(startDt) || !isValidDateString(endDt)) return [];
1395
+ const startDateString = extractDate(startDt) + 'T00:00';
1396
+ const endDateString = extractDate(endDt) + 'T00:00';
1397
+ const startDate = new Date(startDateString);
1398
+ const endDate = new Date(endDateString);
1403
1399
  const error = isDate(endDate) && isDate(startDate) && isValidDateRange(startDate, endDate) ? false : true;
1404
1400
  const between = [];
1405
1401
  let iterations = 0;
1406
1402
 
1407
1403
  if (!error) {
1408
- const currentDate = offsetDate(startDate);
1409
- const end = offsetDate(endDate);
1404
+ const currentDate = startDate;
1405
+ const end = endDate;
1410
1406
 
1411
1407
  while (currentDate <= end && iterations < 300) {
1412
1408
  iterations += 1; // must be a *new* Date otherwise it is an array of the same object
@@ -1416,10 +1412,10 @@ function dateRange(startDt, endDt) {
1416
1412
  }
1417
1413
  }
1418
1414
 
1419
- return between;
1415
+ return between.map(date => formatDate(date));
1420
1416
 
1421
1417
  function isValidDateRange(minDate, maxDate) {
1422
- return offsetDate(minDate) <= offsetDate(maxDate);
1418
+ return minDate <= maxDate;
1423
1419
  }
1424
1420
  } // matches valid ISO date string
1425
1421
 
@@ -26710,14 +26706,17 @@ function clearScheduledMatchUps$1({
26710
26706
  tournamentRecord,
26711
26707
  inContext: false
26712
26708
  });
26709
+ let clearedScheduleCount = 0;
26713
26710
 
26714
26711
  for (const matchUp of matchUps) {
26715
26712
  if (relevantMatchUpIds.includes(matchUp.matchUpId)) {
26716
26713
  matchUp.timeItems = (matchUp.timeItems || []).filter(timeItem => ![ASSIGN_COURT, ASSIGN_VENUE, SCHEDULED_DATE, SCHEDULED_TIME].includes(timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemType));
26714
+ clearedScheduleCount += 1;
26717
26715
  }
26718
26716
  }
26719
26717
 
26720
- return { ...SUCCESS
26718
+ return { ...SUCCESS,
26719
+ clearedScheduleCount
26721
26720
  };
26722
26721
  }
26723
26722
 
@@ -43499,63 +43498,178 @@ function setTournamentNotes({
43499
43498
  element: tournamentRecord,
43500
43499
  notes
43501
43500
  });
43502
- } // TODO: check for matchUps that must be unscheduled with change in date
43503
- // TODO: check all courts in all venues for dateAvailability that is outside of tournament date range
43504
-
43505
- function setTournamentStartDate({
43501
+ }
43502
+ function setTournamentCategories({
43506
43503
  tournamentRecord,
43507
- startDate
43504
+ categories
43508
43505
  }) {
43509
43506
  if (!tournamentRecord) return {
43510
43507
  error: MISSING_TOURNAMENT_RECORD
43511
43508
  };
43512
- if (!dateValidation.test(startDate)) return {
43513
- error: INVALID_DATE
43514
- };
43509
+ categories = (categories || []).filter(category => {
43510
+ return category.categoryName && category.type;
43511
+ });
43512
+ tournamentRecord.tournamentCategories = categories;
43513
+ return SUCCESS;
43514
+ }
43515
43515
 
43516
- if (tournamentRecord.startDate && new Date(startDate) > new Date(tournamentRecord.startDate)) ;
43516
+ function updateCourtAvailability({
43517
+ tournamentRecord
43518
+ }) {
43519
+ if (!tournamentRecord) return {
43520
+ error: MISSING_TOURNAMENT_RECORD
43521
+ };
43522
+ const {
43523
+ startDate,
43524
+ endDate
43525
+ } = tournamentRecord;
43526
+ const tournamentDates = dateRange(startDate, endDate);
43527
+ const {
43528
+ courts
43529
+ } = getCourts({
43530
+ tournamentRecord
43531
+ });
43517
43532
 
43518
- if (tournamentRecord.endDate && new Date(startDate) > new Date(tournamentRecord.endDate)) {
43519
- tournamentRecord.endDate = startDate;
43533
+ for (const court of courts) {
43534
+ const {
43535
+ startTime,
43536
+ endTime
43537
+ } = court.dateAvailability.reduce((extents, availability) => {
43538
+ const startMinutes = timeStringMinutes(extents.startTime);
43539
+ const endMinutes = timeStringMinutes(extents.endTime);
43540
+ if (availability.startTime && timeStringMinutes(availability.startTime) < startMinutes) extents.startTime = availability.startTime;
43541
+ if (availability.endTime && timeStringMinutes(availability.endTime) > endMinutes) extents.endTime = availability.endTime;
43542
+ return extents;
43543
+ }, {
43544
+ startTime: '08:00',
43545
+ endTime: '18:00'
43546
+ });
43547
+ const updatedDateAvailability = tournamentDates.map(date => {
43548
+ const existing = court.dateAvailability.find(availability => availability.date === date);
43549
+ return existing || {
43550
+ date,
43551
+ startTime,
43552
+ endTime
43553
+ };
43554
+ });
43555
+ court.dateAvailability = updatedDateAvailability;
43520
43556
  }
43521
43557
 
43522
- tournamentRecord.startDate = startDate;
43523
- return SUCCESS;
43524
- } // TODO: check for matchUps that must be unscheduled with change in date
43525
- // TODO: check all courts in all venues for dateAvailability that is outside of tournament date range
43558
+ return { ...SUCCESS
43559
+ };
43560
+ }
43526
43561
 
43527
- function setTournamentEndDate({
43562
+ function setTournamentDates({
43528
43563
  tournamentRecord,
43564
+ startDate,
43529
43565
  endDate
43530
43566
  }) {
43567
+ var _removeInvalidSchedul;
43568
+
43531
43569
  if (!tournamentRecord) return {
43532
43570
  error: MISSING_TOURNAMENT_RECORD
43533
43571
  };
43534
- if (!dateValidation.test(endDate)) return {
43572
+ if (startDate && !dateValidation.test(startDate) || endDate && !dateValidation.test(endDate)) return {
43535
43573
  error: INVALID_DATE
43536
43574
  };
43575
+ if (!startDate && !endDate) return {
43576
+ error: MISSING_DATE
43577
+ };
43578
+ if (new Date(endDate) > new Date(startDate)) return {
43579
+ error: INVALID_VALUES
43580
+ };
43581
+ let checkScheduling; // if start has moved closer to end or end has moved closer to start, check for scheduling issues
43582
+
43583
+ if (startDate && tournamentRecord.startDate && new Date(startDate) > new Date(tournamentRecord.startDate) || endDate && tournamentRecord.endDate && new Date(endDate) < new Date(tournamentRecord.endDate)) {
43584
+ checkScheduling = true;
43585
+ }
43537
43586
 
43538
- if (tournamentRecord.endDate && new Date(endDate) < new Date(tournamentRecord.endDate)) ;
43587
+ if (startDate) tournamentRecord.startDate = startDate;
43588
+ if (endDate) tournamentRecord.endDate = endDate; // if there is a startDate specified after current endDate, endDate must be set to startDate
43539
43589
 
43540
- if (tournamentRecord.startDate && new Date(endDate) < new Date(tournamentRecord.startDate)) {
43590
+ if (startDate && tournamentRecord.endDate && new Date(startDate) > new Date(tournamentRecord.endDate)) {
43591
+ tournamentRecord.endDate = startDate;
43592
+ } // if there is a endDate specified before current startDate, startDate must be set to endDate
43593
+
43594
+
43595
+ if (endDate && tournamentRecord.startDate && new Date(endDate) < new Date(tournamentRecord.startDate)) {
43541
43596
  tournamentRecord.startDate = endDate;
43542
43597
  }
43543
43598
 
43544
- tournamentRecord.endDate = endDate;
43545
- return SUCCESS;
43546
- }
43547
- function setTournamentCategories({
43599
+ const unscheduledMatchUpIds = checkScheduling && ((_removeInvalidSchedul = removeInvalidScheduling({
43600
+ tournamentRecord
43601
+ })) === null || _removeInvalidSchedul === void 0 ? void 0 : _removeInvalidSchedul.unscheduledMatchUpIds);
43602
+ updateCourtAvailability({
43603
+ tournamentRecord
43604
+ });
43605
+ return { ...SUCCESS,
43606
+ unscheduledMatchUpIds
43607
+ };
43608
+ } // TODO: check all courts in all venues for dateAvailability that is outside of tournament date range
43609
+
43610
+ function setTournamentStartDate({
43548
43611
  tournamentRecord,
43549
- categories
43612
+ startDate
43550
43613
  }) {
43551
- if (!tournamentRecord) return {
43552
- error: MISSING_TOURNAMENT_RECORD
43553
- };
43554
- categories = (categories || []).filter(category => {
43555
- return category.categoryName && category.type;
43614
+ return setTournamentDates({
43615
+ tournamentRecord,
43616
+ startDate
43556
43617
  });
43557
- tournamentRecord.tournamentCategories = categories;
43558
- return SUCCESS;
43618
+ } // TODO: check all courts in all venues for dateAvailability that is outside of tournament date range
43619
+
43620
+ function setTournamentEndDate({
43621
+ tournamentRecord,
43622
+ endDate
43623
+ }) {
43624
+ return setTournamentDates({
43625
+ tournamentRecord,
43626
+ endDate
43627
+ });
43628
+ } // unschedule scheduled matchUps that fall outside of tournament dates
43629
+
43630
+ function removeInvalidScheduling({
43631
+ tournamentRecord
43632
+ }) {
43633
+ const {
43634
+ matchUps
43635
+ } = allTournamentMatchUps({
43636
+ tournamentRecord
43637
+ });
43638
+ const startDate = tournamentRecord.startDate && new Date(tournamentRecord.startDate);
43639
+ const endDate = tournamentRecord.endDate && new Date(tournamentRecord.endDate);
43640
+ const invalidScheduledDates = [];
43641
+ const invalidSchedulingMatchUpIds = [];
43642
+
43643
+ for (const matchUp of matchUps) {
43644
+ const {
43645
+ schedule,
43646
+ matchUpId
43647
+ } = matchUp;
43648
+ if (!schedule) continue;
43649
+
43650
+ if (schedule.scheduledDate) {
43651
+ const scheduledDate = new Date(schedule.scheduledDate);
43652
+
43653
+ if (startDate && scheduledDate < startDate || endDate && scheduledDate > endDate) {
43654
+ invalidSchedulingMatchUpIds.push(matchUpId);
43655
+ if (!invalidScheduledDates.includes(schedule.scheduledDate)) invalidScheduledDates.push(schedule.scheduledDate);
43656
+ }
43657
+ }
43658
+ }
43659
+
43660
+ if (invalidScheduledDates.length) {
43661
+ const result = clearScheduledMatchUps$1({
43662
+ scheduledDates: invalidScheduledDates,
43663
+ tournamentRecord
43664
+ });
43665
+ if (!result.clearedScheduleCount) return {
43666
+ error: 'schedule not cleared'
43667
+ };
43668
+ }
43669
+
43670
+ return {
43671
+ unscheduledMatchUpIds: invalidSchedulingMatchUpIds
43672
+ };
43559
43673
  }
43560
43674
 
43561
43675
  const tournamentGovernor = {
@@ -43565,6 +43679,7 @@ const tournamentGovernor = {
43565
43679
  analyzeDraws,
43566
43680
  setTournamentName,
43567
43681
  setTournamentNotes,
43682
+ setTournamentDates,
43568
43683
  setTournamentEndDate,
43569
43684
  setTournamentStartDate,
43570
43685
  setTournamentCategories,