.
This commit is contained in:
1 parent
09286e7711
commit
feeb30c6a9
8 files changed
+196
-22
No files matched your search
@@ -54,6 +54,7 @@ export class AuctionController {
|
|||||||
})),
|
})),
|
||||||
initialPoints: body.initialPoints ?? 1000,
|
initialPoints: body.initialPoints ?? 1000,
|
||||||
maxTimerSeconds: body.maxTimerSeconds ?? 30,
|
maxTimerSeconds: body.maxTimerSeconds ?? 30,
|
||||||
|
bidExtensionSeconds: body.bidExtensionSeconds ?? 5,
|
||||||
topTierThreshold: body.topTierThreshold ?? 'NONE',
|
topTierThreshold: body.topTierThreshold ?? 'NONE',
|
||||||
manualTopTierUserIds: (body.manualTopTierUserIds ?? []).map(
|
manualTopTierUserIds: (body.manualTopTierUserIds ?? []).map(
|
||||||
(userId) => new mongoose.Types.ObjectId(userId),
|
(userId) => new mongoose.Types.ObjectId(userId),
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ describe('AuctionService', () => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
it('rejects bids when the team already has 5 members including captain', async () => {
|
it('rejects bids when the team already has 5 members including captain', async () => {
|
||||||
const matchId = new mongoose.Types.ObjectId();
|
const matchId = new mongoose.Types.ObjectId();
|
||||||
const auction = {
|
const auction = {
|
||||||
@@ -89,6 +93,50 @@ describe('AuctionService', () => {
|
|||||||
expect(auction.save).not.toHaveBeenCalled();
|
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 () => {
|
it('rejects sold confirmation when the winning team is already full', async () => {
|
||||||
const matchId = new mongoose.Types.ObjectId();
|
const matchId = new mongoose.Types.ObjectId();
|
||||||
const auction = {
|
const auction = {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ interface StartAuctionParams {
|
|||||||
}[];
|
}[];
|
||||||
initialPoints: number;
|
initialPoints: number;
|
||||||
maxTimerSeconds: number;
|
maxTimerSeconds: number;
|
||||||
|
bidExtensionSeconds: number;
|
||||||
topTierThreshold: AuctionTopTierThreshold;
|
topTierThreshold: AuctionTopTierThreshold;
|
||||||
manualTopTierUserIds: mongoose.Types.ObjectId[];
|
manualTopTierUserIds: mongoose.Types.ObjectId[];
|
||||||
}
|
}
|
||||||
@@ -188,6 +189,7 @@ export class AuctionService {
|
|||||||
bids: [],
|
bids: [],
|
||||||
currentBid: 0,
|
currentBid: 0,
|
||||||
maxTimerSeconds: params.maxTimerSeconds,
|
maxTimerSeconds: params.maxTimerSeconds,
|
||||||
|
bidExtensionSeconds: params.bidExtensionSeconds,
|
||||||
initialPoints: params.initialPoints,
|
initialPoints: params.initialPoints,
|
||||||
topTierThreshold: params.topTierThreshold,
|
topTierThreshold: params.topTierThreshold,
|
||||||
manualTopTierUserIds:
|
manualTopTierUserIds:
|
||||||
@@ -750,14 +752,24 @@ export class AuctionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private resolveBidExtensionSeconds(auction: AuctionDocument): number {
|
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) {
|
if (!auction.currentDeadline) {
|
||||||
return auction.maxTimerSeconds;
|
return maxTimerSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
const remainingSeconds = Math.ceil(
|
const remainingSeconds = Math.ceil(
|
||||||
(auction.currentDeadline.getTime() - Date.now()) / 1000,
|
(auction.currentDeadline.getTime() - Date.now()) / 1000,
|
||||||
);
|
);
|
||||||
return Math.max(5, remainingSeconds);
|
return Math.min(
|
||||||
|
maxTimerSeconds,
|
||||||
|
Math.max(minimumRemainingSeconds, remainingSeconds),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private assertTeamHasSlot(team: AuctionTeam): void {
|
private assertTeamHasSlot(team: AuctionTeam): void {
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ export class StartAuctionDto {
|
|||||||
@IsInt()
|
@IsInt()
|
||||||
@Min(5)
|
@Min(5)
|
||||||
maxTimerSeconds?: number;
|
maxTimerSeconds?: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsInt()
|
||||||
|
@Min(0)
|
||||||
|
bidExtensionSeconds?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PlaceBidDto {
|
export class PlaceBidDto {
|
||||||
|
|||||||
@@ -533,6 +533,7 @@ export interface Auction extends MongooseTimestamps {
|
|||||||
currentBid: number;
|
currentBid: number;
|
||||||
currentBidderTeamIndex?: number;
|
currentBidderTeamIndex?: number;
|
||||||
maxTimerSeconds: number;
|
maxTimerSeconds: number;
|
||||||
|
bidExtensionSeconds: number;
|
||||||
currentDeadline?: Date;
|
currentDeadline?: Date;
|
||||||
initialPoints: number;
|
initialPoints: number;
|
||||||
topTierThreshold: AuctionTopTierThreshold;
|
topTierThreshold: AuctionTopTierThreshold;
|
||||||
@@ -1300,6 +1301,7 @@ export const AuctionSchema = new Schema<Auction>(
|
|||||||
currentBid: { type: Number, required: true, default: 0 },
|
currentBid: { type: Number, required: true, default: 0 },
|
||||||
currentBidderTeamIndex: { type: Number, required: false, min: 1 },
|
currentBidderTeamIndex: { type: Number, required: false, min: 1 },
|
||||||
maxTimerSeconds: { type: Number, required: true, default: 30 },
|
maxTimerSeconds: { type: Number, required: true, default: 30 },
|
||||||
|
bidExtensionSeconds: { type: Number, required: true, default: 5, min: 0 },
|
||||||
currentDeadline: { type: Date, required: false },
|
currentDeadline: { type: Date, required: false },
|
||||||
initialPoints: { type: Number, required: true, default: 1000 },
|
initialPoints: { type: Number, required: true, default: 1000 },
|
||||||
topTierThreshold: {
|
topTierThreshold: {
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ export interface AuctionStateView {
|
|||||||
currentBidder: { teamIndex: number } | null;
|
currentBidder: { teamIndex: number } | null;
|
||||||
timer: number;
|
timer: number;
|
||||||
maxTimer: number;
|
maxTimer: number;
|
||||||
|
bidExtensionSeconds: number;
|
||||||
deadline?: string;
|
deadline?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,6 +522,7 @@ export function mapApiAuctionToAuctionState(
|
|||||||
: null,
|
: null,
|
||||||
timer,
|
timer,
|
||||||
maxTimer: auction.maxTimerSeconds,
|
maxTimer: auction.maxTimerSeconds,
|
||||||
|
bidExtensionSeconds: auction.bidExtensionSeconds ?? 5,
|
||||||
deadline: auction.currentDeadline,
|
deadline: auction.currentDeadline,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -269,6 +269,7 @@ export interface ApiAuction {
|
|||||||
currentBid: number;
|
currentBid: number;
|
||||||
currentBidderTeamIndex?: number;
|
currentBidderTeamIndex?: number;
|
||||||
maxTimerSeconds: number;
|
maxTimerSeconds: number;
|
||||||
|
bidExtensionSeconds: number;
|
||||||
currentDeadline?: string;
|
currentDeadline?: string;
|
||||||
initialPoints: number;
|
initialPoints: number;
|
||||||
topTierThreshold: AuctionTopTierThreshold;
|
topTierThreshold: AuctionTopTierThreshold;
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ type CaptainSelection = {
|
|||||||
initialPoints: string;
|
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) {
|
function captainSlotKey(slot: CaptainSelectionSlot) {
|
||||||
return String(slot.teamIndex);
|
return String(slot.teamIndex);
|
||||||
}
|
}
|
||||||
@@ -59,6 +63,19 @@ function parseInitialPointsInput(value: string) {
|
|||||||
return points;
|
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[]) {
|
function buildAuctionParticipantPool(participants: ApiMatchParticipant[]) {
|
||||||
const ordered = [...participants].sort(
|
const ordered = [...participants].sort(
|
||||||
(left, right) =>
|
(left, right) =>
|
||||||
@@ -969,6 +986,12 @@ export default function MatchDetailPage() {
|
|||||||
const [manualTopTierUserIds, setManualTopTierUserIds] = useState<string[]>(
|
const [manualTopTierUserIds, setManualTopTierUserIds] = useState<string[]>(
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
const [maxTimerSeconds, setMaxTimerSeconds] = useState(
|
||||||
|
String(DEFAULT_AUCTION_MAX_TIMER_SECONDS),
|
||||||
|
);
|
||||||
|
const [bidExtensionSeconds, setBidExtensionSeconds] = useState(
|
||||||
|
String(DEFAULT_AUCTION_BID_EXTENSION_SECONDS),
|
||||||
|
);
|
||||||
const pollTournamentResultMutation =
|
const pollTournamentResultMutation =
|
||||||
usePollTournamentResult(DEFAULT_COMMUNITY_ID);
|
usePollTournamentResult(DEFAULT_COMMUNITY_ID);
|
||||||
|
|
||||||
@@ -1016,7 +1039,12 @@ export default function MatchDetailPage() {
|
|||||||
topTierThreshold,
|
topTierThreshold,
|
||||||
manualTopTierUserIds:
|
manualTopTierUserIds:
|
||||||
topTierThreshold === "MANUAL" ? selectedManualTopTierUserIds : [],
|
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 () => {
|
onSuccess: async () => {
|
||||||
@@ -1157,6 +1185,13 @@ export default function MatchDetailPage() {
|
|||||||
const selectedManualTopTierUserIds = manualTopTierUserIds.filter((userId) =>
|
const selectedManualTopTierUserIds = manualTopTierUserIds.filter((userId) =>
|
||||||
manualPriorityCandidateIds.has(userId),
|
manualPriorityCandidateIds.has(userId),
|
||||||
);
|
);
|
||||||
|
const parsedMaxTimerSeconds = parseAuctionSecondsInput(maxTimerSeconds, 5);
|
||||||
|
const parsedBidExtensionSeconds = parseAuctionSecondsInput(
|
||||||
|
bidExtensionSeconds,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const hasValidAuctionTimerSettings =
|
||||||
|
parsedMaxTimerSeconds !== null && parsedBidExtensionSeconds !== null;
|
||||||
const waitingParticipantCount =
|
const waitingParticipantCount =
|
||||||
matchQuery.data.participants.length - auctionParticipantPool.length;
|
matchQuery.data.participants.length - auctionParticipantPool.length;
|
||||||
const canStartAuction =
|
const canStartAuction =
|
||||||
@@ -1165,7 +1200,8 @@ export default function MatchDetailPage() {
|
|||||||
auctionParticipantPool.length >= 10 &&
|
auctionParticipantPool.length >= 10 &&
|
||||||
auctionNotStarted &&
|
auctionNotStarted &&
|
||||||
hasUniqueCaptainSelections &&
|
hasUniqueCaptainSelections &&
|
||||||
hasValidCaptainInitialPoints;
|
hasValidCaptainInitialPoints &&
|
||||||
|
hasValidAuctionTimerSettings;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-6">
|
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-6">
|
||||||
@@ -1384,24 +1420,91 @@ export default function MatchDetailPage() {
|
|||||||
경매를 시작하려면 최소 10명이 필요합니다.
|
경매를 시작하려면 최소 10명이 필요합니다.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<label className="block text-xs text-base-content/45">
|
<div className="grid gap-x-3 gap-y-4 sm:grid-cols-2">
|
||||||
상위 티어 우선 등장
|
<label className="block text-xs text-base-content/45">
|
||||||
<select
|
경매 제한 시간
|
||||||
className="mt-1 w-full max-w-xs border border-base-content/10 bg-transparent px-2 py-2 text-sm"
|
<div className="mt-1 flex items-center border border-base-content/10 bg-transparent focus-within:border-primary/30">
|
||||||
value={topTierThreshold}
|
<input
|
||||||
onChange={(event) =>
|
type="number"
|
||||||
setTopTierThreshold(
|
min={5}
|
||||||
event.target.value as AuctionTopTierThreshold,
|
max={MAX_AUCTION_TIMER_SECONDS}
|
||||||
)
|
step={5}
|
||||||
}
|
className="min-w-0 flex-1 bg-transparent px-2 py-2 text-sm tabular-nums focus:outline-none"
|
||||||
>
|
value={maxTimerSeconds}
|
||||||
<option value="NONE">없음</option>
|
onChange={(event) =>
|
||||||
<option value="EMERALD">EMERALD+</option>
|
setMaxTimerSeconds(event.target.value)
|
||||||
<option value="DIAMOND">DIAMOND+</option>
|
}
|
||||||
<option value="MASTER">MASTER+</option>
|
onBlur={() => {
|
||||||
<option value="MANUAL">수동 선택</option>
|
if (
|
||||||
</select>
|
parseAuctionSecondsInput(maxTimerSeconds, 5)
|
||||||
</label>
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setMaxTimerSeconds(
|
||||||
|
String(DEFAULT_AUCTION_MAX_TIMER_SECONDS),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span className="shrink-0 px-2 text-[11px] text-base-content/30">
|
||||||
|
초
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
<label className="block text-xs text-base-content/45">
|
||||||
|
최저 입찰 보장 시간
|
||||||
|
<div className="mt-1 flex items-center border border-base-content/10 bg-transparent focus-within:border-primary/30">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
max={MAX_AUCTION_TIMER_SECONDS}
|
||||||
|
step={1}
|
||||||
|
className="min-w-0 flex-1 bg-transparent px-2 py-2 text-sm tabular-nums focus:outline-none"
|
||||||
|
value={bidExtensionSeconds}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBidExtensionSeconds(event.target.value)
|
||||||
|
}
|
||||||
|
onBlur={() => {
|
||||||
|
if (
|
||||||
|
parseAuctionSecondsInput(
|
||||||
|
bidExtensionSeconds,
|
||||||
|
0,
|
||||||
|
) !== null
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setBidExtensionSeconds(
|
||||||
|
String(DEFAULT_AUCTION_BID_EXTENSION_SECONDS),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span className="shrink-0 px-2 text-[11px] text-base-content/30">
|
||||||
|
초
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span className="mt-1 block text-[11px] text-base-content/30">
|
||||||
|
남은 시간이 이 값보다 적을 때 입찰하면 이 시간까지
|
||||||
|
늘어납니다.
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<label className="block text-xs text-base-content/45">
|
||||||
|
상위 티어 우선 등장
|
||||||
|
<select
|
||||||
|
className="mt-1 h-[38px] w-full border border-base-content/10 bg-transparent px-2 py-2 text-sm focus:border-primary/30 focus:outline-none"
|
||||||
|
value={topTierThreshold}
|
||||||
|
onChange={(event) =>
|
||||||
|
setTopTierThreshold(
|
||||||
|
event.target.value as AuctionTopTierThreshold,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="NONE">없음</option>
|
||||||
|
<option value="EMERALD">EMERALD+</option>
|
||||||
|
<option value="DIAMOND">DIAMOND+</option>
|
||||||
|
<option value="MASTER">MASTER+</option>
|
||||||
|
<option value="MANUAL">수동 선택</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
{topTierThreshold === "MANUAL" && (
|
{topTierThreshold === "MANUAL" && (
|
||||||
<div className="border border-base-content/10 bg-base-200/20 p-3">
|
<div className="border border-base-content/10 bg-base-200/20 p-3">
|
||||||
<div className="mb-2 text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
<div className="mb-2 text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
||||||
|
|||||||
Reference in new issue
Block a user