orderiom-api-package 0.2.39 → 0.2.41

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orderiom-api-package",
3
- "version": "0.2.39",
3
+ "version": "0.2.41",
4
4
  "description": "this package will install all neccessary api calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -113,6 +113,25 @@ const mutations = {
113
113
  }
114
114
  };
115
115
  const actions = {
116
+ calculateBasketIdParameter({ rootState }){
117
+ if(rootState.orderiomApiPackage.auth.privateToken) return undefined;
118
+ // localStorage might fail
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
+ },
132
+ // TODO: note the axios in loop
133
+ // Orderiom api doesn't use this function
134
+ // check whether ordermood is using this function or not
116
135
  getCategoriesWithProducts({ commit, dispatch }, restaurantId) {
117
136
  return axios
118
137
  .get("api/restaurant/category", { params: { restaurantId: restaurantId } })
@@ -177,6 +196,8 @@ const actions = {
177
196
  .get("api/restaurant/category", { params: { restaurantId: restaurantId } })
178
197
  .then((res) => {
179
198
  let categories = res.data.data;
199
+ //TODO: why calling an api write after another while we can do it together?
200
+ //TODO: this api call returns empty on restaurant refresh
180
201
  axios
181
202
  .get("api/restaurant/category", { params: { restaurantId: restaurantId, extra: 1 } })
182
203
  .then((res) => {
@@ -230,16 +251,21 @@ const actions = {
230
251
  }
231
252
  });
232
253
  },
233
- getProducts({ commit, state }, data) {
254
+ getProducts({ commit, state, dispatch }, data) {
234
255
  commit("setSelectedCategory", data.category);
235
256
 
236
- const params = {
257
+ let basketId = undefined;
258
+ try{
259
+ basketId = dispatch('calculateBasketIdParameter');
260
+ } catch {
261
+ return { type: 'error', msg: 'Basket not found' }
262
+ }
263
+
264
+ return axios.get("api/restaurant/products", {params: {
237
265
  categoryId: data.category.id,
238
266
  restaurantId: data.restaurantId,
239
- };
240
- if(data.deliveryType) params.deliveryType = data.deliveryType;
241
-
242
- return axios.get("api/restaurant/products", { params }).then(res => {
267
+ basketId
268
+ }}).then(res => {
243
269
  let products = res.data.data;
244
270
  products.map(m => {
245
271
  if (state.ShoppingCart.find(
@@ -431,20 +457,10 @@ const actions = {
431
457
  },
432
458
  changeDeliveryMethod({ commit, dispatch, rootState }, deliveryType){
433
459
  let basketId = undefined;
434
-
435
- if(!rootState.orderiomApiPackage.auth.privateToken){
436
- // localStorage might fail
437
- let baskets = [];
438
- try{
439
- baskets = JSON.parse(localStorage.getItem("basket")) || [];
440
- }catch(e){
441
- console.error(e);
442
- }
443
- const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId);
444
- basketId = foundBasket ? foundBasket.basketId : null;
445
- if(!basketId){
446
- return { type: 'error', msg: 'Basket not found' }
447
- }
460
+ try{
461
+ basketId = dispatch('calculateBasketIdParameter');
462
+ } catch {
463
+ return { type: 'error', msg: 'Basket not found' }
448
464
  }
449
465
 
450
466
  const shoppingCartItems = rootState.orderiomApiPackage.product.ShoppingCart.length;
@@ -459,6 +475,11 @@ const actions = {
459
475
  return { type: 'error', msg: 'There was an error in updating the delivery type' }
460
476
  }
461
477
 
478
+ dispatch('getProducts', {
479
+ restaurantId,
480
+ category: state.selectedCategory || state.categories[0]
481
+ });
482
+
462
483
  const result = await dispatch("getBasket", restaurantId);
463
484
 
464
485
  return {