From bff1cc0874ad828e32f27d38904134a7675054bd Mon Sep 17 00:00:00 2001 From: Kostya Zgara Date: Mon, 31 Oct 2022 09:10:18 +0200 Subject: [PATCH] fix(filter): fix filter value and omit undefined filters --- .../filter/lib/interceptors/filter.interceptor.ts | 14 ++++++++------ .../lib/interfaces/filter-options.interface.ts | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/filter/lib/interceptors/filter.interceptor.ts b/packages/filter/lib/interceptors/filter.interceptor.ts index 43871671..996d676d 100644 --- a/packages/filter/lib/interceptors/filter.interceptor.ts +++ b/packages/filter/lib/interceptors/filter.interceptor.ts @@ -7,7 +7,7 @@ import { SelectDatabaseOptions, } from '@knexion/core'; import { FilterObject, FilterObjectOptions } from '../interfaces'; -import { isPlainObject } from '@nestjs/common/utils/shared.utils'; +import { isPlainObject, isUndefined } from '@nestjs/common/utils/shared.utils'; export class FilterInterceptor implements KnexionInterceptor @@ -40,11 +40,13 @@ export class FilterInterceptor alias?: string, ): Record { return Object.fromEntries( - Object.entries(filter).map(([name, value]) => { - const { useAlias = true } = this.options; - const column = useAlias ? addPrefixColumn(name, alias) : name; - return [column, value]; - }), + Object.entries(filter) + .filter(([, value]) => !isUndefined(value)) + .map(([name, value]) => { + const { useAlias = true } = this.options; + const column = useAlias ? addPrefixColumn(name, alias) : name; + return [column, value]; + }), ); } } diff --git a/packages/filter/lib/interfaces/filter-options.interface.ts b/packages/filter/lib/interfaces/filter-options.interface.ts index 59b02f8b..670f4b0f 100644 --- a/packages/filter/lib/interfaces/filter-options.interface.ts +++ b/packages/filter/lib/interfaces/filter-options.interface.ts @@ -3,7 +3,7 @@ export interface FilterOptions { } export type FilterObject = Partial< - Record + Record >; export interface FilterObjectOptions extends FilterOptions {