feat(api): add community statistics aggregation

This commit is contained in:
dahyeon committed 2026-04-12 06:37:00 +09:00
1 parent 1d335de216
commit 43435f2c5e
5 files changed
+1453

No files matched your search

@@ -0,0 +1,115 @@
import { Controller, Get, Param, Query } from '@nestjs/common';
import mongoose from 'mongoose';
import { AllowPublicAccess } from '../auth/allow-public-access.decorator';
import { ParseObjectIdPipe } from '../common/parse-object-id.pipe';
import { CommunityStatsService } from './community-stats.service';
import type { CommunityStatsFilters } from './community-stats.types';
@Controller('communities/:communityId')
export class CommunityStatsController {
constructor(private readonly communityStatsService: CommunityStatsService) {}
@Get('internal-stats/matches')
@AllowPublicAccess()
public getMatches(
@Param('communityId', ParseObjectIdPipe)
communityId: mongoose.Types.ObjectId,
@Query('seasonId') seasonId?: string,
@Query('from') from?: string,
@Query('to') to?: string,
@Query('championId') championId?: string,
@Query('cursor') cursor?: string,
@Query('limit') limit?: string,
) {
return this.communityStatsService.getMatches({
communityId,
filters: this.toFilters({ seasonId, from, to, championId, cursor, limit }),
});
}
@Get('internal-stats/leaderboard')
@AllowPublicAccess()
public getLeaderboard(
@Param('communityId', ParseObjectIdPipe)
communityId: mongoose.Types.ObjectId,
@Query('seasonId') seasonId?: string,
@Query('from') from?: string,
@Query('to') to?: string,
@Query('championId') championId?: string,
) {
return this.communityStatsService.getLeaderboard({
communityId,
filters: this.toFilters({ seasonId, from, to, championId }),
});
}
@Get('internal-stats/team-insights')
@AllowPublicAccess()
public getTeamInsights(
@Param('communityId', ParseObjectIdPipe)
communityId: mongoose.Types.ObjectId,
@Query('seasonId') seasonId?: string,
@Query('from') from?: string,
@Query('to') to?: string,
@Query('championId') championId?: string,
) {
return this.communityStatsService.getTeamInsights({
communityId,
filters: this.toFilters({ seasonId, from, to, championId }),
});
}
@Get('internal-stats/match/:matchId')
@AllowPublicAccess()
public getMatchDetail(
@Param('communityId', ParseObjectIdPipe)
communityId: mongoose.Types.ObjectId,
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
) {
return this.communityStatsService.getMatchDetail({ communityId, matchId });
}
@Get('users/:userId/internal-history')
@AllowPublicAccess()
public getUserInternalHistory(
@Param('communityId', ParseObjectIdPipe)
communityId: mongoose.Types.ObjectId,
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
@Query('seasonId') seasonId?: string,
@Query('from') from?: string,
@Query('to') to?: string,
@Query('championId') championId?: string,
@Query('cursor') cursor?: string,
@Query('limit') limit?: string,
) {
return this.communityStatsService.getUserInternalHistory({
communityId,
userId,
filters: this.toFilters({ seasonId, from, to, championId, cursor, limit }),
});
}
private toFilters(params: {
seasonId?: string;
from?: string;
to?: string;
championId?: string;
cursor?: string;
limit?: string;
}): CommunityStatsFilters {
return {
seasonId: params.seasonId,
from: params.from,
to: params.to,
championId: this.toNumber(params.championId),
cursor: this.toNumber(params.cursor),
limit: this.toNumber(params.limit),
};
}
private toNumber(value: string | undefined): number | undefined {
if (!value) return undefined;
const parsed = Number(value);
return Number.isFinite(parsed) ? parsed : undefined;
}
}