Last active
May 7, 2018 12:45
-
-
Save jlaine/1459871cc50daf98a789b139ca92d80d to your computer and use it in GitHub Desktop.
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
export function queryPaginated<T>(http: HttpClient, baseUrl: string, urlOrFilter?: string | object): Observable<Page<T>> { | |
let params = new HttpParams(); | |
let url = baseUrl; | |
if (typeof urlOrFilter === 'string') { | |
// we were given a page URL, use it | |
url = urlOrFilter; | |
} else if (typeof urlOrFilter === 'object') { | |
// we were given filtering criteria, build the query string | |
Object.keys(urlOrFilter).sort().forEach(key => { | |
const value = urlOrFilter[key]; | |
if (value !== null) { | |
params = params.set(key, value.toString()); | |
} | |
}); | |
} | |
return http.get<Page<T>>(url, { | |
params: params | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment