fix issues in core

This commit is contained in:
2025-12-23 16:16:12 +01:00
parent 120d3bb1a1
commit d04a21fe02
40 changed files with 280 additions and 841 deletions

View File

@@ -17,7 +17,7 @@ export interface MoneyProps {
}
export class Money implements IValueObject<MoneyProps> {
private static readonly PLATFORM_FEE_PERCENTAGE = 0.10;
static readonly DEFAULT_PLATFORM_FEE_PERCENTAGE = 0.10;
readonly amount: number;
readonly currency: Currency;
@@ -37,20 +37,24 @@ export class Money implements IValueObject<MoneyProps> {
return new Money(amount, currency);
}
// TODO i dont think platform fee must be coupled
/**
* Calculate platform fee (10%)
* Calculate a fee amount for a given percentage.
* Defaults to the current platform fee percentage.
*/
calculatePlatformFee(): Money {
const feeAmount = this.amount * Money.PLATFORM_FEE_PERCENTAGE;
calculatePlatformFee(platformFeePercentage: number = Money.DEFAULT_PLATFORM_FEE_PERCENTAGE): Money {
if (!Number.isFinite(platformFeePercentage) || platformFeePercentage < 0) {
throw new RacingDomainValidationError('Platform fee percentage must be a non-negative finite number');
}
const feeAmount = this.amount * platformFeePercentage;
return new Money(feeAmount, this.currency);
}
/**
* Calculate net amount after platform fee
* Calculate net amount after subtracting a fee.
* Defaults to subtracting the current platform fee percentage.
*/
calculateNetAmount(): Money {
const platformFee = this.calculatePlatformFee();
calculateNetAmount(platformFeePercentage: number = Money.DEFAULT_PLATFORM_FEE_PERCENTAGE): Money {
const platformFee = this.calculatePlatformFee(platformFeePercentage);
return new Money(this.amount - platformFee.amount, this.currency);
}