feat: refresh the home page and separate match event types
Add an inhouse hero, Hall of Fame, rankings, and event-specific schedules. Carry the event type through the API and admin tools, and improve results and player history displays.
This commit is contained in:
1 parent
7e0cd7cb19
commit
664af15255
58 files changed
+2316
-593
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import mongoose, { Schema, HydratedDocument } from 'mongoose';
|
||||
import type { MatchEventType } from '@lolympus/contracts';
|
||||
import type {
|
||||
RiotPlatformRoute,
|
||||
RiotRegionalRoute,
|
||||
@@ -38,6 +39,8 @@ export const MATCH_STATUSES: MatchStatus[] = [
|
||||
'finished',
|
||||
];
|
||||
|
||||
export const MATCH_EVENT_TYPES = ['inhouse', 'tournament'] as const satisfies readonly MatchEventType[];
|
||||
|
||||
export type TeamSide = 'blue' | 'red';
|
||||
export const TEAM_SIDES: TeamSide[] = ['blue', 'red'];
|
||||
|
||||
@@ -686,6 +689,7 @@ export interface Match extends MongooseTimestamps {
|
||||
competitionId?: mongoose.Types.ObjectId;
|
||||
shortCode?: string;
|
||||
title: string;
|
||||
eventType?: MatchEventType;
|
||||
description: string;
|
||||
mapId: number; // Riot Match-V5 mapId (11=소환사의 협곡, 12=ARAM 등)
|
||||
status: MatchStatus;
|
||||
@@ -1954,6 +1958,7 @@ export const MatchSchema = new Schema<Match>(
|
||||
maxlength: 6,
|
||||
},
|
||||
title: { type: String, required: true },
|
||||
eventType: { type: String, enum: MATCH_EVENT_TYPES, default: 'inhouse' },
|
||||
description: { type: String, required: false, default: '' },
|
||||
mapId: { type: Number, required: true, default: 11 },
|
||||
status: {
|
||||
|
||||
@@ -79,3 +79,30 @@ describe('Grand final format validation', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Match event type validation', () => {
|
||||
it.each(['inhouse', 'tournament', undefined])(
|
||||
'accepts %s in create and update requests',
|
||||
(eventType) => {
|
||||
expect(
|
||||
validateSync(
|
||||
plainToInstance(CreateMatchDto, {
|
||||
title: 'Competition',
|
||||
scheduledAt: '2026-07-13T10:00:00.000Z',
|
||||
eventType,
|
||||
}),
|
||||
),
|
||||
).toEqual([]);
|
||||
expect(validateSync(plainToInstance(UpdateMatchDto, { eventType }))).toEqual(
|
||||
[],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(['double-elimination', null])('rejects %s as an event type', (eventType) => {
|
||||
const dto = plainToInstance(UpdateMatchDto, { eventType });
|
||||
expect(validateSync(dto)).toEqual([
|
||||
expect.objectContaining({ property: 'eventType' }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { GrandFinalGameCount } from '@lolympus/contracts';
|
||||
import type { GrandFinalGameCount, MatchEventType } from '@lolympus/contracts';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
ArrayMaxSize,
|
||||
@@ -15,11 +15,12 @@ import {
|
||||
MaxLength,
|
||||
Min,
|
||||
MinLength,
|
||||
ValidateIf,
|
||||
ValidateNested,
|
||||
ValidationArguments,
|
||||
ValidationOptions,
|
||||
} from 'class-validator';
|
||||
import { POSITIONS } from '../../global/database/schema';
|
||||
import { MATCH_EVENT_TYPES, POSITIONS } from '../../global/database/schema';
|
||||
import type { MatchGameMode, Position } from '../../global/database/schema';
|
||||
|
||||
const LIVE_MATCH_GAME_MODES = [
|
||||
@@ -83,6 +84,10 @@ export class CreateMatchDto {
|
||||
@MaxLength(128)
|
||||
title!: string;
|
||||
|
||||
@ValidateIf((_object, value) => value !== undefined)
|
||||
@IsIn(MATCH_EVENT_TYPES)
|
||||
eventType?: MatchEventType;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(2048)
|
||||
@@ -150,6 +155,10 @@ export class UpdateMatchDto {
|
||||
@MaxLength(128)
|
||||
title?: string;
|
||||
|
||||
@ValidateIf((_object, value) => value !== undefined)
|
||||
@IsIn(MATCH_EVENT_TYPES)
|
||||
eventType?: MatchEventType;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(2048)
|
||||
|
||||
@@ -37,8 +37,11 @@ const finishedMatch = {
|
||||
};
|
||||
const singleSeries = {
|
||||
status: 'completed',
|
||||
entries: [{ gameWins: 2 }, { gameWins: 1 }],
|
||||
outcome: { type: 'played', winnerTeamId: firstId.toString() },
|
||||
entries: [
|
||||
{ teamId: secondId.toString(), gameWins: 2 },
|
||||
{ teamId: firstId.toString(), gameWins: 1 },
|
||||
],
|
||||
outcome: { type: 'played', winnerTeamId: secondId.toString() },
|
||||
};
|
||||
|
||||
describe('summarizeMatchHistoryResult', () => {
|
||||
@@ -55,7 +58,9 @@ describe('summarizeMatchHistoryResult', () => {
|
||||
type: 'score',
|
||||
teamAWins: 2,
|
||||
teamBWins: 1,
|
||||
winnerTeamName: '첫 팀',
|
||||
teamAName: '둘째 팀',
|
||||
teamBName: '첫 팀',
|
||||
winnerTeamName: '둘째 팀',
|
||||
});
|
||||
expect(
|
||||
summarizeMatchHistoryResult(
|
||||
@@ -91,7 +96,7 @@ describe('summarizeMatchHistoryResult', () => {
|
||||
).toEqual({
|
||||
type: 'decision',
|
||||
decision: 'forfeit',
|
||||
winnerTeamName: '첫 팀',
|
||||
winnerTeamName: '둘째 팀',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -126,8 +131,8 @@ describe('summarizeMatchHistoryResult', () => {
|
||||
const match = {
|
||||
status: 'finished' as const,
|
||||
teams: [
|
||||
{ teamIndex: 1, name: '첫 팀', members: [] },
|
||||
{ teamIndex: 2, name: '둘째 팀', members: [] },
|
||||
{ teamIndex: 1, name: '첫 팀', members: [] },
|
||||
],
|
||||
result: {
|
||||
winnerTeamIndex: 2,
|
||||
@@ -152,6 +157,8 @@ describe('summarizeMatchHistoryResult', () => {
|
||||
type: 'score',
|
||||
teamAWins: 0,
|
||||
teamBWins: 1,
|
||||
teamAName: '첫 팀',
|
||||
teamBName: '둘째 팀',
|
||||
winnerTeamName: '둘째 팀',
|
||||
});
|
||||
expect(
|
||||
|
||||
@@ -23,7 +23,7 @@ export function summarizeMatchHistoryResult(
|
||||
>;
|
||||
if (!outcome) return;
|
||||
|
||||
const teamName = (teamId: string) => {
|
||||
const teamName = (teamId: string | null) => {
|
||||
const team = competition.teams.find(
|
||||
(item) => String(item.teamId) === teamId,
|
||||
);
|
||||
@@ -44,6 +44,8 @@ export function summarizeMatchHistoryResult(
|
||||
type: 'score',
|
||||
teamAWins: teamA.gameWins,
|
||||
teamBWins: teamB.gameWins,
|
||||
teamAName: teamName(teamA.teamId),
|
||||
teamBName: teamName(teamB.teamId),
|
||||
winnerTeamName,
|
||||
};
|
||||
}
|
||||
@@ -112,6 +114,8 @@ function summarizeLegacyResult(
|
||||
type: 'score',
|
||||
teamAWins,
|
||||
teamBWins,
|
||||
teamAName: teamA.name.trim() || `${teamA.teamIndex}팀`,
|
||||
teamBName: teamB.name.trim() || `${teamB.teamIndex}팀`,
|
||||
winnerTeamName: winner && (winner.name.trim() || `${winner.teamIndex}팀`),
|
||||
};
|
||||
}
|
||||
@@ -75,6 +75,7 @@ describe('presentPublicMatch', () => {
|
||||
communityId: oid('2').toString(),
|
||||
competitionId: oid('3').toString(),
|
||||
title: '내전',
|
||||
eventType: 'inhouse',
|
||||
doubleEliminationResetFinalEnabled: false,
|
||||
scheduledAt: '2026-07-12T10:00:00.000Z',
|
||||
participants: [
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { MatchDetailResponse, MatchTierView } from '@lolympus/contracts';
|
||||
import type {
|
||||
MatchDetailResponse,
|
||||
MatchEventType,
|
||||
MatchTierView,
|
||||
} from '@lolympus/contracts';
|
||||
import type {
|
||||
MatchGameMode,
|
||||
MatchStatus,
|
||||
@@ -13,6 +17,7 @@ interface PublicMatchSource {
|
||||
competitionId?: IdLike;
|
||||
shortCode?: string;
|
||||
title: string;
|
||||
eventType?: MatchEventType;
|
||||
description: string;
|
||||
mapId: number;
|
||||
status: MatchStatus;
|
||||
@@ -67,6 +72,7 @@ export function presentPublicMatch(
|
||||
: {}),
|
||||
...(source.shortCode ? { shortCode: source.shortCode } : {}),
|
||||
title: source.title,
|
||||
eventType: source.eventType ?? 'inhouse',
|
||||
description: source.description,
|
||||
mapId: source.mapId,
|
||||
status: source.status,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'reflect-metadata';
|
||||
import { GUARDS_METADATA } from '@nestjs/common/constants';
|
||||
import mongoose from 'mongoose';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
import { METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED } from '../auth/allow-public-access.decorator';
|
||||
import { ROLES_KEY } from '../auth/roles.decorator';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
import type { UserDocument } from '../global/database/schema';
|
||||
import { UpdateMatchDto } from './dto/create-match.dto';
|
||||
import { MatchController } from './match.controller';
|
||||
|
||||
describe('MatchController history summaries', () => {
|
||||
@@ -43,14 +45,40 @@ describe('MatchController history summaries', () => {
|
||||
undefined,
|
||||
'desc',
|
||||
'true',
|
||||
'tournament',
|
||||
),
|
||||
).resolves.toMatchObject({ matches: [{ ...summary, historyResult }] });
|
||||
expect(matchService.listPage).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ eventType: 'tournament' }),
|
||||
);
|
||||
expect(matchService.getHistoryResults).toHaveBeenCalledWith(communityId, [
|
||||
match,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('MatchController partial updates', () => {
|
||||
it('passes only supplied fields when reclassifying a match', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const user = { _id: new mongoose.Types.ObjectId(), communityId };
|
||||
const matchService = {
|
||||
update: jest.fn().mockResolvedValue({ participants: [] }),
|
||||
serialize: jest.fn(),
|
||||
};
|
||||
const controller = new MatchController(matchService as never);
|
||||
const body = plainToInstance(UpdateMatchDto, { eventType: 'tournament' });
|
||||
|
||||
await controller.updateMatch(user as UserDocument, communityId, matchId, body);
|
||||
|
||||
expect(matchService.update).toHaveBeenCalledWith({
|
||||
communityId,
|
||||
matchId,
|
||||
patch: { eventType: 'tournament' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('MatchController participant access', () => {
|
||||
function createController() {
|
||||
const joinedMatch = { _id: new mongoose.Types.ObjectId() };
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type {
|
||||
MatchDetailResponse,
|
||||
MatchEventType,
|
||||
MatchListResponse,
|
||||
} from '@lolympus/contracts';
|
||||
import {
|
||||
@@ -23,6 +24,7 @@ import { Roles } from '../auth/roles.decorator';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
import { ParseObjectIdPipe } from '../common/parse-object-id.pipe';
|
||||
import type { MatchStatus, UserDocument } from '../global/database/schema';
|
||||
import { MATCH_EVENT_TYPES } from '../global/database/schema';
|
||||
import {
|
||||
AddParticipantDto,
|
||||
CreateMatchDto,
|
||||
@@ -51,6 +53,7 @@ export class MatchController {
|
||||
hostUserId: currentUser._id,
|
||||
data: {
|
||||
title: body.title,
|
||||
eventType: body.eventType,
|
||||
description: body.description ?? '',
|
||||
mapId: body.mapId ?? 11,
|
||||
scheduledAt: body.scheduledAt,
|
||||
@@ -85,10 +88,15 @@ export class MatchController {
|
||||
@Query('scheduledTo') scheduledTo?: string,
|
||||
@Query('sort') sort?: 'asc' | 'desc',
|
||||
@Query('includeResults') includeResults?: string,
|
||||
@Query('eventType') eventType?: MatchEventType,
|
||||
): Promise<MatchListResponse> {
|
||||
if (eventType !== undefined && !MATCH_EVENT_TYPES.includes(eventType)) {
|
||||
throw new BadRequestException('Invalid eventType.');
|
||||
}
|
||||
const result = await this.matchService.listPage({
|
||||
communityId,
|
||||
status,
|
||||
eventType,
|
||||
limit: this.toOptionalNumber(limit),
|
||||
page: this.toOptionalNumber(page),
|
||||
offset: this.toOptionalNumber(offset),
|
||||
|
||||
@@ -280,6 +280,28 @@ describe('MatchService', () => {
|
||||
expect(sort).toHaveBeenCalledWith({ scheduledAt: -1 });
|
||||
});
|
||||
|
||||
it.each([
|
||||
['inhouse', { $in: ['inhouse', null] }],
|
||||
['tournament', 'tournament'],
|
||||
] as const)(
|
||||
'filters both results and pagination totals for %s events',
|
||||
async (eventType, expectedEventType) => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const scheduledTo = new Date('2026-06-08T12:00:00.000Z');
|
||||
const { service, MatchModel } = createServiceWithListModel();
|
||||
|
||||
await service.listPage({ communityId, scheduledTo, eventType });
|
||||
|
||||
const expectedFilter = {
|
||||
communityId,
|
||||
scheduledAt: { $lt: scheduledTo },
|
||||
eventType: expectedEventType,
|
||||
};
|
||||
expect(MatchModel.find).toHaveBeenCalledWith(expectedFilter);
|
||||
expect(MatchModel.countDocuments).toHaveBeenCalledWith(expectedFilter);
|
||||
},
|
||||
);
|
||||
|
||||
it('uses saved user preferences when joining without explicit positions', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const userId = new mongoose.Types.ObjectId();
|
||||
@@ -637,6 +659,26 @@ describe('MatchService', () => {
|
||||
expect(match.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows reclassifying a finished match without altering its competition settings', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const match = {
|
||||
communityId,
|
||||
status: 'finished',
|
||||
set: jest.fn(),
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const { service } = createService(match);
|
||||
|
||||
await service.update({
|
||||
matchId: new mongoose.Types.ObjectId(),
|
||||
communityId,
|
||||
patch: { eventType: 'tournament' },
|
||||
});
|
||||
|
||||
expect(match.set).toHaveBeenCalledWith({ eventType: 'tournament' });
|
||||
expect(match.save).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('rejects game count changes after recruiting', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const match = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { MatchHistoryResult } from '@lolympus/contracts';
|
||||
import type { MatchEventType, MatchHistoryResult } from '@lolympus/contracts';
|
||||
import {
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
@@ -57,6 +57,7 @@ interface UpdateMatchParams {
|
||||
interface ListMatchesQuery {
|
||||
communityId: mongoose.Types.ObjectId;
|
||||
status?: MatchStatus;
|
||||
eventType?: MatchEventType;
|
||||
limit?: number;
|
||||
scheduledFrom?: Date;
|
||||
scheduledTo?: Date;
|
||||
@@ -71,6 +72,7 @@ interface ListMatchesPageQuery extends ListMatchesQuery {
|
||||
interface MatchListFilter {
|
||||
communityId: mongoose.Types.ObjectId;
|
||||
status?: MatchStatus;
|
||||
eventType?: MatchEventType | { $in: (MatchEventType | null)[] };
|
||||
scheduledAt?: {
|
||||
$gte?: Date;
|
||||
$lt?: Date;
|
||||
@@ -712,6 +714,11 @@ export class MatchService {
|
||||
communityId: query.communityId,
|
||||
};
|
||||
if (query.status) filter.status = query.status;
|
||||
if (query.eventType) {
|
||||
// MongoDB matches missing fields as well as explicit null values.
|
||||
filter.eventType =
|
||||
query.eventType === 'inhouse' ? { $in: ['inhouse', null] } : query.eventType;
|
||||
}
|
||||
if (query.scheduledFrom || query.scheduledTo) {
|
||||
filter.scheduledAt = {};
|
||||
if (query.scheduledFrom) filter.scheduledAt.$gte = query.scheduledFrom;
|
||||
|
||||
Reference in new issue
Block a user