From 6db159f1cc78d0b2718a9a3792fd50ebe80a5c18 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Tue, 13 Dec 2022 11:42:56 +0200 Subject: [PATCH] Fix filters (#1830) * fix filters * add chainid, fix test --- src/@types/aquarius/SearchQuery.ts | 1 + src/@utils/aquarius/index.test.ts | 2 +- src/@utils/aquarius/index.ts | 45 +++++++++++++----------------- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/@types/aquarius/SearchQuery.ts b/src/@types/aquarius/SearchQuery.ts index 026adbcfd..9dbabc564 100644 --- a/src/@types/aquarius/SearchQuery.ts +++ b/src/@types/aquarius/SearchQuery.ts @@ -46,6 +46,7 @@ declare global { // eslint-disable-next-line @typescript-eslint/no-explicit-any query: any sort?: { [jsonPath: string]: SortDirectionOptions } + // eslint-disable-next-line @typescript-eslint/no-explicit-any aggs?: any } } diff --git a/src/@utils/aquarius/index.test.ts b/src/@utils/aquarius/index.test.ts index e9d646de9..97a8446cb 100644 --- a/src/@utils/aquarius/index.test.ts +++ b/src/@utils/aquarius/index.test.ts @@ -9,8 +9,8 @@ const defaultBaseQueryReturn = { query: { bool: { filter: [ - { terms: { chainId: [1, 3] } }, { term: { _index: 'aquarius' } }, + { terms: { chainId: [1, 3] } }, { term: { 'purgatory.state': false } }, { bool: { must_not: [{ term: { 'nft.state': 5 } }] } } ] diff --git a/src/@utils/aquarius/index.ts b/src/@utils/aquarius/index.ts index 070037fcc..480e5506f 100644 --- a/src/@utils/aquarius/index.ts +++ b/src/@utils/aquarius/index.ts @@ -42,6 +42,24 @@ export function getFilterTerm( export function generateBaseQuery( baseQueryParams: BaseQueryParams ): SearchQuery { + const filters: unknown[] = [getFilterTerm('_index', 'aquarius')] + baseQueryParams.filters && filters.push(...baseQueryParams.filters) + baseQueryParams.chainIds && + filters.push(getFilterTerm('chainId', baseQueryParams.chainIds)) + !baseQueryParams.ignorePurgatory && + filters.push(getFilterTerm('purgatory.state', false)) + !baseQueryParams.ignoreState && + filters.push({ + bool: { + must_not: [ + { + term: { + 'nft.state': 5 + } + } + ] + } + }) const generatedQuery = { from: baseQueryParams.esPaginationOptions?.from || 0, size: @@ -51,31 +69,7 @@ export function generateBaseQuery( query: { bool: { ...baseQueryParams.nestedQuery, - filter: [ - ...(baseQueryParams.filters || []), - baseQueryParams.chainIds - ? getFilterTerm('chainId', baseQueryParams.chainIds) - : [], - getFilterTerm('_index', 'aquarius'), - ...(baseQueryParams.ignorePurgatory - ? [] - : [getFilterTerm('purgatory.state', false)]), - ...(baseQueryParams.ignoreState - ? [] - : [ - { - bool: { - must_not: [ - { - term: { - 'nft.state': 5 - } - } - ] - } - } - ]) - ] + filter: filters } } } as SearchQuery @@ -90,7 +84,6 @@ export function generateBaseQuery( baseQueryParams.sortOptions.sortDirection || SortDirectionOptions.Descending } - return generatedQuery }