ManageIQ/manageiq-ui-classic

View on GitHub
app/javascript/oldjs/services/post_service.js

Summary

Maintainability
A
35 mins
Test Coverage
/* global miqFlashLater */
 
ManageIQ.angular.app.service('postService', ['miqService', '$window', 'API', function(miqService, $window, API) {
this.saveRecord = function(apiURL, redirectURL, object, successMsg) {
return saveRecord(apiURL, redirectURL, object, successMsg, 'edit');
};
 
this.createRecord = function(apiURL, redirectURL, object, successMsg) {
return saveRecord(apiURL, redirectURL, object, successMsg, 'create');
};
 
this.cancelOperation = function(redirectURL, msg) {
miqFlashLater({ message: msg });
$window.location.href = redirectURL;
};
 
 
Function `saveRecord` has 5 arguments (exceeds 4 allowed). Consider refactoring.
function saveRecord(apiURL, redirectURL, object, successMsg, action) {
miqService.sparkleOn();
 
return API.post(apiURL, angular.toJson({
Expected property shorthand.
action: action,
resource: object,
}), {
skipErrors: [400],
})
.then(handleErrors)
.then(handleSuccess(successMsg, redirectURL))
.catch(miqService.handleFailure);
}
 
Expected to return a value at the end of function 'handleErrors'.
function handleErrors(response) {
if (response.error) {
// flash & sparkleOff handled by miqService.handleFailure
Expected the Promise rejection reason to be an Error.
return Promise.reject({
Unexpected string concatenation.
message: __(response.error.klass) + ': ' + __(response.error.message),
});
}
}
 
function handleSuccess(message, url) {
return function() {
Expected property shorthand.
miqFlashLater({ message: message });
$window.location.href = url;
};
}
}]);