This commit is contained in:
dahyeon committed 2026-05-02 04:05:35 -07:00
1 parent 4baea89f89
commit fd386ed202
32 files changed
+1128 -601

No files matched your search

@@ -26,7 +26,6 @@ import {
buildUserByPuuidMap,
countKnownParticipants,
resolveExternalCount,
resolveTeam100IsBlue,
type UserByPuuidMap,
} from './match-builder.util';
import {
@@ -306,9 +305,11 @@ export class LegacyImportService {
externalCount: raw
? resolveExternalCount(raw, userByPuuid)
: Math.max(0, 10 - memberCount),
blueScore: match.result?.blueScore ?? 0,
redScore: match.result?.redScore ?? 0,
winnerSide: match.result?.winnerSide,
teamAIndex: match.result?.seriesResults?.[0]?.teamAIndex ?? 1,
teamBIndex: match.result?.seriesResults?.[0]?.teamBIndex ?? 2,
teamAWins: match.result?.seriesResults?.[0]?.teamAWins ?? 0,
teamBWins: match.result?.seriesResults?.[0]?.teamBWins ?? 0,
winnerTeamIndex: match.result?.winnerTeamIndex,
};
}),
nextCursor:
@@ -391,9 +392,8 @@ export class LegacyImportService {
continue;
}
const team100IsBlue = resolveTeam100IsBlue(raw, userByPuuid);
const participants = buildParticipantsSnapshot(raw, userByPuuid);
const gameResult = buildGameResult(raw, userByPuuid, team100IsBlue, 1);
const gameResult = buildGameResult(raw, userByPuuid, 1);
if (!gameResult || participants.length === 0) {
result.skippedNoKnownParticipants += 1;
if (Object.keys(update).length > 0) {
@@ -402,23 +402,21 @@ export class LegacyImportService {
continue;
}
const winnerSide = gameResult.winnerSide;
const winnerTeamIndex = gameResult.winnerTeamIndex;
update.mapId = raw.info.mapId ?? match.mapId;
update.participants = participants;
update.teams = buildTeams(raw, userByPuuid, team100IsBlue);
update.teams = buildTeams(raw, userByPuuid);
update.result = {
winnerSide,
blueScore: winnerSide === 'blue' ? 1 : 0,
redScore: winnerSide === 'red' ? 1 : 0,
winnerTeamIndex,
riotMatchIds: [riotMatchId],
games: [gameResult],
seriesResults: [
{
blueGroupIndex: 1,
redGroupIndex: 1,
blueScore: winnerSide === 'blue' ? 1 : 0,
redScore: winnerSide === 'red' ? 1 : 0,
winnerSide,
teamAIndex: 1,
teamBIndex: 2,
teamAWins: winnerTeamIndex === 1 ? 1 : 0,
teamBWins: winnerTeamIndex === 2 ? 1 : 0,
winnerTeamIndex,
},
],
};
@@ -485,11 +483,10 @@ export class LegacyImportService {
const counts = countKnownParticipants(detail, userByPuuid);
if (counts.total === 0) return 'skipped';
const team100IsBlue = resolveTeam100IsBlue(detail, userByPuuid);
const gameResult = buildGameResult(detail, userByPuuid, team100IsBlue, 1);
const gameResult = buildGameResult(detail, userByPuuid, 1);
if (!gameResult || gameResult.participants.length === 0) return 'skipped';
const winnerSide = gameResult.winnerSide;
const winnerTeamIndex = gameResult.winnerTeamIndex;
const matchPayload: Partial<Match> = {
communityId: new mongoose.Types.ObjectId(job.communityId),
title: this.formatLegacyDate(detail.info.gameCreation),
@@ -504,20 +501,18 @@ export class LegacyImportService {
teamBuiltAt: new Date(detail.info.gameCreation),
hostUserId: new mongoose.Types.ObjectId(job.triggeredBy),
participants: buildParticipantsSnapshot(detail, userByPuuid),
teams: buildTeams(detail, userByPuuid, team100IsBlue),
teams: buildTeams(detail, userByPuuid),
result: {
winnerSide,
blueScore: winnerSide === 'blue' ? 1 : 0,
redScore: winnerSide === 'red' ? 1 : 0,
winnerTeamIndex,
riotMatchIds: [riotMatchId],
games: [gameResult],
seriesResults: [
{
blueGroupIndex: 1,
redGroupIndex: 1,
blueScore: winnerSide === 'blue' ? 1 : 0,
redScore: winnerSide === 'red' ? 1 : 0,
winnerSide,
teamAIndex: 1,
teamBIndex: 2,
teamAWins: winnerTeamIndex === 1 ? 1 : 0,
teamBWins: winnerTeamIndex === 2 ? 1 : 0,
winnerTeamIndex,
},
],
},
@@ -55,9 +55,11 @@ export interface LegacyMatchListResponse {
riotMatchId: string | null;
memberCount: number;
externalCount: number;
blueScore: number;
redScore: number;
winnerSide?: 'blue' | 'red';
teamAIndex: number;
teamBIndex: number;
teamAWins: number;
teamBWins: number;
winnerTeamIndex?: number;
}>;
nextCursor: number | null;
}
@@ -5,7 +5,6 @@ import type {
MatchTeam,
Position,
RiotAccount,
TeamSide,
UserDocument,
} from '../global/database/schema';
import type { RiotMatchDto, RiotMatchParticipantDto } from '../riot/riot.types';
@@ -91,10 +90,11 @@ export function buildParticipantsSnapshot(
export function buildTeams(
detail: RiotMatchDto,
userByPuuid: UserByPuuidMap,
team100IsBlue: boolean,
): MatchTeam[] {
return (['blue', 'red'] as TeamSide[]).map((side) => {
const teamId = resolveRiotTeamId(side, team100IsBlue);
return [
{ teamIndex: 1, teamId: RIOT_BLUE_TEAM_ID },
{ teamIndex: 2, teamId: RIOT_RED_TEAM_ID },
].map(({ teamIndex, teamId }) => {
const members = detail.info.participants
.filter((participant) => participant.teamId === teamId)
.map((participant) => {
@@ -107,9 +107,8 @@ export function buildTeams(
})
.filter((member): member is NonNullable<typeof member> => Boolean(member));
return {
side,
groupIndex: 1,
name: side === 'blue' ? '블루팀' : '레드팀',
teamIndex,
name: `${teamIndex}팀`,
members,
};
});
@@ -118,20 +117,21 @@ export function buildTeams(
export function buildGameResult(
detail: RiotMatchDto,
userByPuuid: UserByPuuidMap,
team100IsBlue: boolean,
gameNumber = 1,
): MatchGameResult | null {
const winningTeam = detail.info.teams.find((team) => team.win);
if (!winningTeam) return null;
const winnerSide = resolveSide(winningTeam.teamId, team100IsBlue);
const winnerSide = resolveSide(winningTeam.teamId);
if (!winnerSide) return null;
const winnerTeamIndex = winnerSide === 'blue' ? 1 : 2;
const participants = detail.info.participants
.map((participant) => {
const user = userByPuuid.get(participant.puuid);
const side = resolveSide(participant.teamId, team100IsBlue);
const side = resolveSide(participant.teamId);
if (!user || !side) return null;
return {
userId: user.userId,
teamIndex: side === 'blue' ? 1 : 2,
side,
championId: participant.championId,
kills: participant.kills,
@@ -147,9 +147,10 @@ export function buildGameResult(
return {
gameNumber,
riotMatchId: detail.metadata.matchId,
blueTeamIndex: 1,
redTeamIndex: 2,
winnerTeamIndex,
winnerSide,
blueGroupIndex: 1,
redGroupIndex: 1,
gameCreation: detail.info.gameCreation,
gameDuration: detail.info.gameDuration,
participants,
@@ -165,16 +166,9 @@ export function resolveExternalCount(
).length;
}
function resolveRiotTeamId(side: TeamSide, team100IsBlue: boolean): number {
if (side === 'blue') {
return team100IsBlue ? RIOT_BLUE_TEAM_ID : RIOT_RED_TEAM_ID;
}
return team100IsBlue ? RIOT_RED_TEAM_ID : RIOT_BLUE_TEAM_ID;
}
function resolveSide(teamId: number, team100IsBlue: boolean): TeamSide | null {
if (teamId === RIOT_BLUE_TEAM_ID) return team100IsBlue ? 'blue' : 'red';
if (teamId === RIOT_RED_TEAM_ID) return team100IsBlue ? 'red' : 'blue';
function resolveSide(teamId: number): 'blue' | 'red' | null {
if (teamId === RIOT_BLUE_TEAM_ID) return 'blue';
if (teamId === RIOT_RED_TEAM_ID) return 'red';
return null;
}