orderiom-api-package 0.2.30 → 0.2.32

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.30",
3
+ "version": "0.2.32",
4
4
  "description": "this package will install all neccessary api calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -275,8 +275,7 @@ const actions = {
275
275
  basketId: basket.find((basket) => basket.restaurantId == restaurantId).basketId
276
276
  } : {}
277
277
  return axios
278
- .get('api/basket', { params: { ...basketId, restaurantId: restaurantId } })
279
- .then((res) => {
278
+ .get('api/basket', { params: { ...basketId, restaurantId } }).then(res => {
280
279
  const basketInfo = res.data.data;
281
280
  const id = res.data.data.id;
282
281
  const ShoppingCart = res.data.data.products;
@@ -314,9 +313,11 @@ const actions = {
314
313
  localStorage.setItem("basket", JSON.stringify(basket));
315
314
 
316
315
  }
317
-
318
- })
319
- .catch((error) => console.log(error));
316
+ return true;
317
+ }).catch(error => {
318
+ console.log(error);
319
+ return false;
320
+ });
320
321
  },
321
322
  getAttributeItems({ commit }, data) {
322
323
  return axios.get('api/restaurant/category-attributes-items', {
@@ -403,6 +404,44 @@ const actions = {
403
404
 
404
405
  }
405
406
  });
407
+ },
408
+ changeDeliveryMethod({ commit, dispatch, rootState }, deliveryType){
409
+ const restaurantId = process.env.VUE_APP_RESTAURANT_ID;
410
+ let basketId = undefined;
411
+
412
+ if(!rootState.orderiomApiPackage.auth.privateToken){
413
+ // localStorage might fail
414
+ let baskets = [];
415
+ try{
416
+ baskets = JSON.parse(localStorage.getItem("basket")) || [];
417
+ }catch(e){
418
+ console.error(e);
419
+ }
420
+ const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId);
421
+ basketId = foundBasket ? foundBasket.basketId : null;
422
+ if(!basketId){
423
+ return { type: 'error', msg: 'Basket not found' }
424
+ }
425
+ }
426
+
427
+ return axios.post('api/basket/change-delivery-method', {
428
+ deliveryType,
429
+ basketId,
430
+ restaurantId: !basketId ? restaurantId : undefined
431
+ }).then(async res => {
432
+ if(res.data.message.type !== 'success'){
433
+ return { type: 'error', msg: 'Could not update delivery type' }
434
+ }
435
+
436
+ const result = await dispatch("getBasket", restaurantId);
437
+ return {
438
+ type: result ? 'success' : 'error',
439
+ msg: result ? '' : 'Could not get basket info'
440
+ }
441
+ }).catch(err => {
442
+ console.error(err);
443
+ return { type: 'error', msg: 'Could not update delivery type' }
444
+ });
406
445
  }
407
446
  };
408
447
 
@@ -290,7 +290,7 @@ const actions = {
290
290
  })
291
291
  },
292
292
  getBlogBySlug({ commit }, blogSlug) {
293
- return axios.get('api/blogs/show/' + blogSlug).then(res => {
293
+ return axios.get('api/blogs/show/slug', { params: {blogSlug}}).then(res => {
294
294
  commit('setBlog', res.data.data);
295
295
  return { type: 'success', msg: 'ok' }
296
296
  }).catch(error => {