Skip to content

Commit

Permalink
fix(filter): fix filter value and omit undefined filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kostyazgara committed Oct 31, 2022
1 parent 081f586 commit bff1cc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions packages/filter/lib/interceptors/filter.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TRecord, TResult>
implements KnexionInterceptor<TRecord, TResult>
Expand Down Expand Up @@ -40,11 +40,13 @@ export class FilterInterceptor<TRecord, TResult>
alias?: string,
): Record<string, unknown> {
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];
}),
);
}
}
2 changes: 1 addition & 1 deletion packages/filter/lib/interfaces/filter-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface FilterOptions {
}

export type FilterObject<TRecord> = Partial<
Record<keyof TRecord, string | number | null>
Record<keyof TRecord, string | number | boolean | null>
>;

export interface FilterObjectOptions extends FilterOptions {
Expand Down

0 comments on commit bff1cc0

Please sign in to comment.