mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
WIP
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
import axios from 'axios';
|
||||
import axios from 'services/axios';
|
||||
|
||||
export default {
|
||||
|
||||
get(resource, params) {
|
||||
return axios.get(`api/${resource}`, params);
|
||||
return axios.get(`/api/${resource}`, params);
|
||||
},
|
||||
|
||||
post(resource, params) {
|
||||
return axios.post(`api/${resource}`, params);
|
||||
return axios.post(`/api/${resource}`, params);
|
||||
},
|
||||
|
||||
update(resource, slug, params) {
|
||||
return axios.put(`api/${resource}/${slug}`, params);
|
||||
return axios.put(`/api/${resource}/${slug}`, params);
|
||||
},
|
||||
|
||||
put(resource, params) {
|
||||
return axios.put(`api/${resource}`, params);
|
||||
return axios.put(`/api/${resource}`, params);
|
||||
},
|
||||
|
||||
delete(resource, params) {
|
||||
return axios.delete(`api/${resource}`, params);
|
||||
return axios.delete(`/api/${resource}`, params);
|
||||
}
|
||||
};
|
||||
|
||||
3
client/src/services/NamedRoutes.js
Normal file
3
client/src/services/NamedRoutes.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import dashboard from 'routes/dashboard';
|
||||
|
||||
|
||||
29
client/src/services/RemoteDataBinding.js
Normal file
29
client/src/services/RemoteDataBinding.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import ApiService from 'services/ApiService';
|
||||
|
||||
export default class RemoteDataBinding {
|
||||
|
||||
execute(state) {
|
||||
return this.getData(state);
|
||||
}
|
||||
|
||||
getData(state) {
|
||||
const pageQuery = `$skip=${state.skip}&$top=${state.take}`;
|
||||
let sortQuery = '';
|
||||
|
||||
if ((state.sorted || []).length) {
|
||||
sortQuery = `&$orderby=` + (state).sorted.map((obj) => {
|
||||
return obj.direction === 'descending' ? `${obj.name} desc` : obj.name;
|
||||
}).reverse().join(',');
|
||||
}
|
||||
|
||||
this.ajax.url = `${this.baseUrl}?${pageQuery}${sortQuery}&$inlinecount=allpages&$format=json`;
|
||||
|
||||
return ApiService.get(this.ajax.url).then((response) => {
|
||||
let data = JSON.parse(response);
|
||||
return {
|
||||
result: data['d']['results'],
|
||||
count: parseInt(data['d']['__count'], 10),
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
34
client/src/services/axios.js
Normal file
34
client/src/services/axios.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import axios from 'axios';
|
||||
import store from 'store/createStore';
|
||||
|
||||
const http = axios.create();
|
||||
|
||||
http.interceptors.request.use((request) => {
|
||||
const state = store.getState();
|
||||
const token = state.authentication.token;
|
||||
const locale = 'en';
|
||||
|
||||
if (token) {
|
||||
request.headers.common['x-access-token'] = token;
|
||||
}
|
||||
if (locale) {
|
||||
request.headers.common['Accept-Language'] = locale;
|
||||
}
|
||||
return request;
|
||||
}, (error) => {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
http.interceptors.response.use((response) => response, (error) => {
|
||||
const { status } = error.response;
|
||||
|
||||
if (status >= 500) {
|
||||
|
||||
}
|
||||
if (status === 401) {
|
||||
|
||||
}
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
export default http;
|
||||
Reference in New Issue
Block a user