-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.es6
130 lines (117 loc) · 3.02 KB
/
server.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const server = (() => { // Ignore ESLintBear (no-unused-vars)
const config = {
orderCallUrl: '/shop/order-call/',
addToCartUrl: '/shop/cart-add/',
oneClickBuyUrl: '/shop/one-click-buy/',
changeCartUrl: '/shop/cart-change/',
removeFromCartUrl: '/shop/cart-remove/',
flushCartUrl: '/shop/cart-flush/',
getCartUrl: '/shop/cart-get/',
yandexOrderUrl: '/shop/yandex-order/',
setViewTypeUrl: '/set-view-type/',
saveFeedback: '/save-feedback/',
deleteFeedback: '/delete-feedback/',
};
/**
* Send information about order call.
* @param phone
* @param time
* @param url
*/
const sendOrderCall = (phone, time, url) => $.post(config.orderCallUrl, { phone, time, url });
/**
* Send Product feedback.
*/
function sendFeedback(feedback) {
return $.post({
url: config.saveFeedback,
data: {
id: feedback.id,
name: feedback.name,
dignities: feedback.dignities,
limitations: feedback.limitations,
general: feedback.general,
rating: feedback.rating,
},
});
}
const deleteFeedback = id => $.post(config.deleteFeedback, { id });
/**
* Load Products from server.
* @param {string} url
*/
const loadProducts = url => $.post(url);
/**
* Send viewType to store user's default view type.
* @param event
* @param viewType
*/
const sendViewType = (event, viewType) => $.post(config.setViewTypeUrl, { view_type: viewType });
/**
* Add product to backend's Cart.
* @param productId
* @param quantity
*/
function addToCart(productId, quantity) {
return $.post(
config.addToCartUrl,
{
product: productId,
quantity,
},
);
}
/**
* Flush (clear) the cart on backend.
*/
const flushCart = () => $.post(config.flushCartUrl);
/**
* Handle one-click-buy feature. Sends:
* @param product - id of a bought product
* @param quantity - selected quantity
* @param phone - customer's phone
*/
function oneClickBuy(product, quantity, phone) {
return $.post(config.oneClickBuyUrl, { product, quantity, phone });
}
/**
* Remove given product from Cart.
* @param productId
*/
const removeFromCart = productId => $.post(config.removeFromCartUrl, { product: productId });
/**
* Return $.post request, which changes quantity of a given Product in Cart.
* @param productId
* @param quantity - new quantity of a product
*/
function changeInCart(productId, quantity) {
return $.post(
config.changeCartUrl,
{
product: productId,
quantity,
},
);
}
/**
* Return $.get request, which gives Cart data.
*/
function getCart() {
return $.get(config.getCartUrl);
}
const sendYandexOrder = data => $.post(config.yandexOrderUrl, data);
return {
addToCart,
changeInCart,
deleteFeedback,
getCart,
loadProducts,
flushCart,
oneClickBuy,
removeFromCart,
sendFeedback,
sendOrderCall,
sendYandexOrder,
sendViewType,
};
})();