refactor: harden competition persistence type boundaries
This commit is contained in:
1 parent
ec92494211
commit
7ea2002975
7 files changed
+127
-62
No files matched your search
@@ -91,6 +91,13 @@ interface CommandEnvelope {
|
||||
payload: Readonly<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
interface AssignmentRecord {
|
||||
seriesId: PersistenceId;
|
||||
gameSlotId: PersistenceId;
|
||||
tournamentCodeId: PersistenceId;
|
||||
state: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CompetitionCommandService {
|
||||
constructor(private readonly connectionService: ConnectionService) {}
|
||||
@@ -170,7 +177,7 @@ export class CompetitionCommandService {
|
||||
.exec(),
|
||||
AssignmentModel.find({ competitionId: command.competitionId })
|
||||
.lean()
|
||||
.exec(),
|
||||
.exec() as Promise<AssignmentRecord[]>,
|
||||
]);
|
||||
const revisionCheck = await CompetitionModel.findById(command.competitionId)
|
||||
.lean()
|
||||
@@ -259,7 +266,7 @@ export class CompetitionCommandService {
|
||||
AssignmentModel.find({ competitionId: command.competitionId })
|
||||
.session(session)
|
||||
.lean()
|
||||
.exec(),
|
||||
.exec() as Promise<AssignmentRecord[]>,
|
||||
]);
|
||||
const input = reversalInput(
|
||||
competition,
|
||||
@@ -589,7 +596,7 @@ export class CompetitionCommandService {
|
||||
private async applyReversalAssignments(
|
||||
competitionId: PersistenceId,
|
||||
preview: SeriesReversalPreview,
|
||||
assignments: Array<Record<string, any>>,
|
||||
assignments: AssignmentRecord[],
|
||||
commandId: string,
|
||||
recordedAt: Date,
|
||||
session: mongoose.ClientSession,
|
||||
@@ -739,7 +746,11 @@ function buildOutbox(
|
||||
updatedCompetition: unknown,
|
||||
recordedAt: Date,
|
||||
): Readonly<Record<string, unknown>> {
|
||||
const facts = Array.isArray(fact) ? fact : [fact];
|
||||
const facts: readonly Readonly<Record<string, unknown>>[] = Array.isArray(
|
||||
fact,
|
||||
)
|
||||
? fact
|
||||
: [fact];
|
||||
return {
|
||||
eventId: `${commandId}:competition-projected`,
|
||||
competitionId,
|
||||
@@ -861,7 +872,7 @@ function reversalInput(
|
||||
competition: Pick<Competition, 'revision' | 'seriesGraph'>,
|
||||
command: PreviewSeriesReversalCommand,
|
||||
facts: readonly unknown[],
|
||||
assignments: readonly Record<string, any>[],
|
||||
assignments: readonly AssignmentRecord[],
|
||||
) {
|
||||
return {
|
||||
competitionId: idString(command.competitionId),
|
||||
|
||||
Reference in new issue
Block a user