feat: support double-elimination series games

This commit is contained in:
dahyeon committed 2026-07-07 17:34:59 -07:00
1 parent 2ee8c3807b
commit e188828423
16 files changed
+1176 -234

No files matched your search

@@ -491,7 +491,7 @@ describe('MatchService', () => {
expect(createdPayloads[0]).toMatchObject({
communityId,
maxParticipants: 20,
gameCount: 1,
gameCount: 5,
gameMode: 'double-elimination',
roundRobinMaxRounds: undefined,
doubleElimination: {
@@ -519,7 +519,9 @@ describe('MatchService', () => {
gameMode: 'double-elimination',
},
}),
).rejects.toThrow('Double elimination supports only 20 or 40 participants.');
).rejects.toThrow(
'Double elimination supports only 20 or 40 participants.',
);
expect(MatchModel.create).not.toHaveBeenCalled();
});
+28 -15
View File
@@ -34,6 +34,7 @@ const MATCH_SHORT_CODE_GENERATION_ATTEMPTS = 20;
const DEFAULT_MATCH_LIST_LIMIT = 50;
const MAX_MATCH_LIST_LIMIT = 200;
const DOUBLE_ELIMINATION_PARTICIPANT_COUNTS = [20, 40] as const;
const DEFAULT_DOUBLE_ELIMINATION_SERIES_GAME_COUNT = 3;
interface DoubleEliminationConfigInput {
doubleEliminationResetFinalEnabled?: boolean;
@@ -109,21 +110,18 @@ interface DoubleEliminationAdminParams {
actorUserId: mongoose.Types.ObjectId;
}
interface SwapDoubleEliminationSeedsParams
extends DoubleEliminationAdminParams {
interface SwapDoubleEliminationSeedsParams extends DoubleEliminationAdminParams {
leftSeedNumber: number;
rightSeedNumber: number;
}
interface ApplyDoubleEliminationWalkoverParams
extends DoubleEliminationAdminParams {
interface ApplyDoubleEliminationWalkoverParams extends DoubleEliminationAdminParams {
bracketMatchId: string;
winnerTeamIndex: number;
reason?: string;
}
interface CancelDoubleEliminationActionParams
extends DoubleEliminationAdminParams {
interface CancelDoubleEliminationActionParams extends DoubleEliminationAdminParams {
bracketMatchId: string;
reason?: string;
}
@@ -529,9 +527,9 @@ export class MatchService {
return await this.throwJoinFailure(MatchModel, params.matchId, user);
}
private normalizeMatchConfig<T extends Partial<Match> & DoubleEliminationConfigInput>(
input: T,
): Partial<Match> {
private normalizeMatchConfig<
T extends Partial<Match> & DoubleEliminationConfigInput,
>(input: T): Partial<Match> {
const patch = this.stripMatchConfigInput(input);
const gameMode = (patch.gameMode ?? 'pair') as MatchGameMode;
const maxParticipants = patch.maxParticipants ?? 10;
@@ -550,7 +548,9 @@ export class MatchService {
...patch,
gameMode,
maxParticipants,
gameCount: 1,
gameCount: this.normalizeDoubleEliminationSeriesGameCount(
patch.gameCount ?? DEFAULT_DOUBLE_ELIMINATION_SERIES_GAME_COUNT,
),
roundRobinMaxRounds: undefined,
gameSchedule: [],
doubleElimination: {
@@ -575,13 +575,20 @@ export class MatchService {
};
}
private stripMatchConfigInput<T extends Partial<Match> & DoubleEliminationConfigInput>(
input: T,
): Partial<Match> {
private stripMatchConfigInput<
T extends Partial<Match> & DoubleEliminationConfigInput,
>(input: T): Partial<Match> {
const { doubleEliminationResetFinalEnabled: _ignored, ...patch } = input;
return patch;
}
private normalizeDoubleEliminationSeriesGameCount(gameCount: number): number {
if (!Number.isInteger(gameCount) || gameCount < 1) {
return DEFAULT_DOUBLE_ELIMINATION_SERIES_GAME_COUNT;
}
return gameCount % 2 === 0 ? gameCount + 1 : gameCount;
}
private async loadDoubleEliminationMatch(params: {
matchId: mongoose.Types.ObjectId;
communityId: mongoose.Types.ObjectId;
@@ -836,7 +843,10 @@ export class MatchService {
private async throwJoinFailure(
MatchModel: mongoose.Model<Match>,
matchId: mongoose.Types.ObjectId,
user: { _id: mongoose.Types.ObjectId; communityId: mongoose.Types.ObjectId },
user: {
_id: mongoose.Types.ObjectId;
communityId: mongoose.Types.ObjectId;
},
): Promise<never> {
const match = await MatchModel.findById(matchId);
if (!match) throw new NotFoundException('Match not found.');
@@ -864,7 +874,10 @@ export class MatchService {
private async throwCancelJoinFailure(
MatchModel: mongoose.Model<Match>,
matchId: mongoose.Types.ObjectId,
user: { _id: mongoose.Types.ObjectId; communityId: mongoose.Types.ObjectId },
user: {
_id: mongoose.Types.ObjectId;
communityId: mongoose.Types.ObjectId;
},
): Promise<never> {
const match = await MatchModel.findById(matchId);
if (!match) throw new NotFoundException('Match not found.');