(projectId, chartId, data, justUpdates)
| 122 | } |
| 123 | |
| 124 | export function updateChart(projectId, chartId, data, justUpdates) { |
| 125 | return (dispatch) => { |
| 126 | const formattedData = data; |
| 127 | |
| 128 | // if (data && data.startDate && data.endDate) { |
| 129 | // formattedData.startDate = moment(data.startDate).endOf("day").format(); |
| 130 | // formattedData.endDate = moment(data.endDate).endOf("day").format(); |
| 131 | // } |
| 132 | |
| 133 | const token = cookie.load("brewToken"); |
| 134 | let url = `${API_HOST}/project/${projectId}/chart/${chartId}`; |
| 135 | const method = "PUT"; |
| 136 | const body = JSON.stringify(formattedData); |
| 137 | const headers = new Headers({ |
| 138 | "Accept": "application/json", |
| 139 | "Content-Type": "application/json", |
| 140 | "authorization": `Bearer ${token}`, |
| 141 | }); |
| 142 | |
| 143 | if (justUpdates) url += "?justUpdates=true"; |
| 144 | |
| 145 | dispatch({ type: FETCH_CHART }); |
| 146 | return fetch(url, { method, body, headers }) |
| 147 | .then((response) => { |
| 148 | if (!response.ok) { |
| 149 | dispatch(addError(response.status)); |
| 150 | return new Promise((resolve, reject) => reject(response.statusText)); |
| 151 | } |
| 152 | |
| 153 | return response.json(); |
| 154 | }) |
| 155 | .then((chart) => { |
| 156 | if (justUpdates) { |
| 157 | dispatch({ type: UPDATE_CHART_FIELDS, chart }); |
| 158 | } else { |
| 159 | dispatch({ type: FETCH_CHART_SUCCESS, chart }); |
| 160 | } |
| 161 | return new Promise(resolve => resolve(chart)); |
| 162 | }) |
| 163 | .catch((error) => { |
| 164 | dispatch({ type: FETCH_CHART_FAIL }); |
| 165 | return new Promise((resolve, reject) => reject(error)); |
| 166 | }); |
| 167 | }; |
| 168 | } |
| 169 | |
| 170 | export function changeOrder(projectId, chartId, otherId) { |
| 171 | return (dispatch) => { |
no test coverage detected