feat: enhance auction interactions and player statistics UI

This commit is contained in:
dahyeon committed 2026-11-11 20:06:22 +09:00
1 parent 6c582ba3cf
commit be4de61bb7
115 files changed
+13292 -2871

No files matched your search

+51 -11
View File
@@ -16,6 +16,7 @@ import {
} from './auction-lifecycle-lock';
import { AUCTION_OPTIONAL_PROJECTION_FIELDS } from './auction-projection';
import { AuctionEventBusService } from './auction-event-bus.service';
import { isAuctionCaptainAuthRequired } from './auction-bid-auth';
import { performance } from 'perf_hooks';
import mongoose from 'mongoose';
import { ConnectionService } from '../global/database/connection.service';
@@ -142,6 +143,8 @@ type RedisActionRequestContext =
interface AppendChatMessageParams {
matchId: mongoose.Types.ObjectId;
clientMessageId?: string;
senderRole?: 'operator';
userId?: mongoose.Types.ObjectId;
displayName?: string;
message: string;
@@ -666,26 +669,57 @@ export class AuctionService {
public async appendChatMessage(params: AppendChatMessageParams): Promise<{
auction: AuctionDocument;
message: AuctionChatMessage;
created: boolean;
}> {
const auction = await this.getByMatchId(params.matchId);
const messageText = this.normalizeChatMessage(params.message);
if (
params.clientMessageId !== undefined &&
!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
params.clientMessageId,
)
) {
throw new BadRequestException('Invalid chat message id.');
}
// A retry keeps its ID. The conditional push is atomic, including when
// the first request is still saving after the client has timed out.
const id = params.clientMessageId
? `${params.userId?.toString() ?? 'guest'}:${params.clientMessageId}`
: randomUUID();
const message: AuctionChatMessage = {
id: randomUUID(),
id,
clientMessageId: params.clientMessageId,
senderRole: params.senderRole,
userId: params.userId,
displayName: this.normalizeChatDisplayName(params.displayName),
message: messageText,
sentAt: new Date(),
};
auction.chatMessages ??= [];
auction.chatMessages.push(message);
const overflow = auction.chatMessages.length - AUCTION_CHAT_MAX_MESSAGES;
if (overflow > 0) {
auction.chatMessages.splice(0, overflow);
}
const AuctionModel = await this.connectionService.getModel('auction');
const auction = await AuctionModel.findOneAndUpdate(
{ matchId: params.matchId, 'chatMessages.id': { $ne: id } },
{
$push: {
chatMessages: {
$each: [message],
$slice: -AUCTION_CHAT_MAX_MESSAGES,
},
},
},
{ new: true },
);
if (auction) return { auction, message, created: true };
await auction.save();
return { auction, message };
const existingAuction = await this.getByMatchId(params.matchId);
const existing = existingAuction.chatMessages.find(
(entry) => entry.id === id,
);
if (!existing || existing.message !== messageText) {
throw new BadRequestException(
'Chat message conflicts with an earlier request.',
);
}
return { auction: existingAuction, message: existing, created: false };
}
public async listHistory(params: {
@@ -2921,7 +2955,13 @@ export class AuctionService {
bidderUserId: mongoose.Types.ObjectId | undefined,
captainUserId: string,
) {
if (bidderUserId && bidderUserId.toString() !== captainUserId) {
if (!isAuctionCaptainAuthRequired()) return;
if (!bidderUserId) {
throw new ForbiddenException(
'팀장 계정으로 로그인해야 입찰할 수 있습니다.',
);
}
if (bidderUserId.toString() !== captainUserId) {
throw new ForbiddenException('해당 팀의 팀장만 입찰할 수 있습니다.');
}
}