From 48e7e0cfdeb08257a952e72c2511a22548c32d24 Mon Sep 17 00:00:00 2001 From: Juan M Date: Sat, 13 Apr 2024 02:07:08 -0300 Subject: [PATCH] Split create address filter into two --- packages/poaps/src/PoapsClient.ts | 5 +-- packages/utils/src/queries/filter.ts | 51 +++++++++++++++------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/packages/poaps/src/PoapsClient.ts b/packages/poaps/src/PoapsClient.ts index 784a1139..33bff456 100644 --- a/packages/poaps/src/PoapsClient.ts +++ b/packages/poaps/src/PoapsClient.ts @@ -22,6 +22,7 @@ import { createBetweenFilter, createEqFilter, createInFilter, + createNotNullAddressFilter, createOrderBy, nextCursor, PaginatedResult, @@ -73,9 +74,9 @@ export class PoapsClient { offset, orderBy: createOrderBy(sortField, sortDir), where: { - ...createAddressFilter( + ...createAddressFilter('collector_address', collectorAddress), + ...createNotNullAddressFilter( 'collector_address', - collectorAddress, filterZeroAddress, filterDeadAddress, ), diff --git a/packages/utils/src/queries/filter.ts b/packages/utils/src/queries/filter.ts index 50d0359c..e84de61a 100644 --- a/packages/utils/src/queries/filter.ts +++ b/packages/utils/src/queries/filter.ts @@ -42,40 +42,43 @@ export function createBoolFilter( : {}; } -// eslint-disable-next-line complexity export function createAddressFilter( key: string, value?: string, - filterZeroAddress?: boolean, - filterDeadAddress?: boolean, -): FieldFilter< - Partial> & - Partial> & - Partial> -> { - return filterZeroAddress || filterDeadAddress || value +): FieldFilter>> { + return value ? { [key]: { - ...(filterZeroAddress && filterDeadAddress - ? { - _nin: [ - '0x0000000000000000000000000000000000000000', - '0x000000000000000000000000000000000000dead', - ], - } - : {}), - ...(filterZeroAddress && !filterDeadAddress - ? { _neq: '0x0000000000000000000000000000000000000000' } - : {}), - ...(!filterZeroAddress && filterDeadAddress - ? { _neq: '0x000000000000000000000000000000000000dead' } - : {}), - ...(value ? { _eq: value.toLowerCase() } : {}), + _eq: value.toLowerCase(), }, } : {}; } +export function createNotNullAddressFilter( + key: string, + filterZeroAddress = true, + filterDeadAddress = true, +): FieldFilter> & Partial>> { + if (filterZeroAddress && filterDeadAddress) { + return { + [key]: { + _nin: [ + '0x0000000000000000000000000000000000000000', + '0x000000000000000000000000000000000000dead', + ], + }, + }; + } + if (filterZeroAddress) { + return { [key]: { _neq: '0x0000000000000000000000000000000000000000' } }; + } + if (filterDeadAddress) { + return { [key]: { _neq: '0x000000000000000000000000000000000000dead' } }; + } + return {}; +} + export function createInFilter( key: string, values?: Array,