diff --git a/src/query/base/timeItems.ts b/src/query/base/timeItems.ts index e91be8b651..47b2736b8f 100644 --- a/src/query/base/timeItems.ts +++ b/src/query/base/timeItems.ts @@ -1,4 +1,5 @@ import { findTournamentParticipant } from '@Acquire/findTournamentParticipant'; +import { makeDeepCopy } from '@Tools/makeDeepCopy'; import { deriveElement } from './deriveElement'; // constants and types @@ -53,7 +54,7 @@ export function getTimeItem(params: TimeItemArgs): TimeItemResult & ResultType { return aDate - bDate; }); - const timeItem = filteredSorted.pop(); + const timeItem = makeDeepCopy(filteredSorted.pop(), false, true); if (timeItem) { const result = { timeItem, ...SUCCESS }; diff --git a/src/query/participants/getParticipantMap.ts b/src/query/participants/getParticipantMap.ts index 1dc58f02b1..d0a363ecea 100644 --- a/src/query/participants/getParticipantMap.ts +++ b/src/query/participants/getParticipantMap.ts @@ -44,9 +44,12 @@ export function getParticipantMap({ withISO2, withIOC, }: GetParticpantsMapArgs): { + missingParticipantIds: string[]; participantMap: ParticipantMap; } { + const missingParticipantIds: string[] = []; const participantMap: ParticipantMap = {}; + // initialize all participants first, to preserve order for (const participant of tournamentRecord.participants ?? []) { const participantId = participant?.participantId; @@ -61,13 +64,16 @@ export function getParticipantMap({ Object.assign(participantMap[participantId].participant, participantCopy); if (individualParticipantIds) { - processIndividualParticipantIds({ + const result = processIndividualParticipantIds({ individualParticipantIds, participantCopy, participantMap, participantType, participantId, }); + if (result.missingParticipantIds.length) { + missingParticipantIds.push(...result.missingParticipantIds); + } } if (withSignInStatus) { @@ -96,7 +102,7 @@ export function getParticipantMap({ addIndividualParticipants({ participantMap, template }); } - return { participantMap }; + return { missingParticipantIds, participantMap }; } function signedIn(participant) { @@ -115,8 +121,14 @@ function processIndividualParticipantIds({ participantType, participantId, }) { + const missingParticipantIds: string[] = []; + for (const individualParticipantId of individualParticipantIds) { - const individualParticipant = participantMap[individualParticipantId].participant; + const individualParticipant = participantMap[individualParticipantId]?.participant; + if (!individualParticipant) { + missingParticipantIds.push(individualParticipantId); + continue; + } individualParticipant[typeMap[participantType]].push(participantId); if ([TEAM, GROUP].includes(participantType)) { @@ -138,6 +150,8 @@ function processIndividualParticipantIds({ participantMap[individualParticipantId].pairIdMap[partnerParticipantId] = participantId; } } + + return { missingParticipantIds }; } function initializeParticipantId({ participantMap, participantId }) { diff --git a/src/query/participants/getParticipants.ts b/src/query/participants/getParticipants.ts index bc039ecaa4..4d8abb433d 100644 --- a/src/query/participants/getParticipants.ts +++ b/src/query/participants/getParticipants.ts @@ -26,6 +26,7 @@ type GetParticipantsArgs = { scheduleAnalysis?: ScheduleAnalysis; policyDefinitions?: PolicyDefinitions; withPotentialMatchUps?: boolean; + returnParticipantMap?: boolean; // defaults to true contextProfile?: ContextProfile; tournamentRecord: Tournament; withRankingProfile?: boolean; @@ -35,6 +36,7 @@ type GetParticipantsArgs = { withTeamMatchUps?: boolean; withScaleValues?: boolean; usePublishState?: boolean; + returnMatchUps?: boolean; // defaults to true withStatistics?: boolean; withOpponents?: boolean; withMatchUps?: boolean; @@ -49,6 +51,7 @@ export function getParticipants(params: GetParticipantsArgs): { eventsPublishStatuses?: { [key: string]: any }; participantIdsWithConflicts?: string[]; participants?: HydratedParticipant[]; + missingParticipantIds?: string[]; participantMap?: ParticipantMap; derivedEventInfo?: any; derivedDrawInfo?: any; @@ -89,7 +92,7 @@ export function getParticipants(params: GetParticipantsArgs): { getMatchUpDependencies({ tournamentRecord }); // ensure goesTos are present } - let { participantMap } = getParticipantMap({ + const mapResult = getParticipantMap({ convertExtensions, tournamentRecord, withSignInStatus, @@ -99,6 +102,8 @@ export function getParticipants(params: GetParticipantsArgs): { withIOC, }); + let { participantMap } = mapResult; + const entriesResult = getParticipantEntries({ withMatchUps: withMatchUps ?? withRankingProfile, withEvents: withEvents ?? withRankingProfile, @@ -199,17 +204,17 @@ export function getParticipants(params: GetParticipantsArgs): { : filteredParticipants; // IDEA: optimizePayload derive array of matchUpIds required for filteredParticipants - // filter mappedMatchUps and matchUps to reduce over-the-wire payloads return { + participantMap: params.returnParticipantMap !== false ? participantMap : undefined, + mappedMatchUps: params.returnMatchUps !== false ? mappedMatchUps : undefined, + matchUps: params.returnMatchUps !== false ? matchUps : undefined, + missingParticipantIds: mapResult.missingParticipantIds, participantIdsWithConflicts, eventsPublishStatuses, derivedEventInfo, derivedDrawInfo, - mappedMatchUps, - participantMap, participants, ...SUCCESS, - matchUps, }; } diff --git a/src/query/tournaments/analyzeTournament.ts b/src/query/tournaments/analyzeTournament.ts index cf25e996a7..772693b6a3 100644 --- a/src/query/tournaments/analyzeTournament.ts +++ b/src/query/tournaments/analyzeTournament.ts @@ -1,6 +1,8 @@ -import { analyzeDraws } from './analyzeDraws'; -import { checkIsDual } from './checkIsDual'; +import { getParticipants } from '@Query/participants/getParticipants'; +import { analyzeDraws } from '@Query/tournaments/analyzeDraws'; +import { checkIsDual } from '@Query/tournaments/checkIsDual'; +// constants import { MISSING_TOURNAMENT_RECORD } from '@Constants/errorConditionConstants'; import { SUCCESS } from '@Constants/resultConstants'; @@ -9,10 +11,15 @@ export function analyzeTournament({ tournamentRecord }) { const { drawsAnalysis } = analyzeDraws({ tournamentRecord }); - const analysis = { + const analysis: any = { isDual: checkIsDual(tournamentRecord), drawsAnalysis, }; + const participantResult = getParticipants({ tournamentRecord }); + if (participantResult.missingParticipantIds?.length) { + analysis.missingParticipantIds = participantResult.missingParticipantIds; + } + return { ...SUCCESS, analysis }; } diff --git a/src/query/tournaments/getTournamentInfo.ts b/src/query/tournaments/getTournamentInfo.ts index ca2396f791..a94d921345 100644 --- a/src/query/tournaments/getTournamentInfo.ts +++ b/src/query/tournaments/getTournamentInfo.ts @@ -62,12 +62,13 @@ export function getTournamentInfo(params?: { tournamentRecord: Tournament; usePu updatedAt, }))(tournamentRecord); - const tournamentContacts = getParticipants({ + const participantResult = getParticipants({ participantFilters: { participantRoles: [ADMINISTRATION, OFFICIAL, MEDIA, MEDICAL, SECURITY] }, policyDefinitions: POLICY_PRIVACY_STAFF, tournamentRecord, - }).participants; + }); + const tournamentContacts = participantResult?.participants ?? []; if (tournamentContacts) tournamentInfo.tournamentContacts = tournamentContacts; const publishState = getPublishState({ tournamentRecord })?.publishState;