orderiom-api-package 0.2.41 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orderiom-api-package",
3
- "version": "0.2.41",
3
+ "version": "0.2.42",
4
4
  "description": "this package will install all neccessary api calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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,6 @@ const mutations = {
113
130
  }
114
131
  };
115
132
  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
133
  // TODO: note the axios in loop
133
134
  // Orderiom api doesn't use this function
134
135
  // check whether ordermood is using this function or not
@@ -251,13 +252,14 @@ const actions = {
251
252
  }
252
253
  });
253
254
  },
254
- getProducts({ commit, state, dispatch }, data) {
255
+ getProducts({ commit, state, rootState }, data) {
255
256
  commit("setSelectedCategory", data.category);
256
257
 
257
258
  let basketId = undefined;
258
259
  try{
259
- basketId = dispatch('calculateBasketIdParameter');
260
- } catch {
260
+ basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
261
+ } catch(e) {
262
+ console.error(e);
261
263
  return { type: 'error', msg: 'Basket not found' }
262
264
  }
263
265
 
@@ -455,11 +457,12 @@ const actions = {
455
457
  }
456
458
  });
457
459
  },
458
- changeDeliveryMethod({ commit, dispatch, rootState }, deliveryType){
460
+ changeDeliveryMethod({ commit, dispatch, rootState, state }, deliveryType){
459
461
  let basketId = undefined;
460
462
  try{
461
- basketId = dispatch('calculateBasketIdParameter');
462
- } catch {
463
+ basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
464
+ } catch(e) {
465
+ console.error(e);
463
466
  return { type: 'error', msg: 'Basket not found' }
464
467
  }
465
468