orderiom-api-package 0.3.17 → 0.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules/order.js +5 -12
- package/src/modules/product.js +19 -32
- package/src/modules/restaurant.js +5 -5
package/package.json
CHANGED
package/src/modules/order.js
CHANGED
|
@@ -50,20 +50,13 @@ const mutations = {
|
|
|
50
50
|
const actions = {
|
|
51
51
|
async shoppingCartUpdateCallback({ dispatch, rootState }, data){
|
|
52
52
|
const getBasketSuccess = await dispatch("product/getBasket", data.restaurantId, { root: true });
|
|
53
|
-
|
|
54
|
-
"product/getProducts",
|
|
55
|
-
{
|
|
56
|
-
category: rootState.orderiomApiPackage.product.selectedCategory,
|
|
57
|
-
restaurantId: data.restaurantId
|
|
58
|
-
},
|
|
59
|
-
{ root: true }
|
|
60
|
-
);
|
|
61
|
-
if(!getBasketSuccess || getProductsResult.type !== 'success'){
|
|
53
|
+
if(!getBasketSuccess){
|
|
62
54
|
return {
|
|
63
55
|
type: 'error',
|
|
64
56
|
msg: 'There was an error in fetching the basket and products'
|
|
65
57
|
}
|
|
66
58
|
}
|
|
59
|
+
|
|
67
60
|
return {
|
|
68
61
|
type: 'success',
|
|
69
62
|
msg: ''
|
|
@@ -105,11 +98,11 @@ const actions = {
|
|
|
105
98
|
.post("api/order/create-basket", data)
|
|
106
99
|
.then(async res => {
|
|
107
100
|
basketData.push({
|
|
108
|
-
restaurantId: restaurantIdEnv,
|
|
101
|
+
restaurantId: data.restaurantId || restaurantIdEnv,
|
|
109
102
|
basketId: res.data.data.basketId,
|
|
110
103
|
});
|
|
111
104
|
localStorage.setItem("basket", JSON.stringify(basketData));
|
|
112
|
-
const result = await dispatch('product/getBasket', restaurantIdEnv, { root: true }) ;
|
|
105
|
+
const result = await dispatch('product/getBasket', data.restaurantId || restaurantIdEnv, { root: true }) ;
|
|
113
106
|
return {
|
|
114
107
|
type: result ? 'success' : 'error',
|
|
115
108
|
msg: result ? 'Basket created' : 'There was an error in fetching the basket info',
|
|
@@ -728,7 +721,7 @@ const actions = {
|
|
|
728
721
|
restaurantId: data.restaurantId || restaurantIdEnv,
|
|
729
722
|
...data
|
|
730
723
|
}).then(res =>
|
|
731
|
-
updateBasket({commit, basketId, res, restaurantId: data.restaurantId})
|
|
724
|
+
updateBasket({commit, basketId, res, restaurantId: data ? data.restaurantId : undefined})
|
|
732
725
|
).catch(err => {
|
|
733
726
|
console.error(err);
|
|
734
727
|
return false;
|
package/src/modules/product.js
CHANGED
|
@@ -6,6 +6,7 @@ const state = () => ({
|
|
|
6
6
|
selectedTime: null,
|
|
7
7
|
selectedDate: null,
|
|
8
8
|
categories: [],
|
|
9
|
+
subCategoris: [],
|
|
9
10
|
selectedCategory: null,
|
|
10
11
|
products: null,
|
|
11
12
|
selectedProduct: null,
|
|
@@ -118,7 +119,10 @@ const mutations = {
|
|
|
118
119
|
},
|
|
119
120
|
basketLoadedOnce(state){
|
|
120
121
|
state.basketLoadedOnce = true;
|
|
121
|
-
}
|
|
122
|
+
},
|
|
123
|
+
setSubCategories(state , subCategoris){
|
|
124
|
+
state.subCategoris = subCategoris;
|
|
125
|
+
}
|
|
122
126
|
};
|
|
123
127
|
const actions = {
|
|
124
128
|
// TODO: note the axios in loop
|
|
@@ -215,6 +219,7 @@ const actions = {
|
|
|
215
219
|
commit("setSelectedCategory", data.category);
|
|
216
220
|
|
|
217
221
|
let basketId = undefined;
|
|
222
|
+
const subCategoris =[];
|
|
218
223
|
try{
|
|
219
224
|
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, data.restaurantId);
|
|
220
225
|
} catch(e) {
|
|
@@ -227,36 +232,18 @@ const actions = {
|
|
|
227
232
|
restaurantId: data.restaurantId,
|
|
228
233
|
basketId
|
|
229
234
|
}}).then(res => {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
state.ShoppingCart.map(b => {
|
|
243
|
-
if (b.RestaurantProductId == m.id) {
|
|
244
|
-
productsInBasket.push(
|
|
245
|
-
b.quantity
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
let qty = productsInBasket.reduce(function (a, b) {
|
|
250
|
-
return a + b;
|
|
251
|
-
}, 0);
|
|
252
|
-
Vue.set(m, 'quantity', qty)
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
Vue.set(m, 'quantity', 0)
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
|
-
commit("setProduct", products);
|
|
259
|
-
return { type: 'success', data: products }
|
|
235
|
+
res.data.data.forEach(productInCategory => {
|
|
236
|
+
if(productInCategory.subcategory_name && !state.subCategoris.includes(productInCategory.subcategory_name)){
|
|
237
|
+
subCategoris.push(productInCategory.subcategory_name)
|
|
238
|
+
}
|
|
239
|
+
productInCategory.quantity = state.ShoppingCart
|
|
240
|
+
.filter(itemInCart => Number(itemInCart.RestaurantProductId) === Number(productInCategory.id))
|
|
241
|
+
.reduce((a, b) => a.quantity + b.quantity, 0)
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
commit('setSubCategories' , subCategoris)
|
|
245
|
+
commit("setProduct", res.data.data);
|
|
246
|
+
return { type: 'success', data: res.data.data }
|
|
260
247
|
}).catch(
|
|
261
248
|
commonErrorCallback()
|
|
262
249
|
);
|
|
@@ -276,7 +263,7 @@ const actions = {
|
|
|
276
263
|
return axios.get('api/basket', {
|
|
277
264
|
params: {
|
|
278
265
|
basketId,
|
|
279
|
-
restaurantId: restaurantIdEnv
|
|
266
|
+
restaurantId: data.restaurantId || restaurantIdEnv
|
|
280
267
|
}
|
|
281
268
|
}).then(res =>
|
|
282
269
|
updateBasket({commit, basketId, res, restaurantId: data ? data.restaurantId : undefined})
|
|
@@ -145,7 +145,7 @@ const actions = {
|
|
|
145
145
|
addReservedTables({ commit }, data) {
|
|
146
146
|
return axios
|
|
147
147
|
.post("api/restaurant/reserve-table", {
|
|
148
|
-
restaurantId: restaurantIdEnv,
|
|
148
|
+
restaurantId: data.restaurantId || restaurantIdEnv,
|
|
149
149
|
people: data.people,
|
|
150
150
|
date: data.date,
|
|
151
151
|
time: data.time,
|
|
@@ -176,11 +176,11 @@ const actions = {
|
|
|
176
176
|
return commonErrorCallback()(error);
|
|
177
177
|
})
|
|
178
178
|
},
|
|
179
|
-
getBlogsByTag({ commit }, tagId) {
|
|
179
|
+
getBlogsByTag({ commit }, tagId, restaurantId = null) {
|
|
180
180
|
commit('startFetchingBlogs');
|
|
181
181
|
return axios.get('/api/blogs/by-tag', {
|
|
182
182
|
params: {
|
|
183
|
-
restaurantId: restaurantIdEnv,
|
|
183
|
+
restaurantId: restaurantId || restaurantIdEnv,
|
|
184
184
|
tagId
|
|
185
185
|
}
|
|
186
186
|
}).then(res => {
|
|
@@ -211,8 +211,8 @@ const actions = {
|
|
|
211
211
|
return commonErrorCallback()(error);
|
|
212
212
|
})
|
|
213
213
|
},
|
|
214
|
-
getBlogBySlug({ commit }, blogSlug) {
|
|
215
|
-
return axios.get('api/blogs/show/slug', { params: {blogSlug, restaurantId: restaurantIdEnv}}).then(res => {
|
|
214
|
+
getBlogBySlug({ commit }, blogSlug, restaurantId = null) {
|
|
215
|
+
return axios.get('api/blogs/show/slug', { params: {blogSlug, restaurantId: restaurantId || restaurantIdEnv}}).then(res => {
|
|
216
216
|
commit('setBlog', res.data.data);
|
|
217
217
|
return { type: 'success', msg: 'ok' }
|
|
218
218
|
}).catch(error => {
|