diff options
author | crupest <crupest@outlook.com> | 2020-07-31 23:13:03 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-31 23:13:03 +0800 |
commit | 9014a5b52e9810eb71bc88b3645b0e716a8576ca (patch) | |
tree | a1a8cdb46a3f1b2770c7a1c310de1a64cada4c8a /Timeline/ClientApp/src/app/utilities/url.ts | |
parent | da0ba10c5f28b494f93b28956ccb96a4d6bd3b94 (diff) | |
download | timeline-9014a5b52e9810eb71bc88b3645b0e716a8576ca.tar.gz timeline-9014a5b52e9810eb71bc88b3645b0e716a8576ca.tar.bz2 timeline-9014a5b52e9810eb71bc88b3645b0e716a8576ca.zip |
Add http get timeline api query params.
Diffstat (limited to 'Timeline/ClientApp/src/app/utilities/url.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/utilities/url.ts | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Timeline/ClientApp/src/app/utilities/url.ts b/Timeline/ClientApp/src/app/utilities/url.ts index 0b8623a2..90923fd2 100644 --- a/Timeline/ClientApp/src/app/utilities/url.ts +++ b/Timeline/ClientApp/src/app/utilities/url.ts @@ -34,8 +34,19 @@ export function updateQueryString( }
export function applyQueryParameters<T>(url: string, query: T): string {
+ if (query == null) return url;
+
for (const [key, value] of Object.entries(query)) {
- url = updateQueryString(key, String(value), url);
+ if (typeof value === 'string') url = updateQueryString(key, value, url);
+ else if (typeof value === 'number')
+ url = updateQueryString(key, String(value), url);
+ else if (typeof value === 'boolean')
+ url = updateQueryString(key, value ? 'true' : 'false', url);
+ else if (value instanceof Date)
+ url = updateQueryString(key, value.toISOString(), url);
+ else {
+ console.error('Unknown query parameter type. Param: ', value);
+ }
}
return url;
}
|