This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/actions/buildAsyncAction.js

29 lines
731 B
JavaScript

import { CALL_API } from 'redux-api-middleware';
import _ from 'underscore';
export default function buildRsaAction(actionSet, path, method, optionalData, meta) {
const types = _.map([actionSet.REQUEST, actionSet.SUCCESS, actionSet.FAILURE], (requestType) => {
if (meta) {
return { type: requestType, meta: _.clone(meta) };
}
return { type: requestType };
});
let actionData = {
types: types,
endpoint: path,
method,
headers: {
'Accept': 'application/json'
},
};
if (optionalData && !_.isEmpty(optionalData)) {
actionData.headers['Content-Type'] = 'application/json';
actionData.body = JSON.stringify(optionalData);
}
return {
[CALL_API]: actionData
};
}