29 lines
731 B
JavaScript
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
|
|
};
|
|
}
|