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

@@ -101,7 +101,7 @@ function makeService(overrides?: {
Promise.resolve({
riotPlatform: 'kr',
riotRegion: 'asia',
}),
}),
}),
}),
});
@@ -198,65 +198,64 @@ describe('RiotAccountEnrichmentService', () => {
masteryService,
recentMatchesService,
recentStatsService,
} =
makeService({
user,
summoner: {
getByPuuid: jest.fn().mockResolvedValue({
} = makeService({
user,
summoner: {
getByPuuid: jest.fn().mockResolvedValue({
puuid: 'puuid-1',
profileIconId: 588,
revisionDate: 1776977597000,
summonerLevel: 529,
}),
} as Partial<RiotSummonerService>,
league: {
getEntriesByPuuid: jest.fn().mockResolvedValue([
{
leagueId: 'L1',
queueType: 'RANKED_SOLO_5x5',
tier: 'EMERALD',
rank: 'I',
puuid: 'puuid-1',
profileIconId: 588,
revisionDate: 1776977597000,
summonerLevel: 529,
}),
} as Partial<RiotSummonerService>,
league: {
getEntriesByPuuid: jest.fn().mockResolvedValue([
{
leagueId: 'L1',
queueType: 'RANKED_SOLO_5x5',
tier: 'EMERALD',
rank: 'I',
puuid: 'puuid-1',
leaguePoints: 75,
wins: 160,
losses: 148,
},
]),
} as Partial<RiotLeagueService>,
mastery: {
getTopByPuuid: jest.fn().mockResolvedValue([
{
puuid: 'puuid-1',
championId: 7,
championLevel: 70,
championPoints: 742560,
},
]),
} as Partial<RiotChampionMasteryService>,
recentMatches: {
syncRecentMatches: jest.fn().mockResolvedValue([]),
loadFromDb: jest.fn().mockResolvedValue([
{ matchId: 'KR_1', raw: {} },
{ matchId: 'KR_2', raw: {} },
]),
} as Partial<RiotRecentMatchesService>,
recentStats: {
computeSummary: jest.fn().mockReturnValue({
overall: {
games: 2,
wins: 1,
losses: 1,
avgKills: 5.5,
avgDeaths: 2.5,
avgAssists: 7,
avgCs: 175,
avgCsPerMin: 6.4,
mostPlayedChampionIds: [7, 103],
},
byLane: {},
}),
} as Partial<RiotRecentStatsService>,
});
leaguePoints: 75,
wins: 160,
losses: 148,
},
]),
} as Partial<RiotLeagueService>,
mastery: {
getTopByPuuid: jest.fn().mockResolvedValue([
{
puuid: 'puuid-1',
championId: 7,
championLevel: 70,
championPoints: 742560,
},
]),
} as Partial<RiotChampionMasteryService>,
recentMatches: {
syncRecentMatches: jest.fn().mockResolvedValue([]),
loadFromDb: jest.fn().mockResolvedValue([
{ matchId: 'KR_1', raw: {} },
{ matchId: 'KR_2', raw: {} },
]),
} as Partial<RiotRecentMatchesService>,
recentStats: {
computeSummary: jest.fn().mockReturnValue({
overall: {
games: 2,
wins: 1,
losses: 1,
avgKills: 5.5,
avgDeaths: 2.5,
avgAssists: 7,
avgCs: 175,
avgCsPerMin: 6.4,
mostPlayedChampionIds: [7, 103],
},
byLane: {},
}),
} as Partial<RiotRecentStatsService>,
});
const result = await service.enrichRiotAccount({
userId: user._id,
@@ -148,14 +148,18 @@ describe('RiotDdragonService', () => {
'ddragon:manifest:v5:ko_KR',
expect.objectContaining({
summonerSpells: expect.objectContaining({
'4': expect.objectContaining({ description: '커서 방향으로 순간이동합니다.' }),
'4': expect.objectContaining({
description: '커서 방향으로 순간이동합니다.',
}),
}),
runesReforged: expect.arrayContaining([
expect.objectContaining({
slots: expect.arrayContaining([
expect.objectContaining({
runes: expect.arrayContaining([
expect.objectContaining({ longDesc: expect.stringContaining('기본 공격') }),
expect.objectContaining({
longDesc: expect.stringContaining('기본 공격'),
}),
]),
}),
]),
@@ -114,7 +114,9 @@ export class RiotDdragonService {
constructor(private readonly redisService: RedisService) {}
public async getManifest(locale: string = DEFAULT_LOCALE): Promise<DdragonManifest> {
public async getManifest(
locale: string = DEFAULT_LOCALE,
): Promise<DdragonManifest> {
const normalizedLocale = normalizeLocale(locale);
const cacheKey = manifestCacheKey(normalizedLocale);
@@ -139,12 +141,14 @@ export class RiotDdragonService {
private async buildManifest(locale: string): Promise<DdragonManifest> {
const version = await this.fetchLatestVersion();
const [champions, summonerSpells, runesReforged, items] = await Promise.all([
this.fetchChampionMap(version, locale),
this.fetchSummonerSpellMap(version, locale),
this.fetchRuneStyles(version, locale),
this.fetchItemMap(version, locale),
]);
const [champions, summonerSpells, runesReforged, items] = await Promise.all(
[
this.fetchChampionMap(version, locale),
this.fetchSummonerSpellMap(version, locale),
this.fetchRuneStyles(version, locale),
this.fetchItemMap(version, locale),
],
);
return {
version,
cdn: DDRAGON_CDN,
@@ -158,7 +162,9 @@ export class RiotDdragonService {
}
private async fetchLatestVersion(): Promise<string> {
const versions = await this.fetchJson<unknown>(`${DDRAGON_BASE}/api/versions.json`);
const versions = await this.fetchJson<unknown>(
`${DDRAGON_BASE}/api/versions.json`,
);
if (!Array.isArray(versions) || typeof versions[0] !== 'string') {
throw new Error('ddragon versions.json response is malformed.');
}
@@ -219,7 +225,9 @@ export class RiotDdragonService {
const url = `${DDRAGON_CDN}/${version}/data/${locale}/runesReforged.json`;
const payload = await this.fetchJson<unknown>(url);
if (!Array.isArray(payload)) {
throw new Error(`ddragon runesReforged.json response is malformed (${url}).`);
throw new Error(
`ddragon runesReforged.json response is malformed (${url}).`,
);
}
return payload
@@ -229,8 +237,7 @@ export class RiotDdragonService {
key: style.key,
icon: style.icon,
name: style.name,
shortDesc:
typeof style.shortDesc === 'string' ? style.shortDesc : '',
shortDesc: typeof style.shortDesc === 'string' ? style.shortDesc : '',
longDesc: typeof style.longDesc === 'string' ? style.longDesc : '',
slots: (style.slots ?? []).map((slot) => ({
runes: (slot.runes ?? [])
@@ -290,9 +297,7 @@ export class RiotDdragonService {
signal: controller.signal,
});
if (!response.ok) {
throw new Error(
`ddragon request failed (${response.status}): ${url}`,
);
throw new Error(`ddragon request failed (${response.status}): ${url}`);
}
return (await response.json()) as T;
} catch (err) {
@@ -1,9 +1,6 @@
import { Injectable } from '@nestjs/common';
import { RiotClientService } from './riot.client.service';
import {
RiotLeagueEntryDto,
RiotPlatformLookupOptions,
} from './riot.types';
import { RiotLeagueEntryDto, RiotPlatformLookupOptions } from './riot.types';
@Injectable()
export class RiotLeagueService {
@@ -98,9 +98,7 @@ function validateMatchIdsLookupOptions(
assertOptionalNonNegativeInteger(options.endTime, 'endTime');
if (options.type !== undefined && !RIOT_MATCH_TYPES.includes(options.type)) {
throw new RangeError(
`type must be one of: ${RIOT_MATCH_TYPES.join(', ')}`,
);
throw new RangeError(`type must be one of: ${RIOT_MATCH_TYPES.join(', ')}`);
}
if (
@@ -278,7 +276,9 @@ function parseTimelineParticipant(
index: number,
): RiotMatchTimelineParticipantDto {
if (!isRecord(value)) {
throw new TypeError(`timeline.info.participants[${index}] must be an object.`);
throw new TypeError(
`timeline.info.participants[${index}] must be an object.`,
);
}
return {
@@ -287,7 +287,10 @@ function parseTimelineParticipant(
value.participantId,
`timeline.info.participants[${index}].participantId`,
),
puuid: requireString(value.puuid, `timeline.info.participants[${index}].puuid`),
puuid: requireString(
value.puuid,
`timeline.info.participants[${index}].puuid`,
),
};
}
@@ -589,7 +592,10 @@ function parseParticipant(
};
}
function parsePerks(value: unknown, participantIndex: number): RiotMatchPerksDto {
function parsePerks(
value: unknown,
participantIndex: number,
): RiotMatchPerksDto {
if (!isRecord(value)) {
throw new TypeError(
`participants[${participantIndex}].perks must be an object.`,
@@ -732,7 +738,9 @@ function parseBan(
banIndex: number,
): RiotMatchBanDto {
if (!isRecord(value)) {
throw new TypeError(`teams[${teamIndex}].bans[${banIndex}] must be an object.`);
throw new TypeError(
`teams[${teamIndex}].bans[${banIndex}] must be an object.`,
);
}
return {
@@ -781,7 +789,9 @@ function parseObjective(
key: keyof RiotMatchObjectivesDto,
): RiotMatchObjectiveDto {
if (!isRecord(value)) {
throw new TypeError(`teams[${teamIndex}].objectives.${key} must be an object.`);
throw new TypeError(
`teams[${teamIndex}].objectives.${key} must be an object.`,
);
}
return {
@@ -84,5 +84,10 @@ export function isRiotQueueGroup(value: string): value is RiotQueueGroup {
}
export function isRiotRankFilter(value: string): value is RiotRankFilter {
return value === 'all' || value === 'solo' || value === 'flex' || value === 'normal';
return (
value === 'all' ||
value === 'solo' ||
value === 'flex' ||
value === 'normal'
);
}
@@ -150,13 +150,16 @@ async function runWithConcurrency<T>(
if (items.length === 0) return;
const queue = [...items];
const runners = Array.from({ length: Math.min(concurrency, queue.length) }, async () => {
while (queue.length > 0) {
const item = queue.shift();
if (item === undefined) return;
await worker(item);
}
});
const runners = Array.from(
{ length: Math.min(concurrency, queue.length) },
async () => {
while (queue.length > 0) {
const item = queue.shift();
if (item === undefined) return;
await worker(item);
}
},
);
await Promise.all(runners);
}
@@ -44,17 +44,29 @@ export class RiotRecentStatsService {
);
for (const match of filteredMatches) {
const participant = match.info.participants.find((entry) => entry.puuid === puuid);
const participant = match.info.participants.find(
(entry) => entry.puuid === puuid,
);
if (!participant) continue;
accumulateAggregate(overall, participant, match.info.gameCreation, match.info.gameDuration);
accumulateAggregate(
overall,
participant,
match.info.gameCreation,
match.info.gameDuration,
);
const lane = resolveLane(participant);
if (!lane) continue;
const aggregate = laneAggregates.get(lane);
if (!aggregate) continue;
accumulateAggregate(aggregate, participant, match.info.gameCreation, match.info.gameDuration);
accumulateAggregate(
aggregate,
participant,
match.info.gameCreation,
match.info.gameDuration,
);
}
if (overall.games === 0) {
@@ -133,7 +145,8 @@ function finalizeAggregate(aggregate: Aggregate): RiotLaneStats {
const mostPlayedChampionIds = [...aggregate.championCounts.entries()]
.sort((left, right) => {
if (right[1] !== left[1]) return right[1] - left[1];
const rightLastPlayed = aggregate.lastPlayedAtByChampion.get(right[0]) ?? 0;
const rightLastPlayed =
aggregate.lastPlayedAtByChampion.get(right[0]) ?? 0;
const leftLastPlayed = aggregate.lastPlayedAtByChampion.get(left[0]) ?? 0;
if (rightLastPlayed !== leftLastPlayed) {
return rightLastPlayed - leftLastPlayed;
@@ -1,9 +1,6 @@
import { Injectable } from '@nestjs/common';
import { RiotClientService } from './riot.client.service';
import {
RiotPlatformLookupOptions,
RiotSummonerDto,
} from './riot.types';
import { RiotPlatformLookupOptions, RiotSummonerDto } from './riot.types';
@Injectable()
export class RiotSummonerService {
@@ -17,8 +17,12 @@ describe('RiotWebhookController', () => {
});
it('logs the incoming webhook payload and returns an acknowledgement', () => {
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined);
const dirSpy = jest.spyOn(console, 'dir').mockImplementation(() => undefined);
const logSpy = jest
.spyOn(console, 'log')
.mockImplementation(() => undefined);
const dirSpy = jest
.spyOn(console, 'dir')
.mockImplementation(() => undefined);
const request = {
method: 'POST',
originalUrl: '/riot/webhooks/tournament',
@@ -1,10 +1,4 @@
import {
All,
Controller,
HttpCode,
HttpStatus,
Req,
} from '@nestjs/common';
import { All, Controller, HttpCode, HttpStatus, Req } from '@nestjs/common';
import type { Request } from 'express';
import { AllowPublicAccess } from '../auth/allow-public-access.decorator';
+8 -3
View File
@@ -263,7 +263,10 @@ export interface RiotMatchTimelineInfoDto extends Record<string, unknown> {
participants?: RiotMatchTimelineParticipantDto[];
}
export interface RiotMatchTimelineParticipantDto extends Record<string, unknown> {
export interface RiotMatchTimelineParticipantDto extends Record<
string,
unknown
> {
participantId: number;
puuid: string;
}
@@ -294,8 +297,10 @@ export interface RiotMatchTimelineEventDto extends Record<string, unknown> {
victimId?: number;
}
export interface RiotMatchTimelineParticipantFrameDto
extends Record<string, unknown> {
export interface RiotMatchTimelineParticipantFrameDto extends Record<
string,
unknown
> {
participantId: number;
totalGold: number;
xp: number;