diff --git a/apps/api/src/app/order/order.controller.ts b/apps/api/src/app/order/order.controller.ts index 7523c0c1c..2759dff0d 100644 --- a/apps/api/src/app/order/order.controller.ts +++ b/apps/api/src/app/order/order.controller.ts @@ -100,11 +100,11 @@ export class OrderController { @Query('accounts') filterByAccounts?: string, @Query('assetClasses') filterByAssetClasses?: string, @Query('dataSource') filterByDataSource?: string, - @Query('symbol') filterBySymbol?: string, @Query('range') dateRange?: DateRange, @Query('skip') skip?: number, @Query('sortColumn') sortColumn?: string, @Query('sortDirection') sortDirection?: Prisma.SortOrder, + @Query('symbol') filterBySymbol?: string, @Query('tags') filterByTags?: string, @Query('take') take?: number ): Promise { diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 5260ed22d..dcbc20e2b 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -345,13 +345,19 @@ export class OrderService { const { ACCOUNT: filtersByAccount, ASSET_CLASS: filtersByAssetClass, - DATA_SOURCE: filtersByDataSource, - SYMBOL: filtersBySymbol, TAG: filtersByTag } = groupBy(filters, ({ type }) => { return type; }); + const filterByDataSource = filters?.find(({ type }) => { + return type === 'DATA_SOURCE'; + })?.id; + + const filterBySymbol = filters?.find(({ type }) => { + return type === 'SYMBOL'; + })?.id; + const searchQuery = filters?.find(({ type }) => { return type === 'SEARCH_QUERY'; })?.id; @@ -397,24 +403,27 @@ export class OrderService { }; } - if (filtersByDataSource?.length > 0) { - where.SymbolProfile = { - dataSource: { - in: filtersByDataSource.map(({ id }) => { - return id; - }) - } - }; - } - - if (filtersBySymbol?.length > 0) { - where.SymbolProfile = { - symbol: { - in: filtersBySymbol.map(({ id }) => { - return id; - }) - } - }; + if (filterByDataSource && filterBySymbol) { + if (where.SymbolProfile) { + where.SymbolProfile = { + AND: [ + where.SymbolProfile, + { + AND: [ + { dataSource: filterByDataSource }, + { symbol: filterBySymbol } + ] + } + ] + }; + } else { + where.SymbolProfile = { + AND: [ + { dataSource: filterByDataSource }, + { symbol: filterBySymbol } + ] + }; + } } if (searchQuery) { diff --git a/apps/api/src/services/api/api.service.ts b/apps/api/src/services/api/api.service.ts index b4504a814..33bd07060 100644 --- a/apps/api/src/services/api/api.service.ts +++ b/apps/api/src/services/api/api.service.ts @@ -28,10 +28,10 @@ export class ApiService { const accountIds = filterByAccounts?.split(',') ?? []; const assetClasses = filterByAssetClasses?.split(',') ?? []; const assetSubClasses = filterByAssetSubClasses?.split(',') ?? []; - const dataSource = filterByDataSource?.split(',') ?? []; + const dataSource = filterByDataSource; const holdingType = filterByHoldingType; const searchQuery = filterBySearchQuery?.toLowerCase(); - const symbols = filterBySymbol?.split(',') ?? []; + const symbol = filterBySymbol; const tagIds = filterByTags?.split(',') ?? []; const filters = [ @@ -53,18 +53,6 @@ export class ApiService { type: 'ASSET_SUB_CLASS' }; }), - ...dataSource.map((dataSource) => { - return { - id: dataSource, - type: 'DATA_SOURCE' - }; - }), - ...symbols.map((symbol) => { - return { - id: symbol, - type: 'SYMBOL' - }; - }), ...tagIds.map((tagId) => { return { id: tagId, @@ -87,6 +75,20 @@ export class ApiService { }); } + if (dataSource) { + filters.push({ + id: dataSource, + type: 'DATA_SOURCE' + }); + } + + if (symbol) { + filters.push({ + id: symbol, + type: 'SYMBOL' + }); + } + return filters; } }