(projectId, connection)
| 144 | } |
| 145 | |
| 146 | export function saveConnection(projectId, connection) { |
| 147 | return (dispatch) => { |
| 148 | if (!cookie.load("brewToken")) { |
| 149 | return new Promise((resolve, reject) => reject(new Error("No Token"))); |
| 150 | } |
| 151 | const token = cookie.load("brewToken"); |
| 152 | const url = `${API_HOST}/project/${projectId}/connection/${connection.id}`; |
| 153 | const method = "PUT"; |
| 154 | const body = JSON.stringify(connection); |
| 155 | const headers = new Headers({ |
| 156 | "Accept": "application/json", |
| 157 | "Content-Type": "application/json", |
| 158 | "authorization": `Bearer ${token}`, |
| 159 | }); |
| 160 | |
| 161 | dispatch({ type: FETCHING_CONNECTION }); |
| 162 | return fetch(url, { method, body, headers }) |
| 163 | .then((response) => { |
| 164 | if (!response.ok) { |
| 165 | dispatch(addError(response.status)); |
| 166 | throw new Error(response.status); |
| 167 | } |
| 168 | |
| 169 | return response.json(); |
| 170 | }) |
| 171 | .then((newConnection) => { |
| 172 | dispatch({ type: FETCH_CONNECTION_SUCCESS, connection: newConnection }); |
| 173 | dispatch(getProject(newConnection.project_id, true)); |
| 174 | return new Promise(resolve => resolve(newConnection)); |
| 175 | }) |
| 176 | .catch((error) => { |
| 177 | return new Promise((resolve, reject) => reject(error)); |
| 178 | }); |
| 179 | }; |
| 180 | } |
| 181 | |
| 182 | export function testConnection(projectId, id) { |
| 183 | return (dispatch) => { |
no test coverage detected