Skip to content

Commit 98b27cd

Browse files
authored
rateCalculatorHelper updated (#59)
1 parent d787c93 commit 98b27cd

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
export function rateCalculatorHelper(
2-
rate: number | undefined,
32
totalAmount: number,
43
surchargeAmount: number
54
): number {
6-
if (typeof rate === 'undefined' || rate <= 0) {
7-
throw new Error('Invalid input: rate amount must be greater than 0.');
8-
} else {
9-
if (surchargeAmount <= 0 || totalAmount <= 0) {
10-
throw new Error('Invalid input: surchargeAmount and totalAmount must be greater than 0.');
11-
}
12-
const purchaseAmount = totalAmount - surchargeAmount
13-
if (purchaseAmount <= 0) {
14-
throw new Error('Invalid input: purchaseAmount amount must be greater than 0.');
15-
}
16-
const rate = (surchargeAmount / purchaseAmount) * 100
17-
return Number(rate.toFixed(1))
5+
if (surchargeAmount <= 0 || totalAmount <= 0) {
6+
throw new Error('Invalid input: surchargeAmount and totalAmount must be greater than 0.');
187
}
8+
const purchaseAmount = totalAmount - surchargeAmount
9+
if (purchaseAmount <= 0) {
10+
throw new Error('Invalid input: purchaseAmount amount must be greater than 0.');
11+
}
12+
const rate = (surchargeAmount / purchaseAmount) * 100
13+
return Number(rate.toFixed(1))
1914
}

functions/src/domain/surcharge/put/putSurchargeUsecase.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const putSurchargeUsecase = async (
1111

1212
if (request.totalAmount && request.surchargeAmount) {
1313
newRate = rateCalculatorHelper(
14-
undefined,
1514
request.totalAmount,
1615
request.surchargeAmount
1716
);

0 commit comments

Comments
 (0)