49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
export type CompetitionDomainErrorCode =
|
|
| 'DUPLICATE_FACT_ID'
|
|
| 'DUPLICATE_GAME_ID'
|
|
| 'DUPLICATE_RIOT_MATCH_ID'
|
|
| 'DUPLICATE_GAME_SLOT'
|
|
| 'DUPLICATE_GAME_ORDINAL'
|
|
| 'DUPLICATE_ADJUDICATION'
|
|
| 'FACT_REFERENCE_NOT_FOUND'
|
|
| 'FACT_ALREADY_REVERSED'
|
|
| 'FACT_TYPE_INVALID'
|
|
| 'GAME_SLOT_INVALID'
|
|
| 'GAME_ORDINAL_INVALID'
|
|
| 'GAME_SERIES_MISMATCH'
|
|
| 'GAME_TEAM_MISMATCH'
|
|
| 'GAME_WINNER_INVALID'
|
|
| 'SERIES_ALREADY_COMPLETED'
|
|
| 'SERIES_DEFINITION_INVALID'
|
|
| 'SERIES_PARTICIPANTS_INVALID'
|
|
| 'ADJUDICATION_INVALID'
|
|
| 'ADJUDICATION_DRAW_NOT_ALLOWED'
|
|
| 'WALKOVER_HAS_ACTIVE_GAMES';
|
|
|
|
/**
|
|
* A deterministic domain-invariant failure. Command handlers translate these
|
|
* errors to the appropriate HTTP conflict/validation response; projectors do
|
|
* not depend on NestJS or transport concerns.
|
|
*/
|
|
export class CompetitionDomainError extends Error {
|
|
constructor(
|
|
public readonly code: CompetitionDomainErrorCode,
|
|
message: string,
|
|
public readonly details?: Readonly<Record<string, unknown>>,
|
|
) {
|
|
super(message);
|
|
this.name = 'CompetitionDomainError';
|
|
}
|
|
}
|
|
|
|
export function assertCompetitionInvariant(
|
|
condition: unknown,
|
|
code: CompetitionDomainErrorCode,
|
|
message: string,
|
|
details?: Readonly<Record<string, unknown>>,
|
|
): asserts condition {
|
|
if (!condition) {
|
|
throw new CompetitionDomainError(code, message, details);
|
|
}
|
|
}
|