orderiom-api-package
Advanced tools
Comparing version 0.2.39 to 0.2.40
{ | ||
"name": "orderiom-api-package", | ||
"version": "0.2.39", | ||
"version": "0.2.40", | ||
"description": "this package will install all neccessary api calls for every orderiom restaurant", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -116,2 +116,18 @@ import axios from "axios"; | ||
const actions = { | ||
calculateBasketIdParameter({ rootState }){ | ||
if(rootState.orderiomApiPackage.auth.privateToken) return undefined; | ||
// localStorage might fail | ||
let baskets = []; | ||
try{ | ||
baskets = JSON.parse(localStorage.getItem("basket")) || []; | ||
}catch(e){ | ||
console.error(e); | ||
throw new Error('Basket not found'); | ||
} | ||
const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId); | ||
if(!foundBasket){ | ||
throw new Error('Basket not found'); | ||
} | ||
return foundBasket.basketId; | ||
}, | ||
getCategoriesWithProducts({ commit, dispatch }, restaurantId) { | ||
@@ -234,12 +250,17 @@ return axios | ||
}, | ||
getProducts({ commit, state }, data) { | ||
getProducts({ commit, state, dispatch }, data) { | ||
commit("setSelectedCategory", data.category); | ||
const params = { | ||
let basketId = undefined; | ||
try{ | ||
basketId = dispatch('calculateBasketIdParameter'); | ||
} catch { | ||
return { type: 'error', msg: 'Basket not found' } | ||
} | ||
return axios.get("api/restaurant/products", {params: { | ||
categoryId: data.category.id, | ||
restaurantId: data.restaurantId, | ||
}; | ||
if(data.deliveryType) params.deliveryType = data.deliveryType; | ||
return axios.get("api/restaurant/products", { params }).then(res => { | ||
basketId | ||
}}).then(res => { | ||
let products = res.data.data; | ||
@@ -436,16 +457,6 @@ products.map(m => { | ||
let basketId = undefined; | ||
if(!rootState.orderiomApiPackage.auth.privateToken){ | ||
// localStorage might fail | ||
let baskets = []; | ||
try{ | ||
baskets = JSON.parse(localStorage.getItem("basket")) || []; | ||
}catch(e){ | ||
console.error(e); | ||
} | ||
const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId); | ||
basketId = foundBasket ? foundBasket.basketId : null; | ||
if(!basketId){ | ||
return { type: 'error', msg: 'Basket not found' } | ||
} | ||
try{ | ||
basketId = dispatch('calculateBasketIdParameter'); | ||
} catch { | ||
return { type: 'error', msg: 'Basket not found' } | ||
} | ||
@@ -452,0 +463,0 @@ |
126151
2856