1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Fix filters (#1830)

* fix filters

* add chainid, fix test
This commit is contained in:
mihaisc 2022-12-13 11:42:56 +02:00 committed by GitHub
parent 025701a4fc
commit 6db159f1cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 27 deletions

View File

@ -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
}
}

View File

@ -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 } }] } }
]

View File

@ -42,28 +42,14 @@ export function getFilterTerm(
export function generateBaseQuery(
baseQueryParams: BaseQueryParams
): SearchQuery {
const generatedQuery = {
from: baseQueryParams.esPaginationOptions?.from || 0,
size:
baseQueryParams.esPaginationOptions?.size >= 0
? baseQueryParams.esPaginationOptions?.size
: 1000,
query: {
bool: {
...baseQueryParams.nestedQuery,
filter: [
...(baseQueryParams.filters || []),
baseQueryParams.chainIds
? getFilterTerm('chainId', baseQueryParams.chainIds)
: [],
getFilterTerm('_index', 'aquarius'),
...(baseQueryParams.ignorePurgatory
? []
: [getFilterTerm('purgatory.state', false)]),
...(baseQueryParams.ignoreState
? []
: [
{
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: [
{
@ -73,9 +59,17 @@ export function generateBaseQuery(
}
]
}
}
])
]
})
const generatedQuery = {
from: baseQueryParams.esPaginationOptions?.from || 0,
size:
baseQueryParams.esPaginationOptions?.size >= 0
? baseQueryParams.esPaginationOptions?.size
: 1000,
query: {
bool: {
...baseQueryParams.nestedQuery,
filter: filters
}
}
} as SearchQuery
@ -90,7 +84,6 @@ export function generateBaseQuery(
baseQueryParams.sortOptions.sortDirection ||
SortDirectionOptions.Descending
}
return generatedQuery
}