orderiom-api-package 0.2.39 → 0.2.40

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.40",
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,22 @@ 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
+ },
116
132
  getCategoriesWithProducts({ commit, dispatch }, restaurantId) {
117
133
  return axios
118
134
  .get("api/restaurant/category", { params: { restaurantId: restaurantId } })
@@ -230,16 +246,21 @@ const actions = {
230
246
  }
231
247
  });
232
248
  },
233
- getProducts({ commit, state }, data) {
249
+ getProducts({ commit, state, dispatch }, data) {
234
250
  commit("setSelectedCategory", data.category);
235
251
 
236
- const params = {
252
+ let basketId = undefined;
253
+ try{
254
+ basketId = dispatch('calculateBasketIdParameter');
255
+ } catch {
256
+ return { type: 'error', msg: 'Basket not found' }
257
+ }
258
+
259
+ return axios.get("api/restaurant/products", {params: {
237
260
  categoryId: data.category.id,
238
261
  restaurantId: data.restaurantId,
239
- };
240
- if(data.deliveryType) params.deliveryType = data.deliveryType;
241
-
242
- return axios.get("api/restaurant/products", { params }).then(res => {
262
+ basketId
263
+ }}).then(res => {
243
264
  let products = res.data.data;
244
265
  products.map(m => {
245
266
  if (state.ShoppingCart.find(
@@ -431,20 +452,10 @@ const actions = {
431
452
  },
432
453
  changeDeliveryMethod({ commit, dispatch, rootState }, deliveryType){
433
454
  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
- }
455
+ try{
456
+ basketId = dispatch('calculateBasketIdParameter');
457
+ } catch {
458
+ return { type: 'error', msg: 'Basket not found' }
448
459
  }
449
460
 
450
461
  const shoppingCartItems = rootState.orderiomApiPackage.product.ShoppingCart.length;