style(api): apply prettier formatting

This commit is contained in:
dahyeon committed 2026-07-24 21:42:28 -07:00
1 parent 80fef25af3
commit 96fede9fe5
75 files changed
+955 -674

No files matched your search

@@ -3,9 +3,7 @@ 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 type { RiotJobPriority } from '../riot-job-queue/riot-job-queue.types';
import { MatchHistoryService } from './match-history.service';
interface RefreshBody {
@@ -1,4 +1,8 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import {
BadRequestException,
Injectable,
NotFoundException,
} from '@nestjs/common';
import mongoose from 'mongoose';
import { ConnectionService } from '../global/database/connection.service';
import type {
@@ -16,10 +20,7 @@ import {
type RiotQueueGroup,
type RiotRankFilter,
} from '../riot/riot-queue.constants';
import type {
RiotMatchDto,
RiotMatchParticipantDto,
} from '../riot/riot.types';
import type { RiotMatchDto, RiotMatchParticipantDto } from '../riot/riot.types';
import type {
ChampionStatsResponse,
ChampionStatsRow,
@@ -104,7 +105,10 @@ export class MatchHistoryService {
fetchedAt: tier.fetchedAt.toISOString(),
})),
tierHistory: [...context.account.tierHistory]
.sort((left, right) => left.recordedAt.getTime() - right.recordedAt.getTime())
.sort(
(left, right) =>
left.recordedAt.getTime() - right.recordedAt.getTime(),
)
.map((entry) => ({
queueType: entry.queueType,
tier: entry.tier,
@@ -170,7 +174,11 @@ export class MatchHistoryService {
seasonId: params.filters.seasonId,
});
const { queueIds } = this.resolveQueueFilters(params.filters);
const limit = this.clampLimit(params.filters.limit, DEFAULT_SUMMARY_LIMIT, 50);
const limit = this.clampLimit(
params.filters.limit,
DEFAULT_SUMMARY_LIMIT,
50,
);
const docs = await this.findStoredMatches({
context,
queueIds,
@@ -196,7 +204,11 @@ export class MatchHistoryService {
seasonId: params.filters.seasonId,
});
const { queueIds } = this.resolveQueueFilters(params.filters);
const limit = this.clampLimit(params.filters.limit, DEFAULT_RECENT_LIMIT, 30);
const limit = this.clampLimit(
params.filters.limit,
DEFAULT_RECENT_LIMIT,
30,
);
const docs = await this.findStoredMatches({
context,
queueIds,
@@ -212,7 +224,10 @@ export class MatchHistoryService {
return {
matches: page,
nextCursor: views.length > limit ? page[page.length - 1]?.gameCreation ?? null : null,
nextCursor:
views.length > limit
? (page[page.length - 1]?.gameCreation ?? null)
: null,
lastFetchedAt: this.resolveLastFetchedAt(docs, context),
season: context.season,
};
@@ -455,8 +470,9 @@ export class MatchHistoryService {
puuid: string,
): RiotMatchParticipantDto | null {
return (
match.info.participants.find((participant) => participant.puuid === puuid) ??
null
match.info.participants.find(
(participant) => participant.puuid === puuid,
) ?? null
);
}
@@ -570,7 +586,8 @@ export class MatchHistoryService {
return {
matchId: dto.metadata.matchId,
queueId: dto.info.queueId,
queueLabel: RIOT_QUEUE_LABELS[dto.info.queueId] ?? `큐 ${dto.info.queueId}`,
queueLabel:
RIOT_QUEUE_LABELS[dto.info.queueId] ?? `큐 ${dto.info.queueId}`,
gameCreation: dto.info.gameCreation,
gameDuration: dto.info.gameDuration,
win: participant.win,
@@ -684,11 +701,15 @@ export class MatchHistoryService {
return {
puuid: participant.puuid,
gameName: participant.riotIdGameName || participant.summonerName || 'Unknown',
gameName:
participant.riotIdGameName ||
participant.summonerName ||
'Unknown',
tagLine: participant.riotIdTagLine || '',
championId: participant.championId,
championLevel: participant.champLevel,
teamPosition: participant.teamPosition || participant.individualPosition,
teamPosition:
participant.teamPosition || participant.individualPosition,
kills: participant.kills,
deaths: participant.deaths,
assists: participant.assists,
@@ -720,7 +741,9 @@ export class MatchHistoryService {
}));
}
private resolvePerks(participant: RiotMatchParticipantDto): RecentMatchView['perks'] {
private resolvePerks(
participant: RiotMatchParticipantDto,
): RecentMatchView['perks'] {
const primary = participant.perks.styles.find(
(style) => style.description === 'primaryStyle',
);
@@ -750,11 +773,19 @@ export class MatchHistoryService {
) as Partial<Record<RiotLane, number>>;
}
private resolveTopChampions(views: RecentMatchView[]): RecentSummaryResponse['topChampions'] {
const byChampion = new Map<number, { games: number; wins: number; rating: number }>();
private resolveTopChampions(
views: RecentMatchView[],
): RecentSummaryResponse['topChampions'] {
const byChampion = new Map<
number,
{ games: number; wins: number; rating: number }
>();
for (const view of views) {
const stat =
byChampion.get(view.championId) ?? { games: 0, wins: 0, rating: 0 };
const stat = byChampion.get(view.championId) ?? {
games: 0,
wins: 0,
rating: 0,
};
stat.games += 1;
stat.wins += view.win ? 1 : 0;
stat.rating += view.rating;
@@ -797,7 +828,8 @@ export class MatchHistoryService {
participant.deaths,
participant.assists,
);
const kp = teamKills > 0 ? (participant.kills + participant.assists) / teamKills : 0;
const kp =
teamKills > 0 ? (participant.kills + participant.assists) / teamKills : 0;
const csPerMin = this.resolveTotalCs(participant) / Math.max(minutes, 1);
const visionPerMin = participant.visionScore / Math.max(minutes, 1);
const score =
@@ -815,8 +847,13 @@ export class MatchHistoryService {
): number {
const teamDamage = match.info.participants
.filter((candidate) => candidate.teamId === participant.teamId)
.reduce((sum, candidate) => sum + candidate.totalDamageDealtToChampions, 0);
return teamDamage > 0 ? participant.totalDamageDealtToChampions / teamDamage : 0;
.reduce(
(sum, candidate) => sum + candidate.totalDamageDealtToChampions,
0,
);
return teamDamage > 0
? participant.totalDamageDealtToChampions / teamDamage
: 0;
}
private resolveTotalCs(participant: RiotMatchParticipantDto): number {
@@ -827,11 +864,16 @@ export class MatchHistoryService {
match: RiotMatchDto,
participant: RiotMatchParticipantDto,
): number {
return Math.max((participant.timePlayed || match.info.gameDuration) / 60, 1);
return Math.max(
(participant.timePlayed || match.info.gameDuration) / 60,
1,
);
}
private resolveKda(kills: number, deaths: number, assists: number): number {
return deaths === 0 ? kills + assists : this.round((kills + assists) / deaths);
return deaths === 0
? kills + assists
: this.round((kills + assists) / deaths);
}
private resolveLastFetchedAt(
@@ -841,9 +883,11 @@ export class MatchHistoryService {
if (docs.length === 0) {
return context.account.recentStatsFetchedAt?.toISOString() ?? null;
}
const oldest = docs.reduce((acc, doc) =>
doc.fetchedAt.getTime() < acc.getTime() ? doc.fetchedAt : acc,
docs[0].fetchedAt);
const oldest = docs.reduce(
(acc, doc) =>
doc.fetchedAt.getTime() < acc.getTime() ? doc.fetchedAt : acc,
docs[0].fetchedAt,
);
return oldest.toISOString();
}
@@ -858,14 +902,17 @@ export class MatchHistoryService {
.map((row) => row.lastFetchedAt)
.filter((value): value is Date => value instanceof Date)
.reduce<Date | null>(
(acc, value) =>
!acc || value.getTime() < acc.getTime() ? value : acc,
(acc, value) => (!acc || value.getTime() < acc.getTime() ? value : acc),
null,
);
return oldest?.toISOString() ?? null;
}
private clampLimit(value: number | undefined, fallback: number, max: number): number {
private clampLimit(
value: number | undefined,
fallback: number,
max: number,
): number {
if (!value || !Number.isFinite(value)) return fallback;
return Math.max(1, Math.min(Math.floor(value), max));
}
@@ -882,18 +929,12 @@ export class MatchHistoryService {
return Math.round(value * 10) / 10;
}
private numberField(
value: RiotMatchParticipantDto,
key: string,
): number {
private numberField(value: RiotMatchParticipantDto, key: string): number {
const field = value[key];
return typeof field === 'number' && Number.isFinite(field) ? field : 0;
}
private booleanField(
value: RiotMatchParticipantDto,
key: string,
): boolean {
private booleanField(value: RiotMatchParticipantDto, key: string): boolean {
return value[key] === true;
}
}