From 84eb166c54aacf2208b884c9b278124eccf71b47 Mon Sep 17 00:00:00 2001 From: PetruccioU Date: Fri, 31 Jan 2025 14:03:22 +1300 Subject: [PATCH] rateCalculatorHelper updated --- .../surcharge/helpers/rateCalculatorHelper.ts | 21 +++++++------------ .../surcharge/put/putSurchargeUsecase.ts | 1 - 2 files changed, 8 insertions(+), 14 deletions(-) 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 );