refactor: whitelist public match responses

This commit is contained in:
dahyeon committed 2026-07-12 19:28:04 +00:00
1 parent 874d785381
commit 28e9ac1529
4 files changed
+248 -40

No files matched your search

+10 -23
View File
@@ -27,6 +27,7 @@ import {
} from '../global/database/schema';
import { DEFAULT_TOURNAMENT_GAME_COUNT } from '../tournament-code/tournament-code.constants';
import { TournamentCodeService } from '../tournament-code/tournament-code.service';
import { presentPublicMatch } from './match-public.presenter';
const MATCH_SHORT_CODE_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
const MATCH_SHORT_CODE_LENGTH = 4;
@@ -218,30 +219,16 @@ export class MatchService {
return match;
}
public async serialize(match: MatchDocument) {
public serialize(match: MatchDocument, options: { joined?: boolean } = {}) {
const obj = match.toObject();
if (obj.result?.games) {
obj.result.games = [...obj.result.games].sort(
(left, right) => left.gameNumber - right.gameNumber,
);
if (!obj.result.seriesResults?.length) {
obj.result.seriesResults = this.buildSeriesResults(obj.result.games);
}
}
return {
...obj,
gameCount: match.gameCount || DEFAULT_TOURNAMENT_GAME_COUNT,
gameMode: match.gameMode ?? 'pair',
participants: (obj.participants ?? []).map((participant) => ({
...participant,
excluded: participant.excluded ?? false,
})),
teams: (obj.teams ?? []).map((team) => ({
...team,
})),
gameSchedule: obj.gameSchedule ?? [],
tournamentCodes: await this.tournamentCodeService.buildSlots(match),
};
return presentPublicMatch(
{
...obj,
gameCount: match.gameCount || DEFAULT_TOURNAMENT_GAME_COUNT,
gameMode: match.gameMode ?? 'pair',
} as never,
options,
);
}
public async update(params: UpdateMatchParams): Promise<MatchDocument> {