function removeInvalidScheduling({ tournamentRecord }) {
  const { matchUps } = allTournamentMatchUps({ tournamentRecord });

  const startDate =
    tournamentRecord.startDate && new Date(tournamentRecord.startDate);
  const endDate =
    tournamentRecord.endDate && new Date(tournamentRecord.endDate);

  const invalidScheduledDates = [];
  const invalidSchedulingMatchUpIds = [];
  for (const matchUp of matchUps) {
    const { schedule, matchUpId } = matchUp;
    if (!schedule) continue;
    if (schedule.scheduledDate) {
      const scheduledDate = new Date(schedule.scheduledDate);
      if (
        (startDate && scheduledDate < startDate) ||
        (endDate && scheduledDate > endDate)
      ) {
        invalidSchedulingMatchUpIds.push(matchUpId);
        if (!invalidScheduledDates.includes(schedule.scheduledDate))
          invalidScheduledDates.push(schedule.scheduledDate);
      }
    }
  }

  if (invalidScheduledDates.length) {
    const result = clearScheduledMatchUps({
      scheduledDates: invalidScheduledDates,
      tournamentRecord,
    });
    if (!result.clearedScheduleCount) return { error: SCHEDULE_NOT_CLEARED };
  }

  return { unscheduledMatchUpIds: invalidSchedulingMatchUpIds };
}
// unschedule scheduled matchUps that fall outside of tournament dates
unschedule scheduled matchUps that fall outside of tournament dates
unschedule scheduled matchUps that fall outside of tournament dates
function removeInvalidScheduling({ tournamentRecord }) {
  const { matchUps } = allTournamentMatchUps({ tournamentRecord });
  const startDate =
    tournamentRecord.startDate && new Date(tournamentRecord.startDate);
  const endDate =
    tournamentRecord.endDate && new Date(tournamentRecord.endDate);
  const invalidScheduledDates = [];
  const invalidSchedulingMatchUpIds = [];
  for (const matchUp of matchUps) {
    const { schedule, matchUpId } = matchUp;
    if (!schedule) continue;
    if (schedule.scheduledDate) {
      const scheduledDate = new Date(schedule.scheduledDate);
      if (
        (startDate && scheduledDate < startDate) ||
        (endDate && scheduledDate > endDate)
      ) {
        invalidSchedulingMatchUpIds.push(matchUpId);
        if (!invalidScheduledDates.includes(schedule.scheduledDate))
          invalidScheduledDates.push(schedule.scheduledDate);
      }
    }
  }
  if (invalidScheduledDates.length) {
    const result = clearScheduledMatchUps({
      scheduledDates: invalidScheduledDates,
      tournamentRecord,
    });
    if (!result.clearedScheduleCount) return { error: SCHEDULE_NOT_CLEARED };
  }
  return { unscheduledMatchUpIds: invalidSchedulingMatchUpIds };
}
function removeInvalidScheduling ( { tournamentRecord } ) { const { matchUps } = allTournamentMatchUps ( { tournamentRecord } ) ; const startDate = tournamentRecord . startDate && new Date ( tournamentRecord . startDate ) ; const endDate = tournamentRecord . endDate && new Date ( tournamentRecord . endDate ) ; const invalidScheduledDates = [ ] ; const invalidSchedulingMatchUpIds = [ ] ; for ( const matchUp of matchUps ) { const { schedule , matchUpId } = matchUp ; if ( ! schedule ) continue ; if ( schedule . scheduledDate ) { const scheduledDate = new Date ( schedule . scheduledDate ) ; if ( ( startDate && scheduledDate < startDate ) || ( endDate && scheduledDate > endDate ) ) { invalidSchedulingMatchUpIds . push ( matchUpId ) ; if ( ! invalidScheduledDates . includes ( schedule . scheduledDate ) ) invalidScheduledDates . push ( schedule . scheduledDate ) ; } } } if ( invalidScheduledDates . length ) { const result = clearScheduledMatchUps ( { scheduledDates : invalidScheduledDates , tournamentRecord , } ) ; if ( ! result . clearedScheduleCount ) return { error : SCHEDULE_NOT_CLEARED } ; } return { unscheduledMatchUpIds : invalidSchedulingMatchUpIds } ; }
unschedule scheduled matchUps that fall outside of tournament dates
unschedule scheduled matchUps that fall outside of tournament dates