Always send region as a query param

This commit is contained in:
Michael Lange
2020-07-20 21:05:07 -07:00
parent 6bfebe2321
commit 23b024eb49

View File

@@ -49,15 +49,18 @@ export default class ApplicationAdapter extends RESTAdapter {
});
}
ajaxOptions(url, type, options = {}) {
ajaxOptions(url, verb, options = {}) {
options.data || (options.data = {});
if (this.get('system.shouldIncludeRegion')) {
// Region should only ever be a query param. The default ajaxOptions
// behavior is to include data attributes in the requestBody for PUT
// and POST requests. This works around that.
const region = this.get('system.activeRegion');
if (region) {
options.data.region = region;
url = associateRegion(url, region);
}
}
return super.ajaxOptions(url, type, options);
return super.ajaxOptions(url, verb, options);
}
// In order to remove stale records from the store, findHasMany has to unload
@@ -119,3 +122,7 @@ export default class ApplicationAdapter extends RESTAdapter {
return this.urlForFindRecord(...arguments);
}
}
function associateRegion(url, region) {
return url.indexOf('?') !== -1 ? `${url}&region=${region}` : `${url}?region=${region}`;
}