2018-05-08 23:54:40 +00:00
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
const apiRoute = '/api/'
|
|
|
|
const api = {
|
2018-05-18 23:37:03 +00:00
|
|
|
HTTPGetDocumentList: (docType) =>
|
2018-05-08 23:54:40 +00:00
|
|
|
axios.get(apiRoute + docType).then(res => {
|
2018-05-18 23:37:03 +00:00
|
|
|
return {status: 'success', docType: docType, data: res.data}
|
2018-05-08 23:54:40 +00:00
|
|
|
}).catch(error => {
|
2018-05-18 23:37:03 +00:00
|
|
|
console.log(error)
|
|
|
|
return {status: 'error', docType: docType, data: error}
|
2018-05-08 23:54:40 +00:00
|
|
|
}),
|
|
|
|
HTTPGetDocumentText: (id, docType, state) =>
|
|
|
|
axios.get(apiRoute + docType + '/' + id).then(res => {
|
|
|
|
return {id: id, status: 'success', docType: docType, state: state, data: res.data}
|
|
|
|
}).catch(error => {
|
|
|
|
return {id: id, status: 'error', docType: docType, state: state, data: error}
|
|
|
|
}),
|
|
|
|
HTTPDeleteDocument: (id, docType) =>
|
|
|
|
axios.delete(apiRoute + docType + '/' + id).then(res => {
|
|
|
|
return {id: id, status: 'success', docType: docType, data: res.data}
|
|
|
|
}).catch(error => {
|
|
|
|
return {id: id, status: 'error', docType: docType, data: error}
|
|
|
|
}),
|
|
|
|
HTTPPutCreateDocument: (docType, data) =>
|
|
|
|
axios.put(apiRoute + docType + '/', data).then(res => {
|
|
|
|
return {status: 'success', docType: docType, data: res.data}
|
|
|
|
}).catch(error => {
|
|
|
|
return {status: 'error', docType: docType, data: error}
|
|
|
|
}),
|
|
|
|
HTTPPostWriteDocument: (id, docType, data) =>
|
|
|
|
axios.post(apiRoute + docType + '/' + id, data).then(res => {
|
|
|
|
return {id: data.id, status: 'success', docType: docType, data: res.data}
|
|
|
|
}).catch(error => {
|
|
|
|
return {id: id, status: 'error', docType: docType, data: error}
|
|
|
|
}),
|
|
|
|
HTTPPostSearchResults: (data) =>
|
|
|
|
axios.post(apiRoute + 'search/', { data }).then(res => {
|
|
|
|
return {status: 'success', data: res.data}
|
|
|
|
}).catch(error => {
|
|
|
|
return {status: 'error', data: res.data}
|
2018-11-28 07:01:39 +00:00
|
|
|
}),
|
|
|
|
HTTPGetRefreshList: (docType) =>
|
|
|
|
axios.get(apiRoute + 'refresh/').then(res => {
|
|
|
|
return {status: 'success', data: res.data}
|
|
|
|
}).catch(error => {
|
|
|
|
return {status: 'error', data: error}
|
2019-08-03 02:24:24 +00:00
|
|
|
}),
|
|
|
|
HTTPGetSignedPost: () =>
|
|
|
|
axios.get(apiRoute + 'signed_post/').then(res=> {
|
|
|
|
return {status: 'success', data: res.data}
|
|
|
|
}).catch(error => {
|
|
|
|
return {status: 'error', data: error}
|
|
|
|
}),
|
|
|
|
HTTPPostMedia: (url, formData) =>
|
2019-08-10 15:28:32 +00:00
|
|
|
axios.post(url, formData, {headers: {'Content-Type': formData.get('file').type}}).then(res=> {
|
2019-08-03 02:24:24 +00:00
|
|
|
return {status: 'success', url: url + formData.get('key')}
|
|
|
|
}).catch(error => {
|
|
|
|
return {status: 'error', data: error}
|
|
|
|
})
|
2018-05-08 23:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default api
|