feat(api): add match history endpoints
This commit is contained in:
1 parent
3447162aa5
commit
fc81beec45
4 files changed
+1079
No files matched your search
@@ -0,0 +1,123 @@
|
||||
import { Body, Controller, Get, Param, Post, 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 { RiotJobQueueService } from '../riot-job-queue/riot-job-queue.service';
|
||||
import type {
|
||||
RiotJobPriority,
|
||||
} from '../riot-job-queue/riot-job-queue.types';
|
||||
import { MatchHistoryService } from './match-history.service';
|
||||
|
||||
interface RefreshBody {
|
||||
queueGroups?: string[];
|
||||
priority?: RiotJobPriority;
|
||||
}
|
||||
|
||||
@Controller('communities/:communityId/users/:userId')
|
||||
export class MatchHistoryController {
|
||||
constructor(
|
||||
private readonly matchHistoryService: MatchHistoryService,
|
||||
private readonly riotJobQueueService: RiotJobQueueService,
|
||||
) {}
|
||||
|
||||
@Get('history-profile')
|
||||
@AllowPublicAccess()
|
||||
public getProfile(
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||
) {
|
||||
return this.matchHistoryService.getProfile({ communityId, userId });
|
||||
}
|
||||
|
||||
@Get('champion-stats')
|
||||
@AllowPublicAccess()
|
||||
public getChampionStats(
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||
@Query('queueGroup') queueGroup?: string,
|
||||
@Query('rank') rank?: string,
|
||||
@Query('seasonId') seasonId?: string,
|
||||
) {
|
||||
return this.matchHistoryService.getChampionStats({
|
||||
communityId,
|
||||
userId,
|
||||
filters: { queueGroup, rank, seasonId },
|
||||
});
|
||||
}
|
||||
|
||||
@Get('recent-summary')
|
||||
@AllowPublicAccess()
|
||||
public getRecentSummary(
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||
@Query('queueGroup') queueGroup?: string,
|
||||
@Query('rank') rank?: string,
|
||||
@Query('seasonId') seasonId?: string,
|
||||
@Query('championId') championId?: string,
|
||||
@Query('limit') limit?: string,
|
||||
) {
|
||||
return this.matchHistoryService.getRecentSummary({
|
||||
communityId,
|
||||
userId,
|
||||
filters: {
|
||||
queueGroup,
|
||||
rank,
|
||||
seasonId,
|
||||
championId: this.toNumber(championId),
|
||||
limit: this.toNumber(limit),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@Get('recent-matches')
|
||||
@AllowPublicAccess()
|
||||
public getRecentMatches(
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||
@Query('queueGroup') queueGroup?: string,
|
||||
@Query('rank') rank?: string,
|
||||
@Query('seasonId') seasonId?: string,
|
||||
@Query('championId') championId?: string,
|
||||
@Query('limit') limit?: string,
|
||||
@Query('cursor') cursor?: string,
|
||||
) {
|
||||
return this.matchHistoryService.getRecentMatches({
|
||||
communityId,
|
||||
userId,
|
||||
filters: {
|
||||
queueGroup,
|
||||
rank,
|
||||
seasonId,
|
||||
championId: this.toNumber(championId),
|
||||
limit: this.toNumber(limit),
|
||||
cursor: this.toNumber(cursor),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@Post('refresh')
|
||||
@AllowPublicAccess()
|
||||
public refresh(
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||
@Body() body: RefreshBody,
|
||||
) {
|
||||
return this.riotJobQueueService.enqueueRefresh({
|
||||
communityId,
|
||||
userId,
|
||||
queueGroups: body.queueGroups ?? ['summoners-rift'],
|
||||
priority: body.priority ?? 'high',
|
||||
});
|
||||
}
|
||||
|
||||
private toNumber(value: string | undefined): number | undefined {
|
||||
if (!value) return undefined;
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user