This commit is contained in:
dahyeon committed 2026-04-26 04:41:07 -07:00
1 parent 8369fbead7
commit ec2315cc3d
2 files changed
+237

No files matched your search

@@ -9,6 +9,7 @@ import { ConnectionService } from '../global/database/connection.service';
import {
AuctionDocument,
AuctionPlayerSnapshot,
MatchTeamMember,
Position,
TeamSide,
} from '../global/database/schema';
@@ -266,6 +267,9 @@ export class AuctionService {
}
auction.currentDeadline = undefined;
await auction.save();
if (auction.phase === 'complete') {
await this.syncMatchTeamsFromAuction(auction);
}
return auction;
}
@@ -296,6 +300,7 @@ export class AuctionService {
await auction.deleteOne({ session });
if (match.status === 'team-built') {
match.status = 'recruiting';
match.teams = [];
await match.save({ session });
}
await session.commitTransaction();
@@ -321,6 +326,52 @@ export class AuctionService {
);
return Math.max(5, remainingSeconds);
}
private async syncMatchTeamsFromAuction(
auction: AuctionDocument,
): Promise<void> {
const MatchModel = await this.connectionService.getModel('match');
const match = await MatchModel.findById(auction.matchId);
if (!match) throw new NotFoundException('Match not found.');
const participantByUserId = new Map(
match.participants.map((participant) => [
participant.userId.toString(),
participant,
]),
);
match.teams = auction.teams.map((team) => {
const captain = participantByUserId.get(team.captainUserId.toString());
const members: MatchTeamMember[] = [
{
userId: team.captainUserId,
assignedPosition: captain?.preferredPositions[0]?.position ?? 'MID',
cost: 0,
},
...team.members
.filter((member) => !member.userId.equals(team.captainUserId))
.map((member) => ({
userId: member.userId,
assignedPosition: member.assignedPosition,
cost: member.cost,
})),
];
return {
side: team.side,
name: this.resolveTeamName(team.side),
captainUserId: team.captainUserId,
members,
};
});
match.status = 'team-built';
await match.save();
}
private resolveTeamName(side: TeamSide): string {
return side === 'blue' ? '블루팀' : '레드팀';
}
}
async function runWithConcurrency<T>(