128 lines
3.9 KiB
TypeScript
128 lines
3.9 KiB
TypeScript
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,
|
|
@Query('lane') lane?: string,
|
|
) {
|
|
return this.matchHistoryService.getRecentSummary({
|
|
communityId,
|
|
userId,
|
|
filters: {
|
|
queueGroup,
|
|
rank,
|
|
seasonId,
|
|
championId: this.toNumber(championId),
|
|
limit: this.toNumber(limit),
|
|
lane,
|
|
},
|
|
});
|
|
}
|
|
|
|
@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,
|
|
@Query('lane') lane?: string,
|
|
@Query('includePositionCounts') includePositionCounts?: string,
|
|
) {
|
|
return this.matchHistoryService.getRecentMatches({
|
|
communityId,
|
|
userId,
|
|
filters: {
|
|
queueGroup,
|
|
rank,
|
|
seasonId,
|
|
championId: this.toNumber(championId),
|
|
limit: this.toNumber(limit),
|
|
cursor: this.toNumber(cursor),
|
|
lane,
|
|
includePositionCounts: includePositionCounts === 'true',
|
|
},
|
|
});
|
|
}
|
|
|
|
@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;
|
|
}
|
|
}
|