diff --git a/functions/src/domain/surcharge/helpers/rateCalculatorHelper.ts b/functions/src/domain/surcharge/helpers/rateCalculatorHelper.ts index d166651..e27e59d 100644 --- a/functions/src/domain/surcharge/helpers/rateCalculatorHelper.ts +++ b/functions/src/domain/surcharge/helpers/rateCalculatorHelper.ts @@ -1,19 +1,14 @@ export function rateCalculatorHelper( - rate: number | undefined, totalAmount: number, surchargeAmount: number ): number { - if (typeof rate === 'undefined' || rate <= 0) { - throw new Error('Invalid input: rate amount must be greater than 0.'); - } else { - if (surchargeAmount <= 0 || totalAmount <= 0) { - throw new Error('Invalid input: surchargeAmount and totalAmount must be greater than 0.'); - } - const purchaseAmount = totalAmount - surchargeAmount - if (purchaseAmount <= 0) { - throw new Error('Invalid input: purchaseAmount amount must be greater than 0.'); - } - const rate = (surchargeAmount / purchaseAmount) * 100 - return Number(rate.toFixed(1)) + if (surchargeAmount <= 0 || totalAmount <= 0) { + throw new Error('Invalid input: surchargeAmount and totalAmount must be greater than 0.'); } + const purchaseAmount = totalAmount - surchargeAmount + if (purchaseAmount <= 0) { + throw new Error('Invalid input: purchaseAmount amount must be greater than 0.'); + } + const rate = (surchargeAmount / purchaseAmount) * 100 + return Number(rate.toFixed(1)) } diff --git a/functions/src/domain/surcharge/put/putSurchargeUsecase.ts b/functions/src/domain/surcharge/put/putSurchargeUsecase.ts index 1371fb4..8e5f419 100644 --- a/functions/src/domain/surcharge/put/putSurchargeUsecase.ts +++ b/functions/src/domain/surcharge/put/putSurchargeUsecase.ts @@ -11,7 +11,6 @@ export const putSurchargeUsecase = async ( if (request.totalAmount && request.surchargeAmount) { newRate = rateCalculatorHelper( - undefined, request.totalAmount, request.surchargeAmount );