fix(auction): prevent skipped players and incomplete completion

This commit is contained in:
dahyeon committed 2026-11-05 23:14:14 +09:00
1 parent de84ad5309
commit 5bc748dc4d
10 files changed
+677 -32

No files matched your search

+55 -10
View File
@@ -1193,11 +1193,7 @@ export class AuctionService {
): Promise<AuctionStateResponse> {
const matchId = auction.matchId.toString();
const state = await this.requireRedisAuctionState(matchId);
if (
state.phase !== 'sold' &&
state.phase !== 'presenting' &&
state.phase !== 'passed'
) {
if (state.phase !== 'sold' && state.phase !== 'passed') {
throw new BadRequestException('Cannot advance from current phase.');
}
@@ -1218,6 +1214,10 @@ export class AuctionService {
structureInput.currentAuctionRound += 1;
structureInput.currentAuctionPlayerOrderIndex = nextIndex;
} else {
await this.assertCompleteAuctionRoster(
auction.matchId,
structureInput.auctionTeams,
);
action = 'complete';
nextPhase = 'complete';
}
@@ -1332,17 +1332,16 @@ export class AuctionService {
if (this.isRedisV1Auction(auction)) {
return this.advanceRedisAuction(auction, actionRequest);
}
if (
auction.phase !== 'sold' &&
auction.phase !== 'presenting' &&
auction.phase !== 'passed'
) {
if (auction.phase !== 'sold' && auction.phase !== 'passed') {
throw new BadRequestException('Cannot advance from current phase.');
}
const nextIndex = auction.currentIndex + 1;
const completesAuction =
nextIndex >= auction.order.length &&
(auction.passedQueue?.length ?? 0) === 0;
if (completesAuction) {
await this.assertCompleteAuctionRoster(matchId, auction.teams);
}
await this.recordSnapshot(auction, completesAuction ? 'complete' : 'next');
if (nextIndex >= auction.order.length) {
if ((auction.passedQueue?.length ?? 0) > 0) {
@@ -2515,6 +2514,52 @@ export class AuctionService {
return ordered.slice(0, desiredAuctionCount);
}
private async assertCompleteAuctionRoster(
matchId: mongoose.Types.ObjectId,
teams: Array<{
captainUserId: mongoose.Types.ObjectId;
members: Array<{ userId: mongoose.Types.ObjectId }>;
}>,
): Promise<void> {
const MatchModel = await this.connectionService.getModel('match');
const match = await MatchModel.findById(matchId);
if (!match) throw new NotFoundException('Match not found.');
// The queue can contain reauction entries or be corrupted; use the original roster.
const expectedIds = match.participants
.filter((participant) => !participant.excluded)
.map((participant) => participant.userId.toString());
const expected = new Set(expectedIds);
const assignedIds = teams.flatMap((team) => [
team.captainUserId.toString(),
...team.members.map((member) => member.userId.toString()),
]);
const assigned = new Set(assignedIds);
const missingUserIds = expectedIds.filter((id) => !assigned.has(id));
const unexpectedUserIds = [...assigned].filter((id) => !expected.has(id));
if (
expected.size === 0 ||
expected.size !== expectedIds.length ||
assigned.size !== assignedIds.length ||
missingUserIds.length > 0 ||
unexpectedUserIds.length > 0
) {
this.logger.error({
event: 'auction_roster_validation_failed',
matchId: matchId.toString(),
expectedCount: expectedIds.length,
assignedCount: assignedIds.length,
assignedUniqueCount: assigned.size,
missingUserIds,
unexpectedUserIds,
});
throw new BadRequestException({
code: 'AUCTION_ROSTER_INVALID',
message: 'Auction roster validation failed.',
});
}
}
private assertCaptainAssignments(
captains: StartAuctionParams['captains'],
activeParticipants: Array<{ userId: mongoose.Types.ObjectId }>,