orderiom-api-package 0.2.40 → 0.2.42
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/product.js +35 -22
package/package.json
CHANGED
package/src/modules/product.js
CHANGED
|
@@ -3,6 +3,23 @@ import Vue from 'vue';
|
|
|
3
3
|
|
|
4
4
|
const restaurantId = process.env.VUE_APP_RESTAURANT_ID;
|
|
5
5
|
|
|
6
|
+
function calculateBasketIdParameter(isLogin) {
|
|
7
|
+
if(isLogin) return undefined;
|
|
8
|
+
// localStorage might fail
|
|
9
|
+
let baskets = [];
|
|
10
|
+
try{
|
|
11
|
+
baskets = JSON.parse(localStorage.getItem("basket")) || [];
|
|
12
|
+
}catch(e){
|
|
13
|
+
console.error(e);
|
|
14
|
+
throw new Error('Basket not found');
|
|
15
|
+
}
|
|
16
|
+
const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId);
|
|
17
|
+
if(!foundBasket){
|
|
18
|
+
throw new Error('Basket not found');
|
|
19
|
+
}
|
|
20
|
+
return foundBasket.basketId;
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
const state = () => ({
|
|
7
24
|
selectedTime: null,
|
|
8
25
|
selectedDate: null,
|
|
@@ -113,22 +130,9 @@ const mutations = {
|
|
|
113
130
|
}
|
|
114
131
|
};
|
|
115
132
|
const actions = {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
let baskets = [];
|
|
120
|
-
try{
|
|
121
|
-
baskets = JSON.parse(localStorage.getItem("basket")) || [];
|
|
122
|
-
}catch(e){
|
|
123
|
-
console.error(e);
|
|
124
|
-
throw new Error('Basket not found');
|
|
125
|
-
}
|
|
126
|
-
const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId);
|
|
127
|
-
if(!foundBasket){
|
|
128
|
-
throw new Error('Basket not found');
|
|
129
|
-
}
|
|
130
|
-
return foundBasket.basketId;
|
|
131
|
-
},
|
|
133
|
+
// TODO: note the axios in loop
|
|
134
|
+
// Orderiom api doesn't use this function
|
|
135
|
+
// check whether ordermood is using this function or not
|
|
132
136
|
getCategoriesWithProducts({ commit, dispatch }, restaurantId) {
|
|
133
137
|
return axios
|
|
134
138
|
.get("api/restaurant/category", { params: { restaurantId: restaurantId } })
|
|
@@ -193,6 +197,8 @@ const actions = {
|
|
|
193
197
|
.get("api/restaurant/category", { params: { restaurantId: restaurantId } })
|
|
194
198
|
.then((res) => {
|
|
195
199
|
let categories = res.data.data;
|
|
200
|
+
//TODO: why calling an api write after another while we can do it together?
|
|
201
|
+
//TODO: this api call returns empty on restaurant refresh
|
|
196
202
|
axios
|
|
197
203
|
.get("api/restaurant/category", { params: { restaurantId: restaurantId, extra: 1 } })
|
|
198
204
|
.then((res) => {
|
|
@@ -246,13 +252,14 @@ const actions = {
|
|
|
246
252
|
}
|
|
247
253
|
});
|
|
248
254
|
},
|
|
249
|
-
getProducts({ commit, state,
|
|
255
|
+
getProducts({ commit, state, rootState }, data) {
|
|
250
256
|
commit("setSelectedCategory", data.category);
|
|
251
257
|
|
|
252
258
|
let basketId = undefined;
|
|
253
259
|
try{
|
|
254
|
-
basketId =
|
|
255
|
-
} catch {
|
|
260
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
261
|
+
} catch(e) {
|
|
262
|
+
console.error(e);
|
|
256
263
|
return { type: 'error', msg: 'Basket not found' }
|
|
257
264
|
}
|
|
258
265
|
|
|
@@ -450,11 +457,12 @@ const actions = {
|
|
|
450
457
|
}
|
|
451
458
|
});
|
|
452
459
|
},
|
|
453
|
-
changeDeliveryMethod({ commit, dispatch, rootState }, deliveryType){
|
|
460
|
+
changeDeliveryMethod({ commit, dispatch, rootState, state }, deliveryType){
|
|
454
461
|
let basketId = undefined;
|
|
455
462
|
try{
|
|
456
|
-
basketId =
|
|
457
|
-
} catch {
|
|
463
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
464
|
+
} catch(e) {
|
|
465
|
+
console.error(e);
|
|
458
466
|
return { type: 'error', msg: 'Basket not found' }
|
|
459
467
|
}
|
|
460
468
|
|
|
@@ -470,6 +478,11 @@ const actions = {
|
|
|
470
478
|
return { type: 'error', msg: 'There was an error in updating the delivery type' }
|
|
471
479
|
}
|
|
472
480
|
|
|
481
|
+
dispatch('getProducts', {
|
|
482
|
+
restaurantId,
|
|
483
|
+
category: state.selectedCategory || state.categories[0]
|
|
484
|
+
});
|
|
485
|
+
|
|
473
486
|
const result = await dispatch("getBasket", restaurantId);
|
|
474
487
|
|
|
475
488
|
return {
|