Browse Source
Feature/extend GET all accounts endpoint by search query filter (#5329)
* Extend GET all accounts endpoint by search query filter
* Update changelog
pull/5333/head^2
Attila Cseh
3 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
20 additions and
1 deletions
-
CHANGELOG.md
-
apps/api/src/app/account/account.controller.ts
-
apps/api/src/app/portfolio/portfolio.service.ts
|
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 |
|
|
|
### Changed |
|
|
|
|
|
|
|
- Extended the import functionality by tags |
|
|
|
- Introduced fuzzy search for the accounts endpoint |
|
|
|
- Improved the language localization for Polish (`pl`) |
|
|
|
- Improved the language localization for Spanish (`es`) |
|
|
|
|
|
|
|
|
|
@ -89,6 +89,7 @@ export class AccountController { |
|
|
|
public async getAllAccounts( |
|
|
|
@Headers(HEADER_KEY_IMPERSONATION.toLowerCase()) impersonationId: string, |
|
|
|
@Query('dataSource') filterByDataSource?: string, |
|
|
|
@Query('query') filterBySearchQuery?: string, |
|
|
|
@Query('symbol') filterBySymbol?: string |
|
|
|
): Promise<AccountsResponse> { |
|
|
|
const impersonationUserId = |
|
|
@ -96,6 +97,7 @@ export class AccountController { |
|
|
|
|
|
|
|
const filters = this.apiService.buildFiltersFromQueryParams({ |
|
|
|
filterByDataSource, |
|
|
|
filterBySearchQuery, |
|
|
|
filterBySymbol |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@ -220,11 +220,27 @@ export class PortfolioService { |
|
|
|
userId: string; |
|
|
|
withExcludedAccounts?: boolean; |
|
|
|
}): Promise<AccountsResponse> { |
|
|
|
const accounts = await this.getAccounts({ |
|
|
|
let accounts = await this.getAccounts({ |
|
|
|
filters, |
|
|
|
userId, |
|
|
|
withExcludedAccounts |
|
|
|
}); |
|
|
|
|
|
|
|
const searchQuery = filters.find(({ type }) => { |
|
|
|
return type === 'SEARCH_QUERY'; |
|
|
|
})?.id; |
|
|
|
|
|
|
|
if (searchQuery) { |
|
|
|
const fuse = new Fuse(accounts, { |
|
|
|
keys: ['name', 'platform.name'], |
|
|
|
threshold: 0.3 |
|
|
|
}); |
|
|
|
|
|
|
|
accounts = fuse.search(searchQuery).map(({ item }) => { |
|
|
|
return item; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
let totalBalanceInBaseCurrency = new Big(0); |
|
|
|
let totalValueInBaseCurrency = new Big(0); |
|
|
|
let transactionCount = 0; |
|
|
|