fix(api): keep zero-bid auction passes open

This commit is contained in:
dahyeon committed 2026-06-07 07:01:01 -07:00
1 parent 6a192276e8
commit b711c63dcd
2 files changed
+67 -90

No files matched your search

@@ -345,9 +345,8 @@ export class AuctionService {
await this.recordSnapshot(auction, 'passed');
current.passCount = (current.passCount ?? 0) + 1;
if ((auction.auctionRound ?? 1) === 1) {
auction.passedQueue.push(this.cloneAuctionPlayerSnapshot(current));
}
auction.passedQueue ??= [];
auction.passedQueue.push(this.cloneAuctionPlayerSnapshot(current));
auction.phase = 'passed';
auction.currentDeadline = undefined;
await auction.save();
@@ -368,29 +367,22 @@ export class AuctionService {
const nextIndex = auction.currentIndex + 1;
const completesAuction =
nextIndex >= auction.order.length &&
!(
(auction.auctionRound ?? 1) === 1 &&
(auction.passedQueue?.length ?? 0) > 0
);
(auction.passedQueue?.length ?? 0) === 0;
await this.recordSnapshot(auction, completesAuction ? 'complete' : 'next');
if (nextIndex >= auction.order.length) {
if (
(auction.auctionRound ?? 1) === 1 &&
(auction.passedQueue?.length ?? 0) > 0
) {
if ((auction.passedQueue?.length ?? 0) > 0) {
auction.order.push(
...auction.passedQueue.map((player) =>
this.cloneAuctionPlayerSnapshot(player),
),
);
auction.passedQueue = [];
auction.auctionRound = 2;
auction.auctionRound = (auction.auctionRound ?? 1) + 1;
auction.currentIndex = nextIndex;
auction.phase = 'presenting';
auction.currentBid = 0;
auction.currentBidderTeamIndex = undefined;
} else {
this.forceAssignRemainingPasses(auction);
auction.phase = 'complete';
auction.completedAt = new Date();
}
@@ -603,41 +595,6 @@ export class AuctionService {
return shuffled;
}
private forceAssignRemainingPasses(auction: AuctionDocument): void {
const forcedPlayers = auction.order.filter(
(player) =>
(player.passCount ?? 0) >= 2 &&
!this.isAuctionPlayerAssigned(auction, player.userId),
);
for (const player of forcedPlayers) {
const targetTeam = [...auction.teams]
.filter(
(team) => this.countTeamMembersIncludingCaptain(team) < AUCTION_MAX_TEAM_SIZE,
)
.sort((left, right) => right.points - left.points)[0];
if (!targetTeam) return;
const preferredPrimary = player.preferredPositions[0]?.position;
targetTeam.members.push({
userId: player.userId,
assignedPosition: preferredPrimary ?? 'MID',
cost: 1,
});
targetTeam.points = Math.max(0, targetTeam.points - 1);
}
}
private isAuctionPlayerAssigned(
auction: AuctionDocument,
userId: mongoose.Types.ObjectId,
): boolean {
const userIdText = userId.toString();
return auction.teams.some((team) =>
team.members.some((member) => member.userId.toString() === userIdText),
);
}
private cloneAuctionPlayerSnapshot(
player: AuctionPlayerSnapshot,
): AuctionPlayerSnapshot {