fix: close competition cutover integrity gaps

This commit is contained in:
dahyeon committed 2026-07-12 21:22:22 +00:00
1 parent 7ea2002975
commit 683d602d63
57 files changed
+4805 -1582

No files matched your search

@@ -13,7 +13,6 @@ import {
import mongoose from 'mongoose';
import { ConnectionService } from '../global/database/connection.service';
import type { Competition, CompetitionFact } from './competition.schema';
import { CompetitionBootstrapService } from './competition-bootstrap.service';
type PersistenceId = string | mongoose.Types.ObjectId;
type CompetitionRecord = Competition & { _id: mongoose.Types.ObjectId };
@@ -30,25 +29,12 @@ interface CompetitionProjectionSource {
@Injectable()
export class CompetitionQueryService {
constructor(
private readonly connectionService: ConnectionService,
private readonly bootstrapService: CompetitionBootstrapService,
) {}
constructor(private readonly connectionService: ConnectionService) {}
/** Resolve the one-to-one aggregate, lazily freezing a completed team build. */
/** Resolve the aggregate created by the finalized team-build workflow. */
public async getCompetition(
scope: CompetitionScope,
): Promise<CompetitionRecord> {
const CompetitionModel =
await this.connectionService.getModel('competition');
const existing = await CompetitionModel.findOne({
matchId: scope.matchId,
communityId: scope.communityId,
})
.lean()
.exec();
if (existing) return existing as CompetitionRecord;
const MatchModel = await this.connectionService.getModel('match');
const match = await MatchModel.findOne({
_id: scope.matchId,
@@ -66,7 +52,19 @@ export class CompetitionQueryService {
'Competition is unavailable until team building is complete.',
);
}
return this.bootstrapService.bootstrap(match as never);
const CompetitionModel =
await this.connectionService.getModel('competition');
const existing = await CompetitionModel.findOne({
matchId: scope.matchId,
communityId: scope.communityId,
})
.lean()
.exec();
if (existing) return existing as CompetitionRecord;
throw new ConflictException(
'Competition is still being initialized by the team-build workflow.',
);
}
public async getTeamView(
@@ -126,7 +124,10 @@ export class CompetitionQueryService {
const TournamentCodeModel =
await this.connectionService.getModel('tournamentCode');
const codes = codeIds.length
? await TournamentCodeModel.find({ _id: { $in: codeIds } })
? await TournamentCodeModel.find({
_id: { $in: codeIds },
state: { $in: ['reserved', 'used'] },
})
.lean()
.exec()
: [];
@@ -150,6 +151,17 @@ export class CompetitionQueryService {
const code = assignment
? codeById.get(idString(assignment.tournamentCodeId))
: undefined;
if (
assignment &&
(!code ||
code.state !== assignment.state ||
!code.matchId ||
!sameId(code.matchId, competition.matchId))
) {
throw new ConflictException(
'Tournament Code assignment is inconsistent and cannot be exposed.',
);
}
return {
gameSlotId: gameSlotId as never,
seriesId: idString(slot.seriesId as PersistenceId) as never,