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'); ...@@ -6,16 +6,10 @@ var get = require('lodash.get');
var retryUtil = require('./retry-util'); var retryUtil = require('./retry-util');
var urlUtil = require('./util/url-util'); var urlUtil = require('./util/url-util');
function prependTransform(defaults, transform) { /**
// We can't guarantee that the default transformation is an array * Return a shallow clone of `obj` with all client-only properties removed.
var result = angular.isArray(defaults) ? defaults.slice(0) : [defaults]; * Client-only properties are marked by a '$' prefix.
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 '_');
function stripInternalProperties(obj) { function stripInternalProperties(obj) {
var result = {}; var result = {};
...@@ -95,15 +89,11 @@ function createAPICall($http, links, route) { ...@@ -95,15 +89,11 @@ function createAPICall($http, links, route) {
var descriptor = get(links, route); var descriptor = get(links, route);
var url = urlUtil.replaceURLParams(descriptor.url, params); var url = urlUtil.replaceURLParams(descriptor.url, params);
var req = { var req = {
data: data, data: data ? stripInternalProperties(data) : null,
method: descriptor.method, method: descriptor.method,
params: url.params, params: url.params,
paramSerializer: serializeParams, paramSerializer: serializeParams,
url: url.url, url: url.url,
transformRequest: prependTransform(
$http.defaults.transformRequest,
stripInternalProperties
),
}; };
return $http(req); return $http(req);
}).then(function (result) { }).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