orderiom-api-package 0.2.55 → 0.2.56

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.55",
3
+ "version": "0.2.56",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -257,17 +257,20 @@ const actions = {
257
257
  commonErrorCallback()
258
258
  );
259
259
  },
260
- getBasket({ commit, rootState }, customRestaurantId = undefined) {
261
- const basket = JSON.parse(localStorage.getItem("basket"));
262
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
263
- basketId: basket.find((basket) => basket.restaurantId == restaurantId).basketId
264
- } : {}
260
+ getBasket({ commit, rootState }) {
261
+ let basketId = undefined;
262
+ try{
263
+ basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
264
+ } catch(e) {
265
+ console.error(e);
266
+ return false;
267
+ }
265
268
 
266
269
  commit('startFetchingBasket');
267
270
  return axios.get('api/basket', {
268
271
  params: {
269
- ...basketId,
270
- restaurantId: customRestaurantId || restaurantId
272
+ basketId,
273
+ restaurantId
271
274
  }
272
275
  }).then(res => {
273
276
  const basketInfo = res.data.data;
@@ -287,18 +290,17 @@ const actions = {
287
290
  commit('setTip', basketInfo.tip);
288
291
  commit('setshippingPrice', basketInfo.shipping_price);
289
292
 
290
- //TODO: This condition is always true.
291
- if (basketInfo.id != basketId) {
292
- const index = basket.indexOf(basket.find((basket) => basket.restaurantId == restaurantId));
293
- if (index > -1) {
294
- basket.splice(index, 1);
295
- }
296
- basket.push({
297
- restaurantId: restaurantId,
293
+ if (parseInt(basketInfo.id) !== parseInt(basketId)) {
294
+ const baskets = JSON.parse(localStorage.getItem('basket'));
295
+ const basketIndex = baskets.findIndex(basket => parseInt(basket.restaurantId) === restaurantId);
296
+ if (basketIndex > -1) baskets.splice(basketIndex, 1);
297
+ baskets.push({
298
+ restaurantId,
298
299
  basketId: basketInfo.id,
299
300
  });
300
- localStorage.setItem("basket", JSON.stringify(basket));
301
+ localStorage.setItem('basket', JSON.stringify(baskets));
301
302
  }
303
+
302
304
  commit('basketLoadedOnce');
303
305
  return true;
304
306
  }).catch(error => {