This commit is contained in:
dahyeon committed 2026-04-24 23:18:56 -07:00
1 parent 30dfb7ce58
commit 5af2c80cd1
33 files changed
+3806 -1440

No files matched your search

@@ -148,6 +148,7 @@ export class AuctionService {
auction.phase = 'bidding';
auction.currentBid = 0;
auction.currentBidder = undefined;
auction.currentDeadline = this.createDeadline(auction.maxTimerSeconds);
await auction.save();
return auction;
}
@@ -165,9 +166,18 @@ export class AuctionService {
if (params.amount > team.points) {
throw new BadRequestException('Bid exceeds team points.');
}
if (
params.bidderUserId &&
!team.captainUserId.equals(params.bidderUserId)
) {
throw new BadRequestException('Bidder is not the captain of this team.');
}
auction.currentBid = params.amount;
auction.currentBidder = params.side;
auction.currentDeadline = this.createDeadline(
this.resolveBidExtensionSeconds(auction),
);
auction.bids.push({
side: params.side,
amount: params.amount,
@@ -200,6 +210,7 @@ export class AuctionService {
});
team.points -= auction.currentBid;
auction.phase = 'sold';
auction.currentDeadline = undefined;
await auction.save();
return auction;
}
@@ -221,6 +232,7 @@ export class AuctionService {
auction.currentBid = 0;
auction.currentBidder = undefined;
}
auction.currentDeadline = undefined;
await auction.save();
return auction;
}
@@ -262,4 +274,19 @@ export class AuctionService {
await session.endSession();
}
}
private createDeadline(secondsFromNow: number): Date {
return new Date(Date.now() + secondsFromNow * 1000);
}
private resolveBidExtensionSeconds(auction: AuctionDocument): number {
if (!auction.currentDeadline) {
return auction.maxTimerSeconds;
}
const remainingSeconds = Math.ceil(
(auction.currentDeadline.getTime() - Date.now()) / 1000,
);
return Math.max(5, remainingSeconds);
}
}