orderiom-api-package 0.4.24 → 0.4.26

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.4.24",
3
+ "version": "0.4.26",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -243,7 +243,7 @@ const mutations = {
243
243
  }
244
244
  };
245
245
  const actions = {
246
- getCategories({ commit, dispatch, rootState }, restaurantId) {
246
+ getCategories({ commit, dispatch, rootState, state }, restaurantId) {
247
247
  let basketId = undefined;
248
248
  try {
249
249
  basketId = calculateBasketIdParameter(
@@ -264,25 +264,45 @@ const actions = {
264
264
  if (res.data.data.length) {
265
265
  categories = [...categories, ...res.data.data];
266
266
  commit('setCategories', categories);
267
- commit("setSelectedCategory", categories[0]);
267
+ if(categories.length){
268
+ if(!state.selectedCategory) {
269
+ commit("setSelectedCategory", categories[0]);
270
+ }else{
271
+ const catInList = categories.find(cat => cat.id === state.selectedCategory.id);
272
+ if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){
273
+ commit("setSelectedCategory", categories[0]);
274
+ }
275
+ }
276
+ }
277
+
268
278
  dispatch("getProducts", {
269
- category: categories[0],
270
- restaurantId: restaurantId,
279
+ category: state.selectedCategory,
280
+ restaurantId,
271
281
  });
272
282
  dispatch("getAttributeItems", {
273
- category: categories[0],
274
- restaurantId: restaurantId
283
+ category: state.selectedCategory,
284
+ restaurantId
275
285
  });
276
286
  } else {
277
287
  commit('setCategories', categories);
278
- commit("setSelectedCategory", categories[0]);
288
+ if(categories.length){
289
+ if(!state.selectedCategory) {
290
+ commit("setSelectedCategory", categories[0]);
291
+ }else{
292
+ const catInList = categories.find(cat => cat.id === state.selectedCategory.id);
293
+ if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){
294
+ commit("setSelectedCategory", categories[0]);
295
+ }
296
+ }
297
+ }
298
+
279
299
  dispatch("getProducts", {
280
- category: categories[0],
281
- restaurantId: restaurantId,
300
+ category: state.selectedCategory,
301
+ restaurantId,
282
302
  });
283
303
  dispatch("getAttributeItems", {
284
- category: categories[0],
285
- restaurantId: restaurantId
304
+ category: state.selectedCategory,
305
+ restaurantId
286
306
  });
287
307
  }
288
308
  });