diff --git a/src/paginate.spec.ts b/src/paginate.spec.ts index 8882fb4..35570bb 100644 --- a/src/paginate.spec.ts +++ b/src/paginate.spec.ts @@ -191,6 +191,37 @@ describe('paginate', () => { expect(result.links.current).toBe('?page=1&limit=20&sortBy=id:ASC&filter.name=$not:Leche') }) + it('should return result based on where array and filter', async () => { + const config: PaginateConfig = { + sortableColumns: ['id'], + where: [ + { + color: 'white', + }, + { + age: 4, + }, + ], + filterableColumns: { + name: [FilterOperator.NOT], + }, + } + const query: PaginateQuery = { + path: '', + filter: { + name: '$not:Leche', + }, + } + + const result = await paginate(query, repo, config) + + expect(result.meta.filter).toStrictEqual({ + name: '$not:Leche', + }) + expect(result.data).toStrictEqual([cats[2], cats[3]]) + expect(result.links.current).toBe('?page=1&limit=20&sortBy=id:ASC&filter.name=$not:Leche') + }) + it('should return result based on multiple filter', async () => { const config: PaginateConfig = { sortableColumns: ['id'], diff --git a/src/paginate.ts b/src/paginate.ts index 615ec46..ea7cc18 100644 --- a/src/paginate.ts +++ b/src/paginate.ts @@ -49,7 +49,7 @@ export interface PaginateConfig { maxLimit?: number defaultSortBy?: SortBy defaultLimit?: number - where?: FindConditions + where?: FindConditions | FindConditions[] filterableColumns?: { [key in Column]?: FilterOperator[] } }