fix: allow array of find options as where config (#88)
This commit is contained in:
parent
929cfe8d1e
commit
5f70471c77
@ -191,6 +191,37 @@ describe('paginate', () => {
|
|||||||
expect(result.links.current).toBe('?page=1&limit=20&sortBy=id:ASC&filter.name=$not:Leche')
|
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 () => {
|
it('should return result based on multiple filter', async () => {
|
||||||
const config: PaginateConfig<CatEntity> = {
|
const config: PaginateConfig<CatEntity> = {
|
||||||
sortableColumns: ['id'],
|
sortableColumns: ['id'],
|
||||||
|
@ -49,7 +49,7 @@ export interface PaginateConfig<T> {
|
|||||||
maxLimit?: number
|
maxLimit?: number
|
||||||
defaultSortBy?: SortBy<T>
|
defaultSortBy?: SortBy<T>
|
||||||
defaultLimit?: number
|
defaultLimit?: number
|
||||||
where?: FindConditions<T>
|
where?: FindConditions<T> | FindConditions<T>[]
|
||||||
filterableColumns?: { [key in Column<T>]?: FilterOperator[] }
|
filterableColumns?: { [key in Column<T>]?: FilterOperator[] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user