diff --git a/CHANGELOG.md b/CHANGELOG.md index 0903fd7cd..edd5cbd55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ 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 +- Introduced the fuzzy search for the accounts endpoint +- Refactored the fuzzy search for the holdings of the assistant - Improved the language localization for Polish (`pl`) - Improved the language localization for Spanish (`es`) diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index f6cbbf105..748cdceb8 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -413,6 +413,7 @@ export class PortfolioController { filterByAssetClasses, filterByDataSource, filterByHoldingType, + filterBySearchQuery, filterBySymbol, filterByTags }); @@ -421,7 +422,6 @@ export class PortfolioController { dateRange, filters, impersonationId, - query: filterBySearchQuery, userId: this.request.user.id }); diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 5ad291238..784661e20 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -292,13 +292,11 @@ export class PortfolioService { dateRange, filters, impersonationId, - query, userId }: { dateRange: DateRange; filters?: Filter[]; impersonationId: string; - query?: string; userId: string; }) { userId = await this.getUserId(impersonationId, userId); @@ -311,13 +309,17 @@ export class PortfolioService { let holdings = Object.values(holdingsMap); - if (query) { + const searchQuery = filters.find(({ type }) => { + return type === 'SEARCH_QUERY'; + })?.id; + + if (searchQuery) { const fuse = new Fuse(holdings, { keys: ['isin', 'name', 'symbol'], threshold: 0.3 }); - holdings = fuse.search(query).map(({ item }) => { + holdings = fuse.search(searchQuery).map(({ item }) => { return item; }); }