diff options
Diffstat (limited to 'client/src/app/core/rest')
-rw-r--r-- | client/src/app/core/rest/rest.service.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/client/src/app/core/rest/rest.service.ts b/client/src/app/core/rest/rest.service.ts index 98e45ffc0..93b5f56b2 100644 --- a/client/src/app/core/rest/rest.service.ts +++ b/client/src/app/core/rest/rest.service.ts | |||
@@ -13,9 +13,8 @@ interface QueryStringFilterPrefixes { | |||
13 | } | 13 | } |
14 | } | 14 | } |
15 | 15 | ||
16 | type ParseQueryStringFilterResult = { | 16 | type ParseQueryStringFilters <K extends keyof any> = Partial<Record<K, string | number | boolean | (string | number | boolean)[]>> |
17 | [key: string]: string | number | boolean | (string | number | boolean)[] | 17 | type ParseQueryStringFiltersResult <K extends keyof any> = ParseQueryStringFilters<K> & { search?: string } |
18 | } | ||
19 | 18 | ||
20 | @Injectable() | 19 | @Injectable() |
21 | export class RestService { | 20 | export class RestService { |
@@ -67,14 +66,17 @@ export class RestService { | |||
67 | return params | 66 | return params |
68 | } | 67 | } |
69 | 68 | ||
70 | componentPaginationToRestPagination (componentPagination: ComponentPaginationLight): RestPagination { | 69 | componentToRestPagination (componentPagination: ComponentPaginationLight): RestPagination { |
71 | const start: number = (componentPagination.currentPage - 1) * componentPagination.itemsPerPage | 70 | const start: number = (componentPagination.currentPage - 1) * componentPagination.itemsPerPage |
72 | const count: number = componentPagination.itemsPerPage | 71 | const count: number = componentPagination.itemsPerPage |
73 | 72 | ||
74 | return { start, count } | 73 | return { start, count } |
75 | } | 74 | } |
76 | 75 | ||
77 | parseQueryStringFilter (q: string, prefixes: QueryStringFilterPrefixes): ParseQueryStringFilterResult { | 76 | /* |
77 | * Returns an object containing the filters and the remaining search | ||
78 | */ | ||
79 | parseQueryStringFilter <T extends QueryStringFilterPrefixes> (q: string, prefixes: T): ParseQueryStringFiltersResult<keyof T> { | ||
78 | if (!q) return {} | 80 | if (!q) return {} |
79 | 81 | ||
80 | // Tokenize the strings using spaces that are not in quotes | 82 | // Tokenize the strings using spaces that are not in quotes |
@@ -90,9 +92,9 @@ export class RestService { | |||
90 | return prefixeStrings.every(prefixString => t.startsWith(prefixString) === false) | 92 | return prefixeStrings.every(prefixString => t.startsWith(prefixString) === false) |
91 | }) | 93 | }) |
92 | 94 | ||
93 | const additionalFilters: ParseQueryStringFilterResult = {} | 95 | const additionalFilters: ParseQueryStringFilters<keyof T> = {} |
94 | 96 | ||
95 | for (const prefixKey of Object.keys(prefixes)) { | 97 | for (const prefixKey of Object.keys(prefixes) as (keyof T)[]) { |
96 | const prefixObj = prefixes[prefixKey] | 98 | const prefixObj = prefixes[prefixKey] |
97 | const prefix = prefixObj.prefix | 99 | const prefix = prefixObj.prefix |
98 | 100 | ||