fix: close competition cutover integrity gaps
This commit is contained in:
1 parent
7ea2002975
commit
683d602d63
57 files changed
+4805
-1582
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import type { MatchDetailResponse, MatchTierView } from '@lolympus/contracts';
|
||||
import type {
|
||||
MatchGameMode,
|
||||
MatchStatus,
|
||||
@@ -57,12 +58,12 @@ interface PublicMatchSource {
|
||||
export function presentPublicMatch(
|
||||
source: PublicMatchSource,
|
||||
options: { joined?: boolean } = {},
|
||||
) {
|
||||
): MatchDetailResponse {
|
||||
return {
|
||||
_id: source._id.toString(),
|
||||
communityId: source.communityId.toString(),
|
||||
_id: source._id.toString() as never,
|
||||
communityId: source.communityId.toString() as never,
|
||||
...(source.competitionId
|
||||
? { competitionId: source.competitionId.toString() }
|
||||
? { competitionId: source.competitionId.toString() as never }
|
||||
: {}),
|
||||
...(source.shortCode ? { shortCode: source.shortCode } : {}),
|
||||
title: source.title,
|
||||
@@ -82,32 +83,37 @@ export function presentPublicMatch(
|
||||
source.doubleElimination?.resetFinalEnabled ?? false,
|
||||
}
|
||||
: {}),
|
||||
...(source.hostUserId ? { hostUserId: source.hostUserId.toString() } : {}),
|
||||
participants: source.participants.map((participant) => ({
|
||||
userId: participant.userId.toString(),
|
||||
...(participant.gameName ? { gameName: participant.gameName } : {}),
|
||||
...(participant.tagLine ? { tagLine: participant.tagLine } : {}),
|
||||
...(participant.profileIconId === undefined
|
||||
? {}
|
||||
: { profileIconId: participant.profileIconId }),
|
||||
...(participant.tier === undefined
|
||||
? {}
|
||||
: { tier: toWireValue(participant.tier) }),
|
||||
preferredPositions: participant.preferredPositions.map((preference) => ({
|
||||
position: preference.position,
|
||||
priority: preference.priority,
|
||||
})),
|
||||
joinedAt: asIso(participant.joinedAt),
|
||||
excluded: participant.excluded ?? false,
|
||||
})),
|
||||
...(source.hostUserId
|
||||
? { hostUserId: source.hostUserId.toString() as never }
|
||||
: {}),
|
||||
participants: source.participants.map((participant) => {
|
||||
const tier = toPublicTier(participant.tier);
|
||||
return {
|
||||
userId: participant.userId.toString() as never,
|
||||
...(participant.gameName ? { gameName: participant.gameName } : {}),
|
||||
...(participant.tagLine ? { tagLine: participant.tagLine } : {}),
|
||||
...(participant.profileIconId === undefined
|
||||
? {}
|
||||
: { profileIconId: participant.profileIconId }),
|
||||
...(tier ? { tier } : {}),
|
||||
preferredPositions: participant.preferredPositions.map(
|
||||
(preference) => ({
|
||||
position: preference.position,
|
||||
priority: preference.priority,
|
||||
}),
|
||||
),
|
||||
joinedAt: asIso(participant.joinedAt),
|
||||
excluded: participant.excluded ?? false,
|
||||
};
|
||||
}),
|
||||
teams: source.teams.map((team) => ({
|
||||
teamIndex: team.teamIndex,
|
||||
name: team.name,
|
||||
...(team.captainUserId
|
||||
? { captainUserId: team.captainUserId.toString() }
|
||||
? { captainUserId: team.captainUserId.toString() as never }
|
||||
: {}),
|
||||
members: team.members.map((member) => ({
|
||||
userId: member.userId.toString(),
|
||||
userId: member.userId.toString() as never,
|
||||
assignedPosition: member.assignedPosition,
|
||||
...(member.cost === undefined ? {} : { cost: member.cost }),
|
||||
})),
|
||||
@@ -115,7 +121,7 @@ export function presentPublicMatch(
|
||||
prizes: [...source.prizes],
|
||||
notices: [...source.notices],
|
||||
schedule: source.schedule.map(({ time, label }) => ({ time, label })),
|
||||
...(options.joined === undefined ? {} : { joined: options.joined }),
|
||||
joined: options.joined ?? false,
|
||||
createdAt: asIso(source.createdAt),
|
||||
updatedAt: asIso(source.updatedAt),
|
||||
};
|
||||
@@ -125,13 +131,29 @@ function asIso(value: Date | string): string {
|
||||
return value instanceof Date ? value.toISOString() : value;
|
||||
}
|
||||
|
||||
function toWireValue(value: unknown): unknown {
|
||||
if (value instanceof Date) return value.toISOString();
|
||||
if (Array.isArray(value)) return value.map(toWireValue);
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).map(([key, child]) => [key, toWireValue(child)]),
|
||||
);
|
||||
function toPublicTier(value: unknown): MatchTierView | undefined {
|
||||
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
const tier = value as Record<string, unknown>;
|
||||
if (
|
||||
typeof tier.queueType !== 'string' ||
|
||||
typeof tier.tier !== 'string' ||
|
||||
typeof tier.rank !== 'string' ||
|
||||
typeof tier.leaguePoints !== 'number' ||
|
||||
typeof tier.wins !== 'number' ||
|
||||
typeof tier.losses !== 'number' ||
|
||||
!(typeof tier.fetchedAt === 'string' || tier.fetchedAt instanceof Date)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
queueType: tier.queueType,
|
||||
tier: tier.tier,
|
||||
rank: tier.rank,
|
||||
leaguePoints: tier.leaguePoints,
|
||||
wins: tier.wins,
|
||||
losses: tier.losses,
|
||||
fetchedAt: asIso(tier.fetchedAt),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user