api: remove undefined in API.Q

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/563/head
Varun Patil 2023-03-29 16:08:25 -07:00
parent b6d251ebf5
commit a0ff17df96
1 changed files with 12 additions and 2 deletions

View File

@ -43,10 +43,20 @@ export class API {
) {
if (!query) return url;
if (typeof query === "object") {
// Clean up undefined and null
Object.keys(query).forEach((key) => {
if (query[key] === undefined || query[key] === null) {
delete query[key];
}
});
// Convert to search params
query = new URLSearchParams(<any>query);
}
if (query instanceof URLSearchParams) {
query = query.toString();
} else if (typeof query === "object") {
query = new URLSearchParams(query as any).toString();
}
if (!query) return url;