function assignMatchUpSideParticipant({
  tournamentRecord,
  drawDefinition,
  participantId,
  sideNumber,
  matchUpId,
  event,
}) {
  if (participantId && typeof participantId !== 'string')
    return { error: INVALID_PARTICIPANT_ID };
  if (!drawDefinition) return { error: MISSING_DRAW_DEFINITION };
  if (!sideNumber) return { error: MISSING_SIDE_NUMBER };
  if (!matchUpId) return { error: MISSING_MATCHUP_ID };

  if (![1, 2].includes(sideNumber))
    return { error: INVALID_VALUES, sideNumber };

  const { matchUp, structure } = findMatchUp({
    drawDefinition,
    matchUpId,
    event,
  });

  const isAdHoc =
    !structure?.structures &&
    !(drawDefinition.drawType && drawDefinition.drawType !== AD_HOC) &&
    !structure?.matchUps.find(({ roundPosition }) => !!roundPosition);

  if (!isAdHoc) return { error: INVALID_DRAW_TYPE };

  // if no participantId / participant is being un-assigned, there cannot be a score or completed outcome
  if (
    !participantId &&
    (matchUp.score?.scoreStringSide1 ||
      completedMatchUpStatuses.includes(matchUp.matchUpstatus) ||
      [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus))
  )
    return {
      error: CANNOT_REMOVE_PARTICIPANTS,
      info: 'matchUp has completed status or score',
    };

  matchUp.sides = [1, 2].map((currentSideNumber) => {
    const existingSide = matchUp.sides?.find(
      (side) => side.sideNumber === currentSideNumber
    ) || { sideNumber: currentSideNumber };

    return sideNumber === currentSideNumber
      ? { ...existingSide, participantId }
      : existingSide;
  });

  modifyMatchUpNotice({
    tournamentId: tournamentRecord?.tournamentId,
    drawDefinition,
    matchUp,
  });

  return { ...SUCCESS };
}
// method only currently used for AD_HOC matchUps where there are no drawPositions
method only currently used for AD_HOC matchUps where there are no drawPositions
method only currently used for AD_HOC matchUps where there are no drawPositions
function assignMatchUpSideParticipant({
  tournamentRecord,
  drawDefinition,
  participantId,
  sideNumber,
  matchUpId,
  event,
}) {
  if (participantId && typeof participantId !== 'string')
    return { error: INVALID_PARTICIPANT_ID };
  if (!drawDefinition) return { error: MISSING_DRAW_DEFINITION };
  if (!sideNumber) return { error: MISSING_SIDE_NUMBER };
  if (!matchUpId) return { error: MISSING_MATCHUP_ID };
  if (![1, 2].includes(sideNumber))
    return { error: INVALID_VALUES, sideNumber };
  const { matchUp, structure } = findMatchUp({
    drawDefinition,
    matchUpId,
    event,
  });
  const isAdHoc =
    !structure?.structures &&
    !(drawDefinition.drawType && drawDefinition.drawType !== AD_HOC) &&
    !structure?.matchUps.find(({ roundPosition }) => !!roundPosition);
  if (!isAdHoc) return { error: INVALID_DRAW_TYPE };
  if (
    !participantId &&
    (matchUp.score?.scoreStringSide1 ||
      completedMatchUpStatuses.includes(matchUp.matchUpstatus) ||
      [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus))
  )
    return {
      error: CANNOT_REMOVE_PARTICIPANTS,
      info: 'matchUp has completed status or score',
    };
  matchUp.sides = [1, 2].map((currentSideNumber) => {
    const existingSide = matchUp.sides?.find(
      (side) => side.sideNumber === currentSideNumber
    ) || { sideNumber: currentSideNumber };
    return sideNumber === currentSideNumber
      ? { ...existingSide, participantId }
      : existingSide;
  });
  modifyMatchUpNotice({
    tournamentId: tournamentRecord?.tournamentId,
    drawDefinition,
    matchUp,
  });
  return { ...SUCCESS };
}
function assignMatchUpSideParticipant ( { tournamentRecord , drawDefinition , participantId , sideNumber , matchUpId , event , } ) { if ( participantId && typeof participantId !== 'string' ) return { error : INVALID_PARTICIPANT_ID } ; if ( ! drawDefinition ) return { error : MISSING_DRAW_DEFINITION } ; if ( ! sideNumber ) return { error : MISSING_SIDE_NUMBER } ; if ( ! matchUpId ) return { error : MISSING_MATCHUP_ID } ; if ( ! [ 1 , 2 ] . includes ( sideNumber ) ) return { error : INVALID_VALUES , sideNumber } ; const { matchUp , structure } = findMatchUp ( { drawDefinition , matchUpId , event , } ) ; const isAdHoc = ! structure ?. structures && ! ( drawDefinition . drawType && drawDefinition . drawType !== AD_HOC ) && ! structure ?. matchUps . find ( ( { roundPosition } ) => ! ! roundPosition ) ; if ( ! isAdHoc ) return { error : INVALID_DRAW_TYPE } ; if ( ! participantId && ( matchUp . score ?. scoreStringSide1 || completedMatchUpStatuses . includes ( matchUp . matchUpstatus ) || [ DOUBLE_WALKOVER , DOUBLE_DEFAULT ] . includes ( matchUp . matchUpStatus ) ) ) return { error : CANNOT_REMOVE_PARTICIPANTS , info : 'matchUp has completed status or score' , } ; matchUp . sides = [ 1 , 2 ] . map ( ( currentSideNumber ) => { const existingSide = matchUp . sides ?. find ( ( side ) => side . sideNumber === currentSideNumber ) || { sideNumber : currentSideNumber } ; return sideNumber === currentSideNumber ? { ... existingSide , participantId } : existingSide ; } ) ; modifyMatchUpNotice ( { tournamentId : tournamentRecord ?. tournamentId , drawDefinition , matchUp , } ) ; return { ... SUCCESS } ; }
method only currently used for AD_HOC matchUps where there are no drawPositions
method only currently used for AD_HOC matchUps where there are no drawPositions
// if no participantId / participant is being un-assigned, there cannot be a score or completed outcome