(projectId, data)
| 89 | } |
| 90 | |
| 91 | export function createChart(projectId, data) { |
| 92 | return (dispatch) => { |
| 93 | const token = cookie.load("brewToken"); |
| 94 | const url = `${API_HOST}/project/${projectId}/chart`; |
| 95 | const method = "POST"; |
| 96 | const body = JSON.stringify(data); |
| 97 | const headers = new Headers({ |
| 98 | "Accept": "application/json", |
| 99 | "Content-Type": "application/json", |
| 100 | "authorization": `Bearer ${token}`, |
| 101 | }); |
| 102 | |
| 103 | dispatch({ type: FETCH_CHART }); |
| 104 | return fetch(url, { method, body, headers }) |
| 105 | .then((response) => { |
| 106 | if (!response.ok) { |
| 107 | dispatch(addError(response.status)); |
| 108 | return new Promise((resolve, reject) => reject(response.statusText)); |
| 109 | } |
| 110 | |
| 111 | return response.json(); |
| 112 | }) |
| 113 | .then((chart) => { |
| 114 | dispatch({ type: FETCH_CHART_SUCCESS, chart }); |
| 115 | return new Promise(resolve => resolve(chart)); |
| 116 | }) |
| 117 | .catch((error) => { |
| 118 | dispatch({ type: FETCH_CHART_FAIL }); |
| 119 | return new Promise((resolve, reject) => reject(error)); |
| 120 | }); |
| 121 | }; |
| 122 | } |
| 123 | |
| 124 | export function updateChart(projectId, chartId, data, justUpdates) { |
| 125 | return (dispatch) => { |
no test coverage detected