DEV: Modernise rest adapter query parameter construction (#17925)
Using `URLSearchParams` means that we don't have to manually encode/join strings
This commit is contained in:
parent
b6c6c803c2
commit
a9e9adf253
|
@ -47,20 +47,22 @@ export default EmberObject.extend({
|
|||
appendQueryParams(path, findArgs, extension) {
|
||||
if (findArgs) {
|
||||
if (typeof findArgs === "object") {
|
||||
const queryString = Object.keys(findArgs)
|
||||
.reject((k) => !findArgs[k])
|
||||
.map((k) => k + "=" + encodeURIComponent(findArgs[k]));
|
||||
const urlSearchParams = new URLSearchParams();
|
||||
|
||||
if (queryString.length) {
|
||||
return `${path}${extension ? extension : ""}?${queryString.join(
|
||||
"&"
|
||||
)}`;
|
||||
for (const [key, value] of Object.entries(findArgs)) {
|
||||
if (value) {
|
||||
urlSearchParams.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
const queryString = urlSearchParams.toString();
|
||||
|
||||
if (queryString) {
|
||||
return `${path}${extension || ""}?${queryString}`;
|
||||
}
|
||||
} else {
|
||||
// It's serializable as a string if not an object
|
||||
return `${path}/${encodeURIComponent(findArgs)}${
|
||||
extension ? extension : ""
|
||||
}`;
|
||||
return `${path}/${encodeURIComponent(findArgs)}${extension || ""}`;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
|
|
Loading…
Reference in New Issue