Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions functions/src/domain/surcharge/helpers/rateCalculatorHelper.ts
Original file line number Diff line number Diff line change
@@ -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))
}
1 change: 0 additions & 1 deletion functions/src/domain/surcharge/put/putSurchargeUsecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const putSurchargeUsecase = async (

if (request.totalAmount && request.surchargeAmount) {
newRate = rateCalculatorHelper(
undefined,
request.totalAmount,
request.surchargeAmount
);
Expand Down