Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
CourtHive committed Apr 1, 2024
2 parents 1d3318c + 52cc39b commit acf5e24
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/query/base/timeItems.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { findTournamentParticipant } from '@Acquire/findTournamentParticipant';
import { makeDeepCopy } from '@Tools/makeDeepCopy';
import { deriveElement } from './deriveElement';

// constants and types
Expand Down Expand Up @@ -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 };
Expand Down
20 changes: 17 additions & 3 deletions src/query/participants/getParticipantMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -96,7 +102,7 @@ export function getParticipantMap({
addIndividualParticipants({ participantMap, template });
}

return { participantMap };
return { missingParticipantIds, participantMap };
}

function signedIn(participant) {
Expand All @@ -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)) {
Expand All @@ -138,6 +150,8 @@ function processIndividualParticipantIds({
participantMap[individualParticipantId].pairIdMap[partnerParticipantId] = participantId;
}
}

return { missingParticipantIds };
}

function initializeParticipantId({ participantMap, participantId }) {
Expand Down
15 changes: 10 additions & 5 deletions src/query/participants/getParticipants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type GetParticipantsArgs = {
scheduleAnalysis?: ScheduleAnalysis;
policyDefinitions?: PolicyDefinitions;
withPotentialMatchUps?: boolean;
returnParticipantMap?: boolean; // defaults to true
contextProfile?: ContextProfile;
tournamentRecord: Tournament;
withRankingProfile?: boolean;
Expand All @@ -35,6 +36,7 @@ type GetParticipantsArgs = {
withTeamMatchUps?: boolean;
withScaleValues?: boolean;
usePublishState?: boolean;
returnMatchUps?: boolean; // defaults to true
withStatistics?: boolean;
withOpponents?: boolean;
withMatchUps?: boolean;
Expand All @@ -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;
Expand Down Expand Up @@ -89,7 +92,7 @@ export function getParticipants(params: GetParticipantsArgs): {
getMatchUpDependencies({ tournamentRecord }); // ensure goesTos are present
}

let { participantMap } = getParticipantMap({
const mapResult = getParticipantMap({
convertExtensions,
tournamentRecord,
withSignInStatus,
Expand All @@ -99,6 +102,8 @@ export function getParticipants(params: GetParticipantsArgs): {
withIOC,
});

let { participantMap } = mapResult;

const entriesResult = getParticipantEntries({
withMatchUps: withMatchUps ?? withRankingProfile,
withEvents: withEvents ?? withRankingProfile,
Expand Down Expand Up @@ -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,
};
}
13 changes: 10 additions & 3 deletions src/query/tournaments/analyzeTournament.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 };
}
5 changes: 3 additions & 2 deletions src/query/tournaments/getTournamentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit acf5e24

Please sign in to comment.