|
@ -30,7 +30,7 @@ export class PublicController { |
|
|
private readonly accessService: AccessService, |
|
|
private readonly accessService: AccessService, |
|
|
private readonly configurationService: ConfigurationService, |
|
|
private readonly configurationService: ConfigurationService, |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly _orderService: OrderService, |
|
|
private readonly orderService: OrderService, |
|
|
private readonly portfolioService: PortfolioService, |
|
|
private readonly portfolioService: PortfolioService, |
|
|
@Inject(REQUEST) private readonly request: RequestWithUser, |
|
|
@Inject(REQUEST) private readonly request: RequestWithUser, |
|
|
private readonly userService: UserService |
|
|
private readonly userService: UserService |
|
@ -61,68 +61,48 @@ export class PublicController { |
|
|
hasDetails = user.subscription.type === 'Premium'; |
|
|
hasDetails = user.subscription.type === 'Premium'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const detailsPromise = this.portfolioService.getDetails({ |
|
|
|
|
|
impersonationId: access.userId, |
|
|
|
|
|
userId: user.id, |
|
|
|
|
|
withMarkets: true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const performance1dPromise = this.portfolioService.getPerformance({ |
|
|
|
|
|
dateRange: '1d', |
|
|
|
|
|
impersonationId: undefined, |
|
|
|
|
|
userId: user.id |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const performanceMaxPromise = this.portfolioService.getPerformance({ |
|
|
|
|
|
dateRange: 'max', |
|
|
|
|
|
impersonationId: undefined, |
|
|
|
|
|
userId: user.id |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const performanceYtdPromise = this.portfolioService.getPerformance({ |
|
|
|
|
|
dateRange: 'ytd', |
|
|
|
|
|
impersonationId: undefined, |
|
|
|
|
|
userId: user.id |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const latestActivitiesPromise = this._orderService.getOrders({ |
|
|
|
|
|
includeDrafts: false, |
|
|
|
|
|
take: 10, |
|
|
|
|
|
sortColumn: 'date', |
|
|
|
|
|
sortDirection: 'desc', |
|
|
|
|
|
userCurrency: |
|
|
|
|
|
this.request.user?.settings?.settings.baseCurrency ?? DEFAULT_CURRENCY, |
|
|
|
|
|
userId: user.id, |
|
|
|
|
|
withExcludedAccountsAndActivities: false |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const [ |
|
|
const [ |
|
|
{ createdAt, holdings, markets }, |
|
|
{ createdAt, holdings, markets }, |
|
|
{ performance: performance1d }, |
|
|
{ performance: performance1d }, |
|
|
{ performance: performanceMax }, |
|
|
{ performance: performanceMax }, |
|
|
{ performance: performanceYtd } |
|
|
{ performance: performanceYtd } |
|
|
] = await Promise.all([ |
|
|
] = await Promise.all([ |
|
|
detailsPromise, |
|
|
this.portfolioService.getDetails({ |
|
|
performance1dPromise, |
|
|
impersonationId: access.userId, |
|
|
performanceMaxPromise, |
|
|
userId: user.id, |
|
|
performanceYtdPromise |
|
|
withMarkets: true |
|
|
|
|
|
}), |
|
|
|
|
|
...['1d', 'max', 'ytd'].map((dateRange) => { |
|
|
|
|
|
return this.portfolioService.getPerformance({ |
|
|
|
|
|
dateRange, |
|
|
|
|
|
impersonationId: undefined, |
|
|
|
|
|
userId: user.id |
|
|
|
|
|
}); |
|
|
|
|
|
}) |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
const latestActivitiesPromise = this.orderService.getOrders({ |
|
|
|
|
|
includeDrafts: false, |
|
|
|
|
|
sortColumn: 'date', |
|
|
|
|
|
sortDirection: 'desc', |
|
|
|
|
|
take: 10, |
|
|
|
|
|
userCurrency: user.settings?.settings.baseCurrency ?? DEFAULT_CURRENCY, |
|
|
|
|
|
userId: user.id, |
|
|
|
|
|
withExcludedAccountsAndActivities: false |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const { activities } = await latestActivitiesPromise; |
|
|
const { activities } = await latestActivitiesPromise; |
|
|
const latestActivities = activities.map((a) => { |
|
|
const latestActivities = activities.map((a) => ({ |
|
|
return { |
|
|
date: a.date, |
|
|
account: a.account |
|
|
quantity: a.quantity, |
|
|
? { name: a.account.name, currency: a.account.currency } |
|
|
SymbolProfile: { |
|
|
: undefined, |
|
|
|
|
|
dataSource: a.SymbolProfile?.dataSource, |
|
|
dataSource: a.SymbolProfile?.dataSource, |
|
|
date: a.date, |
|
|
|
|
|
name: a.SymbolProfile?.name ?? '', |
|
|
name: a.SymbolProfile?.name ?? '', |
|
|
quantity: a.quantity, |
|
|
symbol: a.SymbolProfile?.symbol ?? '' |
|
|
symbol: a.SymbolProfile?.symbol ?? '', |
|
|
}, |
|
|
type: a.type, |
|
|
type: a.type, |
|
|
unitPrice: a.unitPrice |
|
|
unitPrice: a.unitPrice |
|
|
}; |
|
|
})); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Object.values(markets ?? {}).forEach((market) => { |
|
|
Object.values(markets ?? {}).forEach((market) => { |
|
|
delete market.valueInBaseCurrency; |
|
|
delete market.valueInBaseCurrency; |
|
|