|
@ -51,6 +51,7 @@ import { Inject, Injectable } from '@nestjs/common'; |
|
|
import { REQUEST } from '@nestjs/core'; |
|
|
import { REQUEST } from '@nestjs/core'; |
|
|
import { |
|
|
import { |
|
|
Account, |
|
|
Account, |
|
|
|
|
|
AccountBalance, |
|
|
AssetClass, |
|
|
AssetClass, |
|
|
DataSource, |
|
|
DataSource, |
|
|
Order, |
|
|
Order, |
|
@ -125,7 +126,10 @@ export class PortfolioService { |
|
|
const [accounts, details] = await Promise.all([ |
|
|
const [accounts, details] = await Promise.all([ |
|
|
this.accountService.accounts({ |
|
|
this.accountService.accounts({ |
|
|
where, |
|
|
where, |
|
|
include: { Order: true, Platform: true }, |
|
|
include: { |
|
|
|
|
|
Order: true, |
|
|
|
|
|
Platform: true |
|
|
|
|
|
}, |
|
|
orderBy: { name: 'asc' } |
|
|
orderBy: { name: 'asc' } |
|
|
}), |
|
|
}), |
|
|
this.getDetails({ |
|
|
this.getDetails({ |
|
@ -154,8 +158,9 @@ export class PortfolioService { |
|
|
...account, |
|
|
...account, |
|
|
transactionCount, |
|
|
transactionCount, |
|
|
valueInBaseCurrency, |
|
|
valueInBaseCurrency, |
|
|
|
|
|
balance: details.accounts[account.id].balance, |
|
|
balanceInBaseCurrency: this.exchangeRateDataService.toCurrency( |
|
|
balanceInBaseCurrency: this.exchangeRateDataService.toCurrency( |
|
|
account.balance, |
|
|
details.accounts[account.id].balance, |
|
|
account.currency, |
|
|
account.currency, |
|
|
userCurrency |
|
|
userCurrency |
|
|
), |
|
|
), |
|
@ -1795,6 +1800,7 @@ export class PortfolioService { |
|
|
const platforms: PortfolioDetails['platforms'] = {}; |
|
|
const platforms: PortfolioDetails['platforms'] = {}; |
|
|
|
|
|
|
|
|
let currentAccounts: (Account & { |
|
|
let currentAccounts: (Account & { |
|
|
|
|
|
balances?: AccountBalance[]; |
|
|
Order?: Order[]; |
|
|
Order?: Order[]; |
|
|
Platform?: Platform; |
|
|
Platform?: Platform; |
|
|
})[] = []; |
|
|
})[] = []; |
|
@ -1803,7 +1809,10 @@ export class PortfolioService { |
|
|
currentAccounts = await this.accountService.getAccounts(userId); |
|
|
currentAccounts = await this.accountService.getAccounts(userId); |
|
|
} else if (filters.length === 1 && filters[0].type === 'ACCOUNT') { |
|
|
} else if (filters.length === 1 && filters[0].type === 'ACCOUNT') { |
|
|
currentAccounts = await this.accountService.accounts({ |
|
|
currentAccounts = await this.accountService.accounts({ |
|
|
include: { Platform: true }, |
|
|
include: { |
|
|
|
|
|
balances: { orderBy: { createdAt: 'desc' }, take: 1 }, |
|
|
|
|
|
Platform: true |
|
|
|
|
|
}, |
|
|
where: { id: filters[0].id } |
|
|
where: { id: filters[0].id } |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
@ -1837,11 +1846,11 @@ export class PortfolioService { |
|
|
ordersByAccount = ordersByAccount.concat(ordersOfTypeItemByAccount); |
|
|
ordersByAccount = ordersByAccount.concat(ordersOfTypeItemByAccount); |
|
|
|
|
|
|
|
|
accounts[account.id] = { |
|
|
accounts[account.id] = { |
|
|
balance: account.balance, |
|
|
balance: account.balances[0].value, |
|
|
currency: account.currency, |
|
|
currency: account.currency, |
|
|
name: account.name, |
|
|
name: account.name, |
|
|
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( |
|
|
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( |
|
|
account.balance, |
|
|
account.balances[0].value, |
|
|
account.currency, |
|
|
account.currency, |
|
|
userCurrency |
|
|
userCurrency |
|
|
) |
|
|
) |
|
@ -1850,17 +1859,17 @@ export class PortfolioService { |
|
|
if (platforms[account.Platform?.id || UNKNOWN_KEY]?.valueInBaseCurrency) { |
|
|
if (platforms[account.Platform?.id || UNKNOWN_KEY]?.valueInBaseCurrency) { |
|
|
platforms[account.Platform?.id || UNKNOWN_KEY].valueInBaseCurrency += |
|
|
platforms[account.Platform?.id || UNKNOWN_KEY].valueInBaseCurrency += |
|
|
this.exchangeRateDataService.toCurrency( |
|
|
this.exchangeRateDataService.toCurrency( |
|
|
account.balance, |
|
|
account.balances[0].value, |
|
|
account.currency, |
|
|
account.currency, |
|
|
userCurrency |
|
|
userCurrency |
|
|
); |
|
|
); |
|
|
} else { |
|
|
} else { |
|
|
platforms[account.Platform?.id || UNKNOWN_KEY] = { |
|
|
platforms[account.Platform?.id || UNKNOWN_KEY] = { |
|
|
balance: account.balance, |
|
|
balance: account.balances[0].value, |
|
|
currency: account.currency, |
|
|
currency: account.currency, |
|
|
name: account.Platform?.name, |
|
|
name: account.Platform?.name, |
|
|
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( |
|
|
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( |
|
|
account.balance, |
|
|
account.balances[0].value, |
|
|
account.currency, |
|
|
account.currency, |
|
|
userCurrency |
|
|
userCurrency |
|
|
) |
|
|
) |
|
|