This commit is contained in:
2025-12-11 11:25:22 +01:00
parent 6a427eab57
commit e4c1be628d
86 changed files with 1222 additions and 736 deletions

View File

@@ -1,10 +1,12 @@
/**
* Domain Entity: LeagueWallet
*
*
* Represents a league's financial wallet.
* Aggregate root for managing league finances and transactions.
*/
import { RacingDomainValidationError, RacingDomainInvariantError } from '../errors/RacingDomainError';
import type { Money } from '../value-objects/Money';
import type { Transaction } from './Transaction';
@@ -46,15 +48,15 @@ export class LeagueWallet {
private static validate(props: Omit<LeagueWalletProps, 'createdAt' | 'transactionIds'>): void {
if (!props.id || props.id.trim().length === 0) {
throw new Error('LeagueWallet ID is required');
throw new RacingDomainValidationError('LeagueWallet ID is required');
}
if (!props.leagueId || props.leagueId.trim().length === 0) {
throw new Error('LeagueWallet leagueId is required');
throw new RacingDomainValidationError('LeagueWallet leagueId is required');
}
if (!props.balance) {
throw new Error('LeagueWallet balance is required');
throw new RacingDomainValidationError('LeagueWallet balance is required');
}
}
@@ -63,7 +65,7 @@ export class LeagueWallet {
*/
addFunds(netAmount: Money, transactionId: string): LeagueWallet {
if (this.balance.currency !== netAmount.currency) {
throw new Error('Cannot add funds with different currency');
throw new RacingDomainInvariantError('Cannot add funds with different currency');
}
const newBalance = this.balance.add(netAmount);
@@ -81,11 +83,11 @@ export class LeagueWallet {
*/
withdrawFunds(amount: Money, transactionId: string): LeagueWallet {
if (this.balance.currency !== amount.currency) {
throw new Error('Cannot withdraw funds with different currency');
throw new RacingDomainInvariantError('Cannot withdraw funds with different currency');
}
if (!this.balance.isGreaterThan(amount) && !this.balance.equals(amount)) {
throw new Error('Insufficient balance for withdrawal');
throw new RacingDomainInvariantError('Insufficient balance for withdrawal');
}
const newBalance = this.balance.subtract(amount);