diff --git a/apps/api/src/modules/auction/auction.controller.ts b/apps/api/src/modules/auction/auction.controller.ts index 8a4e28d0..86acec54 100644 --- a/apps/api/src/modules/auction/auction.controller.ts +++ b/apps/api/src/modules/auction/auction.controller.ts @@ -54,6 +54,7 @@ export class AuctionController { })), initialPoints: body.initialPoints ?? 1000, maxTimerSeconds: body.maxTimerSeconds ?? 30, + bidExtensionSeconds: body.bidExtensionSeconds ?? 5, topTierThreshold: body.topTierThreshold ?? 'NONE', manualTopTierUserIds: (body.manualTopTierUserIds ?? []).map( (userId) => new mongoose.Types.ObjectId(userId), diff --git a/apps/api/src/modules/auction/auction.service.spec.ts b/apps/api/src/modules/auction/auction.service.spec.ts index 054536af..f90d695c 100644 --- a/apps/api/src/modules/auction/auction.service.spec.ts +++ b/apps/api/src/modules/auction/auction.service.spec.ts @@ -65,6 +65,10 @@ describe('AuctionService', () => { }; } + afterEach(() => { + jest.useRealTimers(); + }); + it('rejects bids when the team already has 5 members including captain', async () => { const matchId = new mongoose.Types.ObjectId(); const auction = { @@ -89,6 +93,50 @@ describe('AuctionService', () => { expect(auction.save).not.toHaveBeenCalled(); }); + it('extends a short bid deadline using the configured bid extension seconds', async () => { + const now = new Date('2026-05-02T00:00:00.000Z'); + jest.useFakeTimers().setSystemTime(now); + + const matchId = new mongoose.Types.ObjectId(); + const captainUserId = new mongoose.Types.ObjectId(); + const auction = { + _id: new mongoose.Types.ObjectId(), + matchId, + phase: 'bidding', + teams: [ + { + teamIndex: 1, + captainUserId, + points: 1000, + members: [], + }, + ], + currentBid: 10, + currentDeadline: new Date(now.getTime() + 2000), + maxTimerSeconds: 30, + bidExtensionSeconds: 12, + bids: [], + save: jest.fn().mockResolvedValue(undefined), + toObject: jest.fn().mockReturnValue({ _id: 'auction', matchId }), + }; + const { service } = createService({ + auction: { + findOne: jest.fn().mockResolvedValue(auction), + }, + }); + + await service.placeBid({ + matchId, + teamIndex: 1, + amount: 20, + }); + + expect(auction.currentDeadline).toEqual( + new Date(now.getTime() + 12000), + ); + expect(auction.save).toHaveBeenCalledTimes(1); + }); + it('rejects sold confirmation when the winning team is already full', 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 83625137..df25faac 100644 --- a/apps/api/src/modules/auction/auction.service.ts +++ b/apps/api/src/modules/auction/auction.service.ts @@ -37,6 +37,7 @@ interface StartAuctionParams { }[]; initialPoints: number; maxTimerSeconds: number; + bidExtensionSeconds: number; topTierThreshold: AuctionTopTierThreshold; manualTopTierUserIds: mongoose.Types.ObjectId[]; } @@ -188,6 +189,7 @@ export class AuctionService { bids: [], currentBid: 0, maxTimerSeconds: params.maxTimerSeconds, + bidExtensionSeconds: params.bidExtensionSeconds, initialPoints: params.initialPoints, topTierThreshold: params.topTierThreshold, manualTopTierUserIds: @@ -750,14 +752,24 @@ export class AuctionService { } private resolveBidExtensionSeconds(auction: AuctionDocument): number { + const maxTimerSeconds = Math.max(5, auction.maxTimerSeconds ?? 30); + const bidExtensionSeconds = Math.max(0, auction.bidExtensionSeconds ?? 5); + const minimumRemainingSeconds = Math.min( + maxTimerSeconds, + bidExtensionSeconds, + ); + if (!auction.currentDeadline) { - return auction.maxTimerSeconds; + return maxTimerSeconds; } const remainingSeconds = Math.ceil( (auction.currentDeadline.getTime() - Date.now()) / 1000, ); - return Math.max(5, remainingSeconds); + return Math.min( + maxTimerSeconds, + Math.max(minimumRemainingSeconds, remainingSeconds), + ); } private assertTeamHasSlot(team: AuctionTeam): void { diff --git a/apps/api/src/modules/auction/dto/auction.dto.ts b/apps/api/src/modules/auction/dto/auction.dto.ts index 3474988e..9c4e4b8e 100644 --- a/apps/api/src/modules/auction/dto/auction.dto.ts +++ b/apps/api/src/modules/auction/dto/auction.dto.ts @@ -59,6 +59,11 @@ export class StartAuctionDto { @IsInt() @Min(5) maxTimerSeconds?: number; + + @IsOptional() + @IsInt() + @Min(0) + bidExtensionSeconds?: number; } export class PlaceBidDto { diff --git a/apps/api/src/modules/global/database/schema.ts b/apps/api/src/modules/global/database/schema.ts index 6442bc96..e151af91 100644 --- a/apps/api/src/modules/global/database/schema.ts +++ b/apps/api/src/modules/global/database/schema.ts @@ -533,6 +533,7 @@ export interface Auction extends MongooseTimestamps { currentBid: number; currentBidderTeamIndex?: number; maxTimerSeconds: number; + bidExtensionSeconds: number; currentDeadline?: Date; initialPoints: number; topTierThreshold: AuctionTopTierThreshold; @@ -1300,6 +1301,7 @@ export const AuctionSchema = new Schema( currentBid: { type: Number, required: true, default: 0 }, currentBidderTeamIndex: { type: Number, required: false, min: 1 }, maxTimerSeconds: { type: Number, required: true, default: 30 }, + bidExtensionSeconds: { type: Number, required: true, default: 5, min: 0 }, currentDeadline: { type: Date, required: false }, initialPoints: { type: Number, required: true, default: 1000 }, topTierThreshold: { diff --git a/apps/web/src/api/mappers.ts b/apps/web/src/api/mappers.ts index 90e81a23..3cb9c491 100644 --- a/apps/web/src/api/mappers.ts +++ b/apps/web/src/api/mappers.ts @@ -130,6 +130,7 @@ export interface AuctionStateView { currentBidder: { teamIndex: number } | null; timer: number; maxTimer: number; + bidExtensionSeconds: number; deadline?: string; } @@ -521,6 +522,7 @@ export function mapApiAuctionToAuctionState( : null, timer, maxTimer: auction.maxTimerSeconds, + bidExtensionSeconds: auction.bidExtensionSeconds ?? 5, deadline: auction.currentDeadline, }; } diff --git a/apps/web/src/api/types.ts b/apps/web/src/api/types.ts index f668056e..153293a1 100644 --- a/apps/web/src/api/types.ts +++ b/apps/web/src/api/types.ts @@ -269,6 +269,7 @@ export interface ApiAuction { currentBid: number; currentBidderTeamIndex?: number; maxTimerSeconds: number; + bidExtensionSeconds: number; currentDeadline?: string; initialPoints: number; topTierThreshold: AuctionTopTierThreshold; diff --git a/apps/web/src/pages/MatchDetailPage.tsx b/apps/web/src/pages/MatchDetailPage.tsx index 3937377d..4cbafc23 100644 --- a/apps/web/src/pages/MatchDetailPage.tsx +++ b/apps/web/src/pages/MatchDetailPage.tsx @@ -46,6 +46,10 @@ type CaptainSelection = { initialPoints: string; }; +const DEFAULT_AUCTION_MAX_TIMER_SECONDS = 30; +const DEFAULT_AUCTION_BID_EXTENSION_SECONDS = 5; +const MAX_AUCTION_TIMER_SECONDS = 3600; + function captainSlotKey(slot: CaptainSelectionSlot) { return String(slot.teamIndex); } @@ -59,6 +63,19 @@ function parseInitialPointsInput(value: string) { return points; } +function parseAuctionSecondsInput(value: string, min: number) { + if (!value.trim()) return null; + const seconds = Number(value); + if ( + !Number.isInteger(seconds) || + seconds < min || + seconds > MAX_AUCTION_TIMER_SECONDS + ) { + return null; + } + return seconds; +} + function buildAuctionParticipantPool(participants: ApiMatchParticipant[]) { const ordered = [...participants].sort( (left, right) => @@ -969,6 +986,12 @@ export default function MatchDetailPage() { const [manualTopTierUserIds, setManualTopTierUserIds] = useState( [], ); + const [maxTimerSeconds, setMaxTimerSeconds] = useState( + String(DEFAULT_AUCTION_MAX_TIMER_SECONDS), + ); + const [bidExtensionSeconds, setBidExtensionSeconds] = useState( + String(DEFAULT_AUCTION_BID_EXTENSION_SECONDS), + ); const pollTournamentResultMutation = usePollTournamentResult(DEFAULT_COMMUNITY_ID); @@ -1016,7 +1039,12 @@ export default function MatchDetailPage() { topTierThreshold, manualTopTierUserIds: topTierThreshold === "MANUAL" ? selectedManualTopTierUserIds : [], - maxTimerSeconds: 30, + maxTimerSeconds: + parseAuctionSecondsInput(maxTimerSeconds, 5) ?? + DEFAULT_AUCTION_MAX_TIMER_SECONDS, + bidExtensionSeconds: + parseAuctionSecondsInput(bidExtensionSeconds, 0) ?? + DEFAULT_AUCTION_BID_EXTENSION_SECONDS, }), }), onSuccess: async () => { @@ -1157,6 +1185,13 @@ export default function MatchDetailPage() { const selectedManualTopTierUserIds = manualTopTierUserIds.filter((userId) => manualPriorityCandidateIds.has(userId), ); + const parsedMaxTimerSeconds = parseAuctionSecondsInput(maxTimerSeconds, 5); + const parsedBidExtensionSeconds = parseAuctionSecondsInput( + bidExtensionSeconds, + 0, + ); + const hasValidAuctionTimerSettings = + parsedMaxTimerSeconds !== null && parsedBidExtensionSeconds !== null; const waitingParticipantCount = matchQuery.data.participants.length - auctionParticipantPool.length; const canStartAuction = @@ -1165,7 +1200,8 @@ export default function MatchDetailPage() { auctionParticipantPool.length >= 10 && auctionNotStarted && hasUniqueCaptainSelections && - hasValidCaptainInitialPoints; + hasValidCaptainInitialPoints && + hasValidAuctionTimerSettings; return (
@@ -1384,24 +1420,91 @@ export default function MatchDetailPage() { 경매를 시작하려면 최소 10명이 필요합니다. )} - +
+ + + +
{topTierThreshold === "MANUAL" && (