Skip to content

Commit 6ff505e

Browse files
committed
feat(graduated-tiered-pricing): [tpp] 🔵 push logic to SubscriptionsBeingPurchased
1 parent e6b3941 commit 6ff505e

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
import { Tier } from "./Tier";
2+
13
export class SubscriptionsBeingPurchased {
2-
constructor(public value: number) {}
4+
constructor(private value: number) {}
5+
6+
covers(tier: Tier): boolean {
7+
return this.value >= tier.to;
8+
}
9+
10+
reaches(tier: Tier): boolean {
11+
return this.value >= tier.from;
12+
}
13+
14+
numberOfSubscriptionsInTier(tier: Tier): number {
15+
return this.value - tier.from + 1;
16+
}
317
}

‎exercises/graduated_tiered_prices/solutions/codely_triangulation-with-tpp/src/Tier.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ export class Tier {
1111
return this.to - this.from + 1;
1212
}
1313

14-
fullTierTotal(): number {
14+
private fullTierTotal(): number {
1515
return this.size() * this.price;
1616
}
1717

1818
totalFor(subscriptions: SubscriptionsBeingPurchased): number {
19-
if (subscriptions.value >= this.to) {
19+
if (subscriptions.covers(this)) {
2020
return this.fullTierTotal();
2121
}
2222

23-
if (subscriptions.value < this.from) {
23+
if (!subscriptions.reaches(this)) {
2424
return 0;
2525
}
26-
27-
return (subscriptions.value - this.from + 1) * this.price;
26+
1;
27+
return subscriptions.numberOfSubscriptionsInTier(this) * this.price;
2828
}
2929
}

0 commit comments

Comments
 (0)