2020-05-07 07:56:37 +00:00
|
|
|
import {
|
|
|
|
|
HTTP_METHODS,
|
|
|
|
|
POST_BODY_FORMAT_OPTIONS,
|
|
|
|
|
} from "constants/ApiEditorConstants";
|
2019-12-23 12:12:58 +00:00
|
|
|
|
2020-05-07 10:42:17 +00:00
|
|
|
export const transformRestAction = (data: any, extraFormData?: any): any => {
|
2019-12-23 12:12:58 +00:00
|
|
|
let action = { ...data };
|
2020-05-07 07:56:37 +00:00
|
|
|
if (data.actionConfiguration.httpMethod === HTTP_METHODS[0]) {
|
|
|
|
|
delete action.actionConfiguration.body;
|
|
|
|
|
}
|
2020-01-08 09:19:00 +00:00
|
|
|
if (
|
|
|
|
|
data.actionConfiguration.queryParameters &&
|
|
|
|
|
data.actionConfiguration.queryParameters.length
|
|
|
|
|
) {
|
2019-12-23 12:12:58 +00:00
|
|
|
const path = data.actionConfiguration.path;
|
|
|
|
|
if (path && path.indexOf("?") > -1) {
|
|
|
|
|
action = {
|
|
|
|
|
...data,
|
|
|
|
|
actionConfiguration: {
|
|
|
|
|
...data.actionConfiguration,
|
|
|
|
|
path: path.substr(0, path.indexOf("?")),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-07 07:56:37 +00:00
|
|
|
|
2020-05-07 10:42:17 +00:00
|
|
|
if (extraFormData && extraFormData?.displayFormat) {
|
|
|
|
|
const { displayFormat } = extraFormData;
|
2020-05-07 07:56:37 +00:00
|
|
|
|
2020-05-07 10:42:17 +00:00
|
|
|
if (displayFormat.value === POST_BODY_FORMAT_OPTIONS[0].value) {
|
2020-05-07 07:56:37 +00:00
|
|
|
if (data.actionConfiguration.body && data.actionConfiguration.body[0]) {
|
|
|
|
|
const body = data.actionConfiguration.body[0];
|
2020-04-14 12:34:14 +00:00
|
|
|
action = {
|
|
|
|
|
...data,
|
|
|
|
|
actionConfiguration: {
|
|
|
|
|
...data.actionConfiguration,
|
2020-05-07 07:56:37 +00:00
|
|
|
body,
|
2020-04-14 12:34:14 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-05-07 10:42:17 +00:00
|
|
|
} else if (displayFormat.value === POST_BODY_FORMAT_OPTIONS[1].value) {
|
2020-05-07 07:56:37 +00:00
|
|
|
if (data.actionConfiguration.body && data.actionConfiguration.body[1]) {
|
|
|
|
|
const body = data.actionConfiguration.body[1];
|
|
|
|
|
if (typeof data.actionConfiguration.body === "object") {
|
|
|
|
|
action = {
|
|
|
|
|
...data,
|
|
|
|
|
actionConfiguration: {
|
|
|
|
|
...data.actionConfiguration,
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-07 10:42:17 +00:00
|
|
|
} else if (displayFormat.value === POST_BODY_FORMAT_OPTIONS[2].value) {
|
|
|
|
|
if (data.actionConfiguration.body && data.actionConfiguration.body[2]) {
|
|
|
|
|
const body = data.actionConfiguration.body[2];
|
|
|
|
|
action = {
|
|
|
|
|
...data,
|
|
|
|
|
actionConfiguration: {
|
|
|
|
|
...data.actionConfiguration,
|
|
|
|
|
body,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-05-07 07:56:37 +00:00
|
|
|
}
|
2020-04-14 12:34:14 +00:00
|
|
|
}
|
2019-12-23 12:12:58 +00:00
|
|
|
return action;
|
|
|
|
|
};
|