orderiom-api-package
Advanced tools
Comparing version 0.4.61 to 0.4.62
{ | ||
"name": "orderiom-api-package", | ||
"version": "0.4.61", | ||
"version": "0.4.62", | ||
"description": "This package will install all necessary API calls for every orderiom restaurant", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -264,2 +264,7 @@ import {commonErrorCallback, calculateBasketIdParameter, updateBasket, formatDate, formatTime, deliveryCodeToName, weekdays, $http} from '../common'; | ||
const actions = { | ||
chooseCategory({commit, dispatch, state}, {category, restaurantId}){ | ||
commit("setSelectedCategory", category); | ||
dispatch("getProducts", {category, restaurantId,}); | ||
dispatch("getAttributeItems", {category, restaurantId}); | ||
}, | ||
getCategories({ commit, dispatch, rootState, state }, restaurantId) { | ||
@@ -274,61 +279,44 @@ let basketId = undefined; | ||
} | ||
return $http | ||
.get("api/restaurant/category", { params: { restaurantId: restaurantId, basketId: basketId } }) | ||
.then((res) => { | ||
let categories = res.data.data; | ||
//TODO: why calling an api write after another while we can do it together? | ||
//TODO: this api call returns empty on restaurant refresh | ||
$http | ||
.get("api/restaurant/category", { params: { restaurantId: restaurantId, extra: 1, basketId: basketId } }) | ||
.then((res) => { | ||
if (res.data.data.length) { | ||
categories = [...categories, ...res.data.data]; | ||
commit('setCategories', categories); | ||
if(categories.length){ | ||
if(!state.selectedCategory) { | ||
commit("setSelectedCategory", categories[0]); | ||
}else{ | ||
const catInList = categories.find(cat => cat.id === state.selectedCategory.id); | ||
if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){ | ||
commit("setSelectedCategory", categories[0]); | ||
} | ||
} | ||
} | ||
dispatch("getProducts", { | ||
category: state.selectedCategory, | ||
restaurantId, | ||
}); | ||
dispatch("getAttributeItems", { | ||
category: state.selectedCategory, | ||
restaurantId | ||
}); | ||
} else { | ||
commit('setCategories', categories); | ||
if(categories.length){ | ||
if(!state.selectedCategory) { | ||
commit("setSelectedCategory", categories[0]); | ||
}else{ | ||
const catInList = categories.find(cat => cat.id === state.selectedCategory.id); | ||
if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){ | ||
commit("setSelectedCategory", categories[0]); | ||
} | ||
} | ||
} | ||
return $http.get("api/restaurant/category", { params: { | ||
restaurantId, | ||
basketId | ||
}}).then(res => { | ||
let categories = res.data.data; | ||
dispatch("getProducts", { | ||
category: state.selectedCategory, | ||
restaurantId, | ||
}); | ||
dispatch("getAttributeItems", { | ||
category: state.selectedCategory, | ||
restaurantId | ||
}); | ||
} | ||
}); | ||
return res | ||
}) | ||
.catch( | ||
commonErrorCallback() | ||
); | ||
$http.get("api/restaurant/category", { params: { | ||
restaurantId, | ||
basketId, | ||
extra: 1, | ||
}}).then(res => { | ||
const extraCategories = res.data.data; | ||
if (extraCategories.length) commit('setCategories', [...categories, ...extraCategories]); | ||
else commit('setCategories', categories); | ||
if(state.categories.length){ | ||
if(!state.selectedCategory) { | ||
dispatch('chooseCategory', { | ||
category: state.categories[0], | ||
restaurantId | ||
}) | ||
}else{ | ||
// if selected category is set then check if it is the same category. If it is the same then there is no need to do anything. | ||
const catInList = categories.find(cat => cat.id === state.selectedCategory.id); | ||
if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){ | ||
dispatch('chooseCategory', { | ||
category: state.categories[0], | ||
restaurantId | ||
}) | ||
} | ||
} | ||
} | ||
}).catch( | ||
commonErrorCallback() | ||
); | ||
return res | ||
}).catch( | ||
commonErrorCallback() | ||
); | ||
}, | ||
@@ -335,0 +323,0 @@ getProducts({ commit, state, rootState }, data) { |
126809
3180