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 | c53e51d28bbaa4fb294eb335001719f82474244f (patch) | |
tree | b030e79f8a896f15a6cc11f9dedd004ea242debe /Timeline/ClientApp/src/app/utilities/url.ts | |
parent | c5cd6aebf8516b485180ae5cadc8fed34e74291d (diff) | |
download | timeline-c53e51d28bbaa4fb294eb335001719f82474244f.tar.gz timeline-c53e51d28bbaa4fb294eb335001719f82474244f.tar.bz2 timeline-c53e51d28bbaa4fb294eb335001719f82474244f.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;
}
|