Commit dea5bf72 authored by Robert Knight's avatar Robert Knight

Simplify stripping of client-only properties in createAPICall()

Rather than using a $http request transform to preprocess the data,
just pass the data object into the `stripInternalProperties` function
directly.
parent 41904b1b
......@@ -6,16 +6,10 @@ var get = require('lodash.get');
var retryUtil = require('./retry-util');
var urlUtil = require('./util/url-util');
function prependTransform(defaults, transform) {
// We can't guarantee that the default transformation is an array
var result = angular.isArray(defaults) ? defaults.slice(0) : [defaults];
result.unshift(transform);
return result;
}
// stripInternalProperties returns a shallow clone of `obj`, lacking all
// properties that begin with a character that marks them as internal
// (currently '$' or '_');
/**
* Return a shallow clone of `obj` with all client-only properties removed.
* Client-only properties are marked by a '$' prefix.
*/
function stripInternalProperties(obj) {
var result = {};
......@@ -95,15 +89,11 @@ function createAPICall($http, links, route) {
var descriptor = get(links, route);
var url = urlUtil.replaceURLParams(descriptor.url, params);
var req = {
data: data,
data: data ? stripInternalProperties(data) : null,
method: descriptor.method,
params: url.params,
paramSerializer: serializeParams,
url: url.url,
transformRequest: prependTransform(
$http.defaults.transformRequest,
stripInternalProperties
),
};
return $http(req);
}).then(function (result) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment