feat: connect tournament views to APIs and recover archived stats
Remove development previews and complete hall of fame, match history, official results, and multi-kill API integration. Fix active match pagination and team-ready controls, preserve basic scoreboards, and recover statistics when Riot archives arrive. Use bounded in-process cache invalidation retries and add the Riot match lookup index migration with regression coverage.
This commit is contained in:
1 parent
20e1e6ec04
commit
0d7617e2d2
70 files changed
+3739
-1793
No files matched your search
@@ -80,7 +80,7 @@ export class AuctionController {
|
||||
return this.auctionService.getStateByMatchId(matchId);
|
||||
}
|
||||
|
||||
// 공개 — 팀장 2명만 쓸 엔드포인트(트러스트 기반, 10명 동시 관전).
|
||||
// 공개 입찰 기록 조회.
|
||||
@Get('bids/history')
|
||||
@AllowPublicAccess()
|
||||
public async getBidHistory(
|
||||
@@ -106,14 +106,20 @@ export class AuctionController {
|
||||
}
|
||||
|
||||
@Post('bids')
|
||||
@AllowPublicAccess()
|
||||
@Roles('admin', 'owner', 'member')
|
||||
@UseGuards(RolesGuard)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async placeBid(
|
||||
@CurrentUser() currentUser: UserDocument,
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: PlaceBidDto,
|
||||
) {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
return this.auctionService.placeBid({
|
||||
matchId,
|
||||
bidderUserId: currentUser._id,
|
||||
teamIndex: body.bidderTeamIndex,
|
||||
amount: body.bidPointAmount,
|
||||
bidRequestId: body.bidRequestId,
|
||||
|
||||
@@ -78,6 +78,8 @@ describe('AuctionGateway', () => {
|
||||
expect(broadcast).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
const bidderUserId = new mongoose.Types.ObjectId();
|
||||
|
||||
function createGateway(params?: {
|
||||
getCurrentRedisTimestampMS?: jest.Mock;
|
||||
placeBidDelta?: jest.Mock;
|
||||
@@ -112,6 +114,23 @@ describe('AuctionGateway', () => {
|
||||
};
|
||||
}
|
||||
|
||||
it('requires an authenticated user before forwarding a bid', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId().toString();
|
||||
const { gateway, auctionService } = createGateway();
|
||||
const ack = jest.fn();
|
||||
|
||||
await gateway.handleBid(
|
||||
{ data: { matchId }, emit: jest.fn() } as never,
|
||||
{ bidderTeamIndex: 1, bidPointAmount: 100 },
|
||||
ack,
|
||||
);
|
||||
|
||||
expect(auctionService.placeBidDelta).not.toHaveBeenCalled();
|
||||
expect(ack).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ rejected: true }),
|
||||
);
|
||||
});
|
||||
|
||||
it('broadcasts a bid delta and acknowledges the matching bid request', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId().toString();
|
||||
const auctionBidHistoryEntry = {
|
||||
@@ -133,7 +152,10 @@ describe('AuctionGateway', () => {
|
||||
const ack = jest.fn();
|
||||
|
||||
await gateway.handleBid(
|
||||
{ data: { matchId }, emit: jest.fn() } as never,
|
||||
{
|
||||
data: { matchId, user: { _id: bidderUserId } },
|
||||
emit: jest.fn(),
|
||||
} as never,
|
||||
{
|
||||
bidPointAmount: 120,
|
||||
bidderTeamIndex: 2,
|
||||
@@ -147,6 +169,7 @@ describe('AuctionGateway', () => {
|
||||
expect(placeBidDelta).toHaveBeenCalledWith({
|
||||
amount: 120,
|
||||
bidRequestId: 'bid-1',
|
||||
bidderUserId,
|
||||
clientObservedAuctionLifecycleId: 'life-1',
|
||||
clientObservedCurrentBidRoundPlayerUserId: 'player-1',
|
||||
matchId: new mongoose.Types.ObjectId(matchId),
|
||||
@@ -200,7 +223,10 @@ describe('AuctionGateway', () => {
|
||||
const ack = jest.fn();
|
||||
|
||||
await gateway.handleBid(
|
||||
{ data: { matchId }, emit: jest.fn() } as never,
|
||||
{
|
||||
data: { matchId, user: { _id: bidderUserId } },
|
||||
emit: jest.fn(),
|
||||
} as never,
|
||||
{
|
||||
bidPointAmount: 50,
|
||||
bidderTeamIndex: 1,
|
||||
@@ -247,7 +273,10 @@ describe('AuctionGateway', () => {
|
||||
const ack = jest.fn();
|
||||
|
||||
await gateway.handleBid(
|
||||
{ data: { matchId }, emit: socketEmit } as never,
|
||||
{
|
||||
data: { matchId, user: { _id: bidderUserId } },
|
||||
emit: socketEmit,
|
||||
} as never,
|
||||
{
|
||||
bidPointAmount: 50,
|
||||
bidderTeamIndex: 1,
|
||||
@@ -318,7 +347,10 @@ describe('AuctionGateway', () => {
|
||||
revision: 3,
|
||||
});
|
||||
const socketEmit = jest.fn();
|
||||
const socket = { data: { matchId }, emit: socketEmit };
|
||||
const socket = {
|
||||
data: { matchId, user: { _id: bidderUserId } },
|
||||
emit: socketEmit,
|
||||
};
|
||||
const { gateway } = createGateway({ placeBidDelta });
|
||||
const acknowledgements: Array<Record<string, unknown>> = [];
|
||||
|
||||
@@ -359,7 +391,10 @@ describe('AuctionGateway', () => {
|
||||
currentHighestBidPointAmount: 50,
|
||||
revision: 3,
|
||||
});
|
||||
const socket = { data: { matchId }, emit: jest.fn() };
|
||||
const socket = {
|
||||
data: { matchId, user: { _id: bidderUserId } },
|
||||
emit: jest.fn(),
|
||||
};
|
||||
const { gateway } = createGateway({ placeBidDelta });
|
||||
|
||||
for (let index = 0; index < 8; index += 1) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { ForbiddenException, Logger } from '@nestjs/common';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { performance } from 'perf_hooks';
|
||||
import {
|
||||
@@ -86,6 +86,7 @@ interface AuctionSocketData {
|
||||
identity?: IdentityDocument;
|
||||
matchId?: string;
|
||||
user?: UserDocument;
|
||||
devUser?: UserDocument;
|
||||
}
|
||||
|
||||
type AuctionSocket = Socket<
|
||||
@@ -114,6 +115,10 @@ export class AuctionGateway implements OnGatewayConnection, OnGatewayInit {
|
||||
private server!: Namespace;
|
||||
|
||||
private readonly logger = new Logger(AuctionGateway.name);
|
||||
private readonly socketAuthentication = new WeakMap<
|
||||
AuctionSocket,
|
||||
Promise<void>
|
||||
>();
|
||||
|
||||
constructor(
|
||||
private readonly auctionService: AuctionService,
|
||||
@@ -130,8 +135,10 @@ export class AuctionGateway implements OnGatewayConnection, OnGatewayInit {
|
||||
}
|
||||
|
||||
public async handleConnection(socket: AuctionSocket) {
|
||||
const authentication = this.authenticateSocket(socket);
|
||||
this.socketAuthentication.set(socket, authentication);
|
||||
try {
|
||||
await this.authenticateSocket(socket);
|
||||
await authentication;
|
||||
this.logger.debug(`Auction client connected: ${socket.id}`);
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
@@ -153,11 +160,13 @@ export class AuctionGateway implements OnGatewayConnection, OnGatewayInit {
|
||||
return;
|
||||
}
|
||||
|
||||
await socket.join(payload.matchId);
|
||||
socket.data.matchId = payload.matchId;
|
||||
|
||||
try {
|
||||
socket.data.matchId = undefined;
|
||||
socket.data.user = undefined;
|
||||
await this.socketAuthentication.get(socket);
|
||||
await socket.join(payload.matchId);
|
||||
await this.resolveSocketUserForMatch(socket, payload.matchId);
|
||||
socket.data.matchId = payload.matchId;
|
||||
const auction = await this.auctionService.getByMatchId(
|
||||
new mongoose.Types.ObjectId(payload.matchId),
|
||||
);
|
||||
@@ -240,11 +249,17 @@ export class AuctionGateway implements OnGatewayConnection, OnGatewayInit {
|
||||
}
|
||||
|
||||
try {
|
||||
const bidderUserId = this.resolveSocketUserId(socket);
|
||||
if (!bidderUserId)
|
||||
throw new ForbiddenException(
|
||||
'팀장 계정으로 로그인해야 입찰할 수 있습니다.',
|
||||
);
|
||||
const bidResult = await this.auctionService.placeBidDelta({
|
||||
matchId: new mongoose.Types.ObjectId(matchId),
|
||||
teamIndex: payload.bidderTeamIndex,
|
||||
amount: payload.bidPointAmount,
|
||||
bidRequestId,
|
||||
bidderUserId,
|
||||
clientObservedBidRoundId: payload.clientObservedBidRoundId,
|
||||
clientObservedAuctionLifecycleId:
|
||||
payload.clientObservedAuctionLifecycleId,
|
||||
@@ -573,14 +588,13 @@ export class AuctionGateway implements OnGatewayConnection, OnGatewayInit {
|
||||
this.readHandshakeUserId(socket),
|
||||
);
|
||||
if (fallback) {
|
||||
socket.data.user = fallback.user;
|
||||
socket.data.devUser = fallback.user;
|
||||
socket.data.identity = fallback.identity;
|
||||
return;
|
||||
}
|
||||
|
||||
const token = this.readHandshakeToken(socket);
|
||||
if (!token) {
|
||||
// 임시 운영용: 경매 진행 중에는 로그인 없이도 관전/팀장 모드 선택/입찰을 허용한다.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -622,14 +636,22 @@ export class AuctionGateway implements OnGatewayConnection, OnGatewayInit {
|
||||
socket: AuctionSocket,
|
||||
matchId: string,
|
||||
): Promise<void> {
|
||||
if (socket.data.user || !socket.data.identity) return;
|
||||
const devUser = socket.data.devUser;
|
||||
const identity = socket.data.identity;
|
||||
if (!devUser && !identity) return;
|
||||
|
||||
const MatchModel = await this.connectionService.getModel('match');
|
||||
const match = await MatchModel.findById(matchId).select({
|
||||
communityId: 1,
|
||||
});
|
||||
if (!match) return;
|
||||
if (devUser) {
|
||||
socket.data.user = devUser.communityId.equals(match.communityId)
|
||||
? devUser
|
||||
: undefined;
|
||||
return;
|
||||
}
|
||||
if (!identity) return;
|
||||
|
||||
const UserModel = await this.connectionService.getModel('user');
|
||||
const user = await UserModel.findOne({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
ConflictException,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
@@ -795,6 +796,10 @@ export class AuctionService {
|
||||
}
|
||||
const team = this.findAuctionTeamByIndex(auction, params.teamIndex);
|
||||
if (!team) throw new BadRequestException('Unknown team.');
|
||||
this.assertBidderIsCaptain(
|
||||
params.bidderUserId,
|
||||
team.captainUserId.toString(),
|
||||
);
|
||||
if (params.amount <= auction.currentBid) {
|
||||
throw new BadRequestException('Bid must exceed current bid.');
|
||||
}
|
||||
@@ -807,8 +812,6 @@ export class AuctionService {
|
||||
'Bid must reserve minimum points for remaining slots.',
|
||||
);
|
||||
}
|
||||
// 임시 운영용: 클라이언트에서 선택한 팀장 모드를 신뢰하고 실제 로그인 사용자 검증은 건너뛴다.
|
||||
|
||||
await this.recordSnapshot(auction, 'bid', params.bidderUserId);
|
||||
auction.currentBid = params.amount;
|
||||
auction.currentBidderTeamIndex = params.teamIndex;
|
||||
@@ -929,6 +932,10 @@ export class AuctionService {
|
||||
if (!bidContext.bidderTeamCaptainUserId) {
|
||||
throw new BadRequestException('Unknown team.');
|
||||
}
|
||||
this.assertBidderIsCaptain(
|
||||
params.bidderUserId,
|
||||
bidContext.bidderTeamCaptainUserId,
|
||||
);
|
||||
|
||||
const auctionLifecycleId =
|
||||
params.clientObservedAuctionLifecycleId ?? bidContext.auctionLifecycleId;
|
||||
@@ -1005,6 +1012,10 @@ export class AuctionService {
|
||||
(entry) => Number(entry.teamIndex) === params.teamIndex,
|
||||
);
|
||||
if (!team) throw new BadRequestException('Unknown team.');
|
||||
this.assertBidderIsCaptain(
|
||||
params.bidderUserId,
|
||||
this.stringFromState(team.captainUserId),
|
||||
);
|
||||
|
||||
const auctionLifecycleId =
|
||||
params.clientObservedAuctionLifecycleId ??
|
||||
@@ -2906,6 +2917,15 @@ export class AuctionService {
|
||||
return auction.teams.find((team) => team.teamIndex === teamIndex);
|
||||
}
|
||||
|
||||
private assertBidderIsCaptain(
|
||||
bidderUserId: mongoose.Types.ObjectId | undefined,
|
||||
captainUserId: string,
|
||||
) {
|
||||
if (bidderUserId && bidderUserId.toString() !== captainUserId) {
|
||||
throw new ForbiddenException('해당 팀의 팀장만 입찰할 수 있습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
private createDeadline(secondsFromNow: number): Date {
|
||||
return new Date(Date.now() + secondsFromNow * 1000);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user