diff --git a/apps/api/src/modules/auction/auction.service.spec.ts b/apps/api/src/modules/auction/auction.service.spec.ts index e5c41945..82992acc 100644 --- a/apps/api/src/modules/auction/auction.service.spec.ts +++ b/apps/api/src/modules/auction/auction.service.spec.ts @@ -322,6 +322,119 @@ describe('AuctionService', () => { expect(randomSpy).toHaveBeenCalled(); }); + it('includes tier history in auction player snapshots when starting an auction', async () => { + const matchId = new mongoose.Types.ObjectId(); + const communityId = new mongoose.Types.ObjectId(); + const userIds = Array.from( + { length: 10 }, + () => new mongoose.Types.ObjectId(), + ); + const participants = userIds.map((userId, index) => ({ + userId, + preferredPositions: [{ position: 'MID', priority: 1 }], + joinedAt: new Date(index), + excluded: false, + })); + const match = { + _id: matchId, + communityId, + participants, + status: 'recruiting', + teamBuiltAt: undefined, + save: jest.fn().mockResolvedValue(undefined), + }; + const tierHistory = [ + { + queueType: 'RANKED_SOLO_5x5', + tier: 'GOLD', + rank: 'II', + leaguePoints: 42, + wins: 30, + losses: 24, + recordedAt: new Date('2026-05-01T00:00:00.000Z'), + }, + { + queueType: 'RANKED_SOLO_5x5', + tier: 'PLATINUM', + rank: 'IV', + leaguePoints: 15, + wins: 34, + losses: 27, + recordedAt: new Date('2026-05-08T00:00:00.000Z'), + }, + ]; + const users = userIds.slice(2).map((userId, index) => ({ + _id: userId, + riotAccounts: [ + { + puuid: `puuid-${index}`, + gameName: `Player${index}`, + tagLine: 'KR1', + profileIconId: index, + tiers: [], + tierHistory: index === 0 ? tierHistory : [], + championMasteries: [], + recentStatsSummary: undefined, + lastRefreshRequestedAt: new Date(), + isPrimary: true, + }, + ], + })); + const auctionCreate = jest.fn().mockImplementation(async (payload) => ({ + _id: new mongoose.Types.ObjectId(), + matchId, + toObject: jest.fn().mockReturnValue({ matchId, ...payload }), + })); + const { service } = createService({ + match: { + findById: jest.fn().mockResolvedValue(match), + }, + user: { + find: jest.fn().mockResolvedValue(users), + }, + auction: { + findOne: jest.fn().mockResolvedValue(null), + create: auctionCreate, + }, + community: { + findById: jest.fn().mockReturnValue({ + select: jest.fn().mockReturnValue({ + lean: jest.fn().mockReturnValue({ + exec: jest.fn().mockResolvedValue({ + riotPlatform: 'kr', + riotRegion: 'asia', + }), + }), + }), + }), + }, + }); + + await service.start({ + matchId, + communityId, + captains: [ + { teamIndex: 1, userId: userIds[0] }, + { teamIndex: 2, userId: userIds[1] }, + ], + initialPoints: 1000, + maxTimerSeconds: 30, + bidExtensionSeconds: 5, + topTierThreshold: 'NONE', + manualTopTierUserIds: [], + }); + + const firstPlayerSnapshot = auctionCreate.mock.calls[0][0].order.find( + (player: { userId: mongoose.Types.ObjectId }) => + player.userId.equals(userIds[2]), + ); + + expect(firstPlayerSnapshot).toMatchObject({ + userId: userIds[2], + tierHistory, + }); + }); + it('rejects bids when the team already has 5 members including captain', async () => { const matchId = new mongoose.Types.ObjectId(); const auction = { diff --git a/apps/api/src/modules/auction/auction.service.ts b/apps/api/src/modules/auction/auction.service.ts index 434e6e21..557bc8eb 100644 --- a/apps/api/src/modules/auction/auction.service.ts +++ b/apps/api/src/modules/auction/auction.service.ts @@ -174,6 +174,7 @@ export class AuctionService { profileIconId: primary.profileIconId, preferredPositions: participant.preferredPositions, tiers: primary.tiers, + tierHistory: primary.tierHistory ?? [], masteries: primary.championMasteries, recentStatsSummary: primary.recentStatsSummary, passCount: 0, @@ -919,6 +920,7 @@ export class AuctionService { 'order.$.tagLine': account.tagLine, 'order.$.profileIconId': account.profileIconId, 'order.$.tiers': account.tiers, + 'order.$.tierHistory': account.tierHistory ?? [], 'order.$.masteries': account.championMasteries, 'order.$.recentStatsSummary': account.recentStatsSummary, updatedAt: new Date(), diff --git a/apps/api/src/modules/global/database/schema.ts b/apps/api/src/modules/global/database/schema.ts index ece1dbff..e7a0807b 100644 --- a/apps/api/src/modules/global/database/schema.ts +++ b/apps/api/src/modules/global/database/schema.ts @@ -593,6 +593,7 @@ export interface AuctionPlayerSnapshot { profileIconId: number; preferredPositions: PositionPreference[]; tiers: TierInfo[]; + tierHistory: TierHistoryEntry[]; masteries: ChampionMasteryEntry[]; recentStatsSummary?: RiotRecentStatsSummary; passCount: number; @@ -1531,6 +1532,11 @@ const AuctionPlayerSnapshotSubSchema = new Schema( default: [], }, tiers: { type: [TierInfoSubSchema], required: true, default: [] }, + tierHistory: { + type: [TierHistoryEntrySubSchema], + required: true, + default: [], + }, masteries: { type: [ChampionMasteryEntrySubSchema], required: true, diff --git a/apps/web/src/api/hooks.ts b/apps/web/src/api/hooks.ts index 34e604bf..b619b68c 100644 --- a/apps/web/src/api/hooks.ts +++ b/apps/web/src/api/hooks.ts @@ -225,6 +225,7 @@ function createUserHistoryPath( export function useUserHistoryProfile( userId: string | undefined, communityId = DEFAULT_COMMUNITY_ID, + enabled = true, ) { return useQuery({ queryKey: ['user-history-profile', communityId, userId ?? null], @@ -233,7 +234,7 @@ export function useUserHistoryProfile( `/communities/${communityId}/users/${userId}/history-profile`, { auth: 'none' }, ), - enabled: Boolean(communityId && userId), + enabled: enabled && Boolean(communityId && userId), retry: false, }); } diff --git a/apps/web/src/api/mappers.ts b/apps/web/src/api/mappers.ts index 3cb9c491..98710038 100644 --- a/apps/web/src/api/mappers.ts +++ b/apps/web/src/api/mappers.ts @@ -7,6 +7,7 @@ import type { ApiPositionPreference, ApiRiotLaneStats, ApiRiotRecentStatsSummary, + ApiTierHistoryEntry, ApiTierInfo, MatchStatus, Position, @@ -91,6 +92,7 @@ export interface AuctionPlayerView extends ParticipantView { level: number; points: number; }[]; + tierHistory: ApiTierHistoryEntry[]; recentStats: { overall: ApiRiotLaneStats; byLane: Partial>; @@ -236,6 +238,7 @@ function mapAuctionPlayerToView( summonerName: player.gameName, tag: player.tagLine, tier: selectPrimaryTier(player.tiers), + tierHistory: player.tierHistory ?? [], mainPosition, subPosition, profileIconId: player.profileIconId, @@ -288,12 +291,14 @@ function mapAuctionTeamToView( ...participant, passCount: 0, masteries: [], + tierHistory: [], recentStats: createEmptyRecentStatsView(), } : { ...createFallbackParticipant(member.userId), passCount: 0, masteries: [], + tierHistory: [], recentStats: createEmptyRecentStatsView(), }); diff --git a/apps/web/src/api/types.ts b/apps/web/src/api/types.ts index 827f913e..5adde77a 100644 --- a/apps/web/src/api/types.ts +++ b/apps/web/src/api/types.ts @@ -78,7 +78,7 @@ export interface ApiRiotAccount { summonerLevel: number; isPrimary: boolean; tiers: ApiTierInfo[]; - tierHistory: unknown[]; + tierHistory: ApiTierHistoryEntry[]; matchIds: string[]; championMasteries: ApiChampionMasteryEntry[]; championRecords: Record>; @@ -247,6 +247,7 @@ export interface ApiAuctionPlayerSnapshot { profileIconId: number; preferredPositions: ApiPositionPreference[]; tiers: ApiTierInfo[]; + tierHistory: ApiTierHistoryEntry[]; masteries: ApiChampionMasteryEntry[]; recentStatsSummary?: ApiRiotRecentStatsSummary; passCount: number; diff --git a/apps/web/src/components/TierHistoryChart.tsx b/apps/web/src/components/TierHistoryChart.tsx index 6319dc78..53ac5bdd 100644 --- a/apps/web/src/components/TierHistoryChart.tsx +++ b/apps/web/src/components/TierHistoryChart.tsx @@ -159,8 +159,10 @@ function TierTooltip({ export default function TierHistoryChart({ entries, + className = "border border-base-content/10 bg-base-100 mb-5 overflow-hidden", }: { entries: ApiTierHistoryEntry[]; + className?: string; }) { // 데이터에 존재하는 큐 목록 (솔로 우선) const availableQueues = useMemo(() => { @@ -264,7 +266,7 @@ export default function TierHistoryChart({ ); return ( -
+
{header} {points.length < 2 ? (
diff --git a/apps/web/src/pages/AuctionPage.tsx b/apps/web/src/pages/AuctionPage.tsx index e1bd5f85..21eea02e 100644 --- a/apps/web/src/pages/AuctionPage.tsx +++ b/apps/web/src/pages/AuctionPage.tsx @@ -1,4 +1,6 @@ import { + lazy, + Suspense, useEffect, useMemo, useRef, @@ -17,6 +19,7 @@ import { useMe, useResetAuction, useUndoAuction, + useUserHistoryProfile, } from '../api/hooks'; import { mapApiAuctionToAuctionState, @@ -50,6 +53,8 @@ import type { Position, } from '../api/types'; +const TierHistoryChart = lazy(() => import('../components/TierHistoryChart')); + type CaptainRole = { teamIndex: number; }; @@ -481,7 +486,16 @@ function PlayerSpotlight({ }) { const { data: ddragon } = useDdragonManifest(); const player = state.currentPlayer; + const historyProfileQuery = useUserHistoryProfile( + player?.userId, + DEFAULT_COMMUNITY_ID, + Boolean(player && player.tierHistory.length === 0), + ); if (!player) return null; + const tierHistory = + player.tierHistory.length > 0 + ? player.tierHistory + : (historyProfileQuery.data?.tierHistory ?? []); return (
@@ -575,6 +589,19 @@ function PlayerSpotlight({
+ {tierHistory.length > 0 && ( + + } + > + + + )} + {(state.phase === 'bidding' || state.phase === 'sold') && (