fix: allow array of find options as where config (#88)

This commit is contained in:
Philipp 2021-09-28 13:15:24 +02:00 committed by GitHub
parent 929cfe8d1e
commit 5f70471c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -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<CatEntity> = {
sortableColumns: ['id'],
where: [
{
color: 'white',
},
{
age: 4,
},
],
filterableColumns: {
name: [FilterOperator.NOT],
},
}
const query: PaginateQuery = {
path: '',
filter: {
name: '$not:Leche',
},
}
const result = await paginate<CatEntity>(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<CatEntity> = {
sortableColumns: ['id'],

View File

@ -49,7 +49,7 @@ export interface PaginateConfig<T> {
maxLimit?: number
defaultSortBy?: SortBy<T>
defaultLimit?: number
where?: FindConditions<T>
where?: FindConditions<T> | FindConditions<T>[]
filterableColumns?: { [key in Column<T>]?: FilterOperator[] }
}