Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: project applications server side paging and sorting and filteri…
…ng (#6236) Uses exactly same pattern as search-store. Nothing too crazy here. Most code is in tests.
- Loading branch information
Showing
12 changed files
with
435 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Knex } from 'knex'; | ||
import { IQueryParam } from '../feature-toggle/types/feature-toggle-strategies-store-type'; | ||
|
||
export const applySearchFilters = ( | ||
qb: Knex.QueryBuilder, | ||
searchParams: string[] | undefined, | ||
columns: string[], | ||
): void => { | ||
const hasSearchParams = searchParams?.length; | ||
if (hasSearchParams) { | ||
const sqlParameters = searchParams.map((item) => `%${item}%`); | ||
const sqlQueryParameters = sqlParameters.map(() => '?').join(','); | ||
|
||
qb.where((builder) => { | ||
columns.forEach((column) => { | ||
builder.orWhereRaw( | ||
`(${column}) ILIKE ANY (ARRAY[${sqlQueryParameters}])`, | ||
sqlParameters, | ||
); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
export const applyGenericQueryParams = ( | ||
query: Knex.QueryBuilder, | ||
queryParams: IQueryParam[], | ||
): void => { | ||
queryParams.forEach((param) => { | ||
switch (param.operator) { | ||
case 'IS': | ||
case 'IS_ANY_OF': | ||
query.whereIn(param.field, param.values); | ||
break; | ||
case 'IS_NOT': | ||
case 'IS_NONE_OF': | ||
query.whereNotIn(param.field, param.values); | ||
break; | ||
case 'IS_BEFORE': | ||
query.where(param.field, '<', param.values[0]); | ||
break; | ||
case 'IS_ON_OR_AFTER': | ||
query.where(param.field, '>=', param.values[0]); | ||
break; | ||
} | ||
}); | ||
}; |
Oops, something went wrong.