Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Jan 18, 2024
1 parent 0dee35a commit 2595f45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
15 changes: 10 additions & 5 deletions lib/domain/models/basket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@ class Basket {
.map((investmentDO) => Investment.from(investmentDO: investmentDO)))
.then((investments) => Future.wait(investments
.map((investment) => investment.getTotalInvestedAmount())))
.then((investedAmounts) =>
investedAmounts.fold(0, (value, element) => value + element));
.then((investedAmounts) => investedAmounts.isNotEmpty
? investedAmounts.reduce((value, element) => value + element)
: 0);
}

Future<double> getValue({final bool considerFuturePayments = false}) async {
return _investmentApi
.getBy(basketId: id)
.then((investments) => investments
.map((investmentDO) => Investment.from(investmentDO: investmentDO)))
.then((investments) => Future.wait(investments
.map((investment) => investment.getValueOn(date: DateTime.now(), considerFuturePayments: considerFuturePayments))))
.then((values) => values.fold(0, (value, element) => value + element));
.then((investments) => Future.wait(investments.map((investment) =>
investment.getValueOn(
date: DateTime.now(),
considerFuturePayments: considerFuturePayments))))
.then((values) => values.isNotEmpty
? values.reduce((value, element) => value + element)
: 0);
}

Future<List<Investment>> getInvestments() {
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/models/goal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Goal {
Investment.from(investmentDO: investmentDO))
.then((investment) => investment.getTotalInvestedAmount())
.then((amount) => amount * goalInvestment.split))))
.then((amounts) => amounts.reduce((value, element) => value + element));
.then((amounts) => amounts.isNotEmpty ? amounts.reduce((value, element) => value + element): 0);
}

Future<double> getMaturityAmount() {
Expand All @@ -80,7 +80,7 @@ class Goal {
.then((investment) => investment.getValueOn(
date: maturityDate, considerFuturePayments: true))
.then((amount) => amount * goalInvestment.split))))
.then((amounts) => amounts.reduce((value, element) => value + element));
.then((amounts) => amounts.isNotEmpty ? amounts.reduce((value, element) => value + element): 0);
}

Future<void> tagInvestment(
Expand Down
11 changes: 6 additions & 5 deletions lib/domain/models/investment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class Investment {
.map((transactionDO) =>
Transaction.from(transactionDO: transactionDO))
.toList())
.then((transactions) => transactions
.map((transaction) => transaction.amount)
.reduce((value, element) => value + element));
.then((transactions) =>
transactions.map((transaction) => transaction.amount))
.then((amounts) => amounts.isNotEmpty
? amounts.reduce((value, element) => value + element)
: 0);
}

Future<double> getValueOn(
Expand Down Expand Up @@ -199,8 +201,7 @@ class Investment {
(transactionDO) => Transaction.from(transactionDO: transactionDO));
}

Future<void> deleteTransaction(
{required final int id}) async {
Future<void> deleteTransaction({required final int id}) async {
return _transactionApi.deleteBy(id: id).then((count) => {});
}

Expand Down

0 comments on commit 2595f45

Please sign in to comment.