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,9 +1,11 @@
/**
* Domain Entity: Transaction
*
*
* Represents a financial transaction in the league wallet system.
*/
import { RacingDomainValidationError, RacingDomainInvariantError } from '../errors/RacingDomainError';
import type { Money } from '../value-objects/Money';
export type TransactionType =
@@ -76,23 +78,23 @@ export class Transaction {
private static validate(props: Omit<TransactionProps, 'createdAt' | 'status' | 'platformFee' | 'netAmount'>): void {
if (!props.id || props.id.trim().length === 0) {
throw new Error('Transaction ID is required');
throw new RacingDomainValidationError('Transaction ID is required');
}
if (!props.walletId || props.walletId.trim().length === 0) {
throw new Error('Transaction walletId is required');
throw new RacingDomainValidationError('Transaction walletId is required');
}
if (!props.type) {
throw new Error('Transaction type is required');
throw new RacingDomainValidationError('Transaction type is required');
}
if (!props.amount) {
throw new Error('Transaction amount is required');
throw new RacingDomainValidationError('Transaction amount is required');
}
if (props.amount.amount <= 0) {
throw new Error('Transaction amount must be greater than zero');
throw new RacingDomainValidationError('Transaction amount must be greater than zero');
}
}
@@ -101,11 +103,11 @@ export class Transaction {
*/
complete(): Transaction {
if (this.status === 'completed') {
throw new Error('Transaction is already completed');
throw new RacingDomainInvariantError('Transaction is already completed');
}
if (this.status === 'failed' || this.status === 'cancelled') {
throw new Error('Cannot complete a failed or cancelled transaction');
throw new RacingDomainInvariantError('Cannot complete a failed or cancelled transaction');
}
return new Transaction({
@@ -120,7 +122,7 @@ export class Transaction {
*/
fail(): Transaction {
if (this.status === 'completed') {
throw new Error('Cannot fail a completed transaction');
throw new RacingDomainInvariantError('Cannot fail a completed transaction');
}
return new Transaction({
@@ -134,7 +136,7 @@ export class Transaction {
*/
cancel(): Transaction {
if (this.status === 'completed') {
throw new Error('Cannot cancel a completed transaction');
throw new RacingDomainInvariantError('Cannot cancel a completed transaction');
}
return new Transaction({