change endpoints for order details, comments and documents

This commit is contained in:
GotPPay
2018-08-14 23:31:12 +02:00
parent 04c7a7536f
commit 8b5374ee24

View File

@@ -24,7 +24,9 @@ import {
SET_SCHEDULING_DISABLED_FLAG SET_SCHEDULING_DISABLED_FLAG
} from '../../constants/ordersConstants'; } from '../../constants/ordersConstants';
import HtmlClient from '../../helpers/HtmlClient'; import HtmlClient from '../../helpers/HtmlClient';
import {updateMessages} from '../notification/notificationActions'; import { updateMessages } from '../notification/notificationActions';
import { fromWCOrder } from '../../helpers/OrderHelper';
import moment from 'moment';
const htmlClient = new HtmlClient(); const htmlClient = new HtmlClient();
@@ -42,15 +44,12 @@ export const fetchOrderInfo = (idOrder) => {
return dispatch => { return dispatch => {
dispatch(requestOrderInfo()); dispatch(requestOrderInfo());
return htmlClient.fetch({ return htmlClient.fetch({
url: `${API_SERVER}/orders/api/getOrderInfo`, url: `${API_SERVER}/wp-json/wc/v2/orders/${idOrder}`,
method: 'post', method: 'get'
data: { })
idOrder
}
})
.then(response => { .then(response => {
if (response.data) { if (response.data) {
dispatch(recieveOrderInfo(response.data)); dispatch(recieveOrderInfo(fromWCOrder(response.data)));
} }
}) })
.catch(error => { .catch(error => {
@@ -66,19 +65,34 @@ const sendComment = () => ({
export const addComment = (idOrder, comment) => { export const addComment = (idOrder, comment) => {
return dispatch => { return dispatch => {
dispatch(sendComment()); dispatch(sendComment());
//TODO: get real user name and store in comment object
return htmlClient.fetch({ return htmlClient.fetch({
url: `${API_SERVER}/orders/api/addOrderComment`, url: `${API_SERVER}/wp-json/wc/v2/orders/${idOrder}`,
method: 'post', method: 'post',
data: { data: {
idOrder, meta_data: [
comment {
} key: `comment-${moment().unix()}`,
}) value: {
comment: comment,
addDate: moment().format("Do MMM, YY"),
username: 'username',
isOwner: 1
}
}
]
}
})
.then(response => { .then(response => {
if (response.data) {
dispatch(fetchOrderInfo(idOrder));
}
/*
if (response.data && response.data.messages) { if (response.data && response.data.messages) {
dispatch(updateMessages(response.data.messages, orderMessages)); dispatch(updateMessages(response.data.messages, orderMessages));
dispatch(fetchOrderInfo(idOrder)); dispatch(fetchOrderInfo(idOrder));
} }
*/
}) })
.catch(error => { .catch(error => {
htmlClient.onError(error, dispatch); htmlClient.onError(error, dispatch);