orderiom-api-package 0.2.50 → 0.2.52

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.
@@ -1,23 +1,5 @@
1
1
  import axios from "axios";
2
-
3
- const restaurantId = process.env.VUE_APP_RESTAURANT_ID;
4
-
5
- function calculateBasketIdParameter(isLogin) {
6
- if(isLogin) return undefined;
7
- // localStorage might fail
8
- let baskets = [];
9
- try{
10
- baskets = JSON.parse(localStorage.getItem("basket")) || [];
11
- }catch(e){
12
- console.error(e);
13
- throw new Error('Basket not found');
14
- }
15
- const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId);
16
- if(!foundBasket){
17
- throw new Error('Basket not found');
18
- }
19
- return foundBasket.basketId;
20
- }
2
+ import { commonErrorCallback, calculateBasketIdParameter, restaurantId } from '../common';
21
3
 
22
4
  const state = () => ({
23
5
  productOrder: null,
@@ -66,6 +48,27 @@ const mutations = {
66
48
 
67
49
  }
68
50
  const actions = {
51
+ async shoppingCartUpdateCallback({ dispatch, rootState }, data){
52
+ const getBasketSuccess = await dispatch("product/getBasket", data.restaurantId, { root: true });
53
+ const getProductsResult = await dispatch(
54
+ "product/getProducts",
55
+ {
56
+ category: rootState.orderiomApiPackage.product.selectedCategory,
57
+ restaurantId: data.restaurantId
58
+ },
59
+ { root: true }
60
+ );
61
+ if(!getBasketSuccess || getProductsResult.type !== 'success'){
62
+ return {
63
+ type: 'error',
64
+ msg: 'There was an error in fetching basket and products'
65
+ }
66
+ }
67
+ return {
68
+ type: 'success',
69
+ msg: ''
70
+ }
71
+ },
69
72
  createBasket({ }, data) {
70
73
  var basketData = JSON.parse(localStorage.getItem("basket") || "[]");
71
74
  let delivery_time = data.delivery_time ? { delivery_time: data.delivery_time } : null
@@ -92,26 +95,9 @@ const actions = {
92
95
  // localStorage.setItem("basketId", res.data.id);
93
96
  return true;
94
97
  })
95
- .catch((error) => {
96
- if (error.response) {
97
- if (error.response.status == 422) {
98
- return {
99
- type: 'error',
100
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
101
-
102
- }
103
- }
104
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
105
-
106
- return {
107
- type: 'error',
108
- msg: error.response.data.message.body
109
-
110
- }
111
- }
112
-
113
- }
114
- });
98
+ .catch(
99
+ commonErrorCallback()
100
+ );
115
101
  },
116
102
  createBasketFromOrder({ dispatch }, data) {
117
103
  const basketData = JSON.parse(localStorage.getItem("basket") || "[]");
@@ -129,31 +115,9 @@ const actions = {
129
115
  msg: result ? 'Basket created' : 'There was an error in fetching the basket info',
130
116
  }
131
117
  })
132
- .catch((error) => {
133
- if(!error.response){
134
- return {
135
- type: 'error',
136
- msg: 'There was an error in creating basket',
137
- }
138
- }
139
- const status = error.response.status;
140
- if (status === 422) {
141
- return {
142
- type: 'error',
143
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
144
- }
145
- }
146
- if ([401, 403, 404, 400].includes(status)) {
147
- return {
148
- type: 'error',
149
- msg: error.response.data.message.body
150
- }
151
- }
152
- return {
153
- type:'error',
154
- msg:'There was an error in creating basket'
155
- }
156
- });
118
+ .catch(
119
+ commonErrorCallback('There was an error in creating basket')
120
+ );
157
121
  },
158
122
  setTable({ rootState }, data) {
159
123
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -181,173 +145,101 @@ const actions = {
181
145
  type: 'success',
182
146
  msg: 'ok'
183
147
  }
184
- }).catch((error) => {
185
- if (error.response) {
186
- if (error.response.status == 422) {
187
- return {
188
- type: 'error',
189
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
190
-
191
- }
192
- }
193
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
194
-
195
- return {
196
- type: 'error',
197
- msg: error.response.data.message.body
198
-
199
- }
200
- }
201
-
202
- }
203
- });
148
+ }).catch(
149
+ commonErrorCallback()
150
+ );
204
151
  },
205
152
  addToBasket({ dispatch, rootState }, data) {
153
+ // might be null
154
+ const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
155
+ f.RestaurantProductId === Number(data.productId)
156
+ );
157
+
206
158
  const basket = JSON.parse(localStorage.getItem("basket"));
207
159
  const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
208
160
  basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
209
161
  } : {}
210
162
  const attributeItems = data.attributeItems.length ? { attributeItems: data.attributeItems } : {}
211
- axios
212
- .post("api/basket/add", {
213
- ...basketId,
214
- productId: data.productId,
215
- quantity: 1,
216
- ...attributeItems,
217
- restaurantId: data.restaurantId,
218
- })
219
- .then(() => {
220
- dispatch("product/getBasket", data.restaurantId, { root: true }).then(() => {
221
-
222
- dispatch(
223
- "product/getProducts",
224
- { category: rootState.orderiomApiPackage.product.selectedCategory, restaurantId: data.restaurantId }, { root: true }
225
- );
226
- });
227
-
228
- // dispatch(
229
- // "product/getAttributeItems",
230
- // rootState.orderiomApiPackage.product.selectedCategory, { root: true }
231
- // );
232
- })
233
- .catch((error) => {
234
- // dispatch('createBasket')
235
- if (error.response) {
236
- if (error.response.status == 422) {
237
- return {
238
- type: 'error',
239
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
240
-
241
- }
242
- }
243
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
244
163
 
245
- return {
246
- type: 'error',
247
- msg: error.response.data.message.body
248
-
249
- }
250
- }
251
-
252
- }
253
- });
164
+ if(basketProduct) basketProduct.changingQuantity = true;
165
+ axios.post("api/basket/add", {
166
+ ...basketId,
167
+ productId: data.productId,
168
+ quantity: 1,
169
+ ...attributeItems,
170
+ restaurantId: data.restaurantId,
171
+ }).then(async () => {
172
+ return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
173
+ }).catch(
174
+ commonErrorCallback()
175
+ ).finally(() => {
176
+ if(basketProduct) basketProduct.changingQuantity = false;
177
+ });
254
178
  },
255
179
  removeFromBasket({ dispatch, rootState }, data) {
256
- let item = rootState.orderiomApiPackage.product.ShoppingCart.find(
257
- (f) => f.RestaurantProductId == data.productId
180
+ const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
181
+ f.RestaurantProductId === Number(data.productId)
258
182
  );
183
+
184
+ if(!basketProduct){
185
+ return {
186
+ type: 'error',
187
+ msg: 'Product not found'
188
+ }
189
+ }
190
+
259
191
  const basket = JSON.parse(localStorage.getItem("basket"));
260
192
  const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
261
193
  basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
262
194
  } : {}
263
- axios
264
- .get("api/basket/remove", {
265
- params: {
266
- ...basketId,
267
- basketProductId: item.basketProductId,
268
- restaurantId: data.restaurantId,
269
- },
270
- })
271
- .then(() => {
272
- dispatch("product/getBasket", data.restaurantId, { root: true }).then(() => {
273
- dispatch(
274
- "product/getProducts",
275
- { category: rootState.orderiomApiPackage.product.selectedCategory, restaurantId: data.restaurantId }, { root: true }
276
- );
277
- });
278
-
279
- // dispatch(
280
- // "product/getAttributeItems",
281
- // rootState.orderiomApiPackage.product.selectedCategory, { root: true }
282
- // );
283
- })
284
- .catch((error) => {
285
- if (error.response) {
286
- if (error.response.status == 422) {
287
- return {
288
- type: 'error',
289
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
290
-
291
- }
292
- }
293
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
294
195
 
295
- return {
296
- type: 'error',
297
- msg: error.response.data.message.body
298
-
299
- }
300
- }
301
-
302
- }
303
- });
196
+ basketProduct.changingQuantity = true;
197
+ axios.get("api/basket/remove", {
198
+ params: {
199
+ ...basketId,
200
+ basketProductId: basketProduct.basketProductId,
201
+ restaurantId: data.restaurantId,
202
+ },
203
+ }).then(async () => {
204
+ return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
205
+ }).catch(
206
+ commonErrorCallback()
207
+ ).finally(() => {
208
+ basketProduct.changingQuantity = false;
209
+ });
304
210
  },
211
+ //TODO: this function is deprecated. use removeFromBasket instead.
305
212
  removeFromBasketWithAttr({ dispatch, rootState }, data) {
213
+ const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
214
+ f.basketProductId === Number(data.basketProductId)
215
+ );
216
+
217
+ if(!basketProduct){
218
+ return {
219
+ type: 'error',
220
+ msg: 'Product not found'
221
+ }
222
+ }
223
+
306
224
  const basket = JSON.parse(localStorage.getItem("basket"));
307
225
  const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
308
226
  basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
309
227
  } : {}
310
- axios
311
- .get("api/basket/remove", {
312
- params: {
313
- ...basketId,
314
- basketProductId: data.basketProductId,
315
- restaurantId: data.restaurantId,
316
- },
317
- })
318
- .then(() => {
319
- dispatch("product/getBasket", data.restaurantId, { root: true }).then(() => {
320
- dispatch(
321
- "product/getProducts",
322
- { category: rootState.orderiomApiPackage.product.selectedCategory, restaurantId: data.restaurantId }, { root: true }
323
- );
324
- });
325
-
326
- // dispatch(
327
- // "product/getAttributeItems",
328
- // rootState.orderiomApiPackage.product.selectedCategory, { root: true }
329
- // );
330
- })
331
- .catch((error) => {
332
- if (error.response) {
333
- if (error.response.status == 422) {
334
- return {
335
- type: 'error',
336
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
337
-
338
- }
339
- }
340
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
341
-
342
- return {
343
- type: 'error',
344
- msg: error.response.data.message.body
345
228
 
346
- }
347
- }
348
-
349
- }
350
- });
229
+ basketProduct.changingQuantity = true;
230
+ axios.get("api/basket/remove", {
231
+ params: {
232
+ ...basketId,
233
+ basketProductId: data.basketProductId,
234
+ restaurantId: data.restaurantId,
235
+ },
236
+ }).then(async () => {
237
+ return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
238
+ }).catch(
239
+ commonErrorCallback()
240
+ ).finally(() => {
241
+ basketProduct.changingQuantity = false;
242
+ });
351
243
  },
352
244
  deleteFromBasket({ dispatch, rootState }, data) {
353
245
  const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
@@ -374,127 +266,73 @@ const actions = {
374
266
  restaurantId: data.restaurantId,
375
267
  },
376
268
  }).then(async () => {
377
- const getBasketSuccess = await dispatch("product/getBasket", data.restaurantId, { root: true });
378
- const getProductsResult = await dispatch(
379
- "product/getProducts",
380
- {
381
- category: rootState.orderiomApiPackage.product.selectedCategory,
382
- restaurantId: data.restaurantId
383
- },
384
- { root: true }
385
- );
386
- if(!getBasketSuccess || getProductsResult.type !== 'success'){
387
- return {
388
- type: 'error',
389
- msg: 'There was an error in fetching basket and products'
390
- }
391
- }
392
- return {
393
- type: 'success',
394
- msg: ''
395
- }
396
- }).catch(error => {
397
- const status = error.response ? error.response.status : null;
398
- if (status === 422) {
399
- return {
400
- type: 'error',
401
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
402
- }
403
- } else if ([401, 403, 404, 400].includes(status)) {
404
- return {
405
- type: 'error',
406
- msg: error.response.data.message.body
407
- }
408
- }
409
- return {
410
- type: 'error',
411
- msg: 'Something went wrong'
412
- }
413
- }).finally(() => {
269
+ return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
270
+ }).catch(
271
+ commonErrorCallback()
272
+ ).finally(() => {
414
273
  basketProduct.deleting = false;
415
274
  });
416
275
  },
276
+ //TODO: this function is deprecated. use deleteFromBasket instead.
417
277
  deleteFromBasketWithAttr({ dispatch, rootState }, data) {
278
+ const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
279
+ f.basketProductId === Number(data.basketProductId)
280
+ );
281
+
282
+ if(!basketProduct){
283
+ return {
284
+ type: 'error',
285
+ msg: 'Product not found'
286
+ }
287
+ }
288
+
418
289
  const basket = JSON.parse(localStorage.getItem("basket"));
419
290
  const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
420
291
  basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
421
292
  } : {}
422
- axios
423
- .get("api/basket/delete-basket-product", {
424
- params: {
425
- ...basketId,
426
- basketProductId: data.basketProductId,
427
- restaurantId: data.restaurantId,
428
- },
429
- })
430
- .then(() => {
431
- dispatch("product/getBasket", data.restaurantId, { root: true }).then(() => {
432
- dispatch(
433
- "product/getProducts",
434
- { category: rootState.orderiomApiPackage.product.selectedCategory, restaurantId: data.restaurantId }, { root: true }
435
- );
436
- })
437
- })
438
- .catch((error) => {
439
- if (error.response) {
440
- if (error.response.status == 422) {
441
- return {
442
- type: 'error',
443
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
444
-
445
- }
446
- }
447
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
448
-
449
- return {
450
- type: 'error',
451
- msg: error.response.data.message.body
452
293
 
453
- }
454
- }
455
-
456
- }
457
-
458
- });
294
+ basketProduct.deleting = true;
295
+ axios.get("api/basket/delete-basket-product", {
296
+ params: {
297
+ ...basketId,
298
+ basketProductId: data.basketProductId,
299
+ restaurantId: data.restaurantId,
300
+ },
301
+ }).then(async () => {
302
+ return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
303
+ }).catch(
304
+ commonErrorCallback()
305
+ ).finally(() => {
306
+ basketProduct.deleting = false;
307
+ });
459
308
  },
460
309
  addProductPackageItem({ dispatch, rootState }, data) {
310
+ const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
311
+ f.RestaurantProductId === Number(data.productId)
312
+ );
313
+
314
+ if(!basketProduct){
315
+ return {
316
+ type: 'error',
317
+ msg: 'Product not found'
318
+ }
319
+ }
320
+
461
321
  const basket = JSON.parse(localStorage.getItem("basket"));
462
322
  const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
463
323
  basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
464
324
  } : {}
325
+
326
+ basketProduct.changingQuantity = true;
465
327
  return axios.post('api/basket/add-product-package-items', {
466
328
  ...basketId,
467
329
  ...data
468
- }).then((result) => {
469
- dispatch("product/getBasket", data.restaurantId, { root: true }).then(() => {
470
- dispatch(
471
- "product/getProducts",
472
- { category: rootState.orderiomApiPackage.product.selectedCategory, restaurantId: data.restaurantId }, { root: true }
473
- );
474
- });
475
- return {
476
- type: 'success',
477
- msg: 'added'
478
- }
479
- }).catch((error) => {
480
- if (error.response) {
481
- if (error.response.status == 422) {
482
- return {
483
- type: 'error',
484
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
485
-
486
- }
487
- }
488
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
489
-
490
- return {
491
- type: 'error',
492
- msg: error.response.data.message.body
493
-
494
- }
495
- }
496
-
497
- }
330
+ }).then(async () => {
331
+ return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
332
+ }).catch(
333
+ commonErrorCallback()
334
+ ).finally(() => {
335
+ basketProduct.changingQuantity = false;
498
336
  });
499
337
  },
500
338
  addAddress({ rootState }, data) {
@@ -511,25 +349,9 @@ const actions = {
511
349
  .then(() => {
512
350
  return true;
513
351
  })
514
- .catch((error) => {
515
- if (error.response) {
516
- if (error.response.status == 422) {
517
- return {
518
- type: 'error',
519
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
520
-
521
- }
522
- }
523
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
524
- return {
525
- type: 'error',
526
- msg: error.response.data.message.body
527
-
528
- }
529
- }
530
-
531
- }
532
- });
352
+ .catch(
353
+ commonErrorCallback()
354
+ );
533
355
  },
534
356
  checkAddress({ rootState }, data) {
535
357
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -552,26 +374,9 @@ const actions = {
552
374
  msg: 'ok'
553
375
  }
554
376
  })
555
- .catch((error) => {
556
- if (error.response) {
557
- if (error.response.status == 422) {
558
- return {
559
- type: 'error',
560
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
561
-
562
- }
563
- }
564
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
565
- return {
566
- type: 'error',
567
- msg: error.response.data.message.body
568
-
569
- }
570
- }
571
-
572
- }
573
- console.clear()
574
- });
377
+ .catch(
378
+ commonErrorCallback()
379
+ );
575
380
  },
576
381
  removeElement({ }, data) {
577
382
  var index = data.array.indexOf(data.item);
@@ -616,25 +421,9 @@ const actions = {
616
421
  msg: 'ok'
617
422
  }
618
423
  })
619
- .catch((error) => {
620
- if (error.response) {
621
- if (error.response.status == 422) {
622
- return {
623
- type: 'error',
624
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
625
-
626
- }
627
- }
628
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
629
- return {
630
- type: 'error',
631
- msg: error.response.data.message.body
632
-
633
- }
634
- }
635
-
636
- }
637
- });
424
+ .catch(
425
+ commonErrorCallback()
426
+ );
638
427
  },
639
428
  getOrder({ commit }, orderId) {
640
429
  return axios
@@ -659,27 +448,9 @@ const actions = {
659
448
  msg: "ok"
660
449
  }
661
450
  })
662
- .catch((error) => {
663
- if (error.response) {
664
- if (error.response.status == 422) {
665
- return {
666
- type: 'error',
667
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
668
-
669
- }
670
- }
671
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
672
-
673
- return {
674
- type: 'error',
675
- msg: error.response.data.message.body
676
-
677
- }
678
- }
679
-
680
- }
681
- });
682
-
451
+ .catch(
452
+ commonErrorCallback()
453
+ );
683
454
  },
684
455
  requestBill({ }, orderId) {
685
456
  return axios
@@ -694,26 +465,9 @@ const actions = {
694
465
  msg: res.data.message.body
695
466
  }
696
467
  })
697
- .catch((error) => {
698
- if (error.response) {
699
- if (error.response.status == 422) {
700
- return {
701
- type: 'error',
702
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
703
-
704
- }
705
- }
706
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
707
-
708
- return {
709
- type: 'error',
710
- msg: error.response.data.message.body
711
-
712
- }
713
- }
714
-
715
- }
716
- });
468
+ .catch(
469
+ commonErrorCallback()
470
+ );
717
471
 
718
472
  },
719
473
  preparePayment({ rootState }, data) {
@@ -730,26 +484,9 @@ const actions = {
730
484
  }
731
485
  }).then((result) => {
732
486
  window.location = result.data.data.mollieLink;
733
- }).catch((error) => {
734
- if (error.response) {
735
- if (error.response.status == 422) {
736
- return {
737
- type: 'error',
738
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
739
-
740
- }
741
- }
742
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
743
-
744
- return {
745
- type: 'error',
746
- msg: error.response.data.message.body
747
-
748
- }
749
- }
750
-
751
- }
752
- });
487
+ }).catch(
488
+ commonErrorCallback()
489
+ );
753
490
  },
754
491
  updatePaymentStatus({ dispatch, commit }, data) {
755
492
  return axios
@@ -769,26 +506,9 @@ const actions = {
769
506
  // msg: 'ok'
770
507
  // }
771
508
  })
772
- .catch((error) => {
773
- if (error.response) {
774
- if (error.response.status == 422) {
775
- return {
776
- type: 'error',
777
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
778
-
779
- }
780
- }
781
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
782
-
783
- return {
784
- type: 'error',
785
- msg: error.response.data.message.body
786
-
787
- }
788
- }
789
-
790
- }
791
- });
509
+ .catch(
510
+ commonErrorCallback()
511
+ );
792
512
  },
793
513
  getShippingPrice({ commit, rootState }, data) {
794
514
  let basketId = undefined;
@@ -817,27 +537,9 @@ const actions = {
817
537
  msg: 'ok'
818
538
  }
819
539
  })
820
- .catch((error) => {
821
- if (error.response) {
822
- if (error.response.status == 422) {
823
- return {
824
- type: 'error',
825
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
826
-
827
- }
828
- }
829
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
830
-
831
- return {
832
- type: 'error',
833
- msg: error.response.data.message.body
834
-
835
- }
836
- }
837
-
838
- }
839
- console.clear();
840
- });
540
+ .catch(
541
+ commonErrorCallback()
542
+ );
841
543
  },
842
544
  getTotalPrice({ commit, rootState }, data) {
843
545
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -863,27 +565,9 @@ const actions = {
863
565
  msg: 'ok'
864
566
  }
865
567
  })
866
- .catch((error) => {
867
- if (error.response) {
868
- if (error.response.status == 422) {
869
- return {
870
- type: 'error',
871
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
872
-
873
- }
874
- }
875
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
876
-
877
- return {
878
- type: 'error',
879
- msg: error.response.data.message.body
880
-
881
- }
882
- }
883
-
884
- }
885
- console.clear();
886
- });
568
+ .catch(
569
+ commonErrorCallback()
570
+ );
887
571
  },
888
572
  addDeliveryTimeToBasket({ dispatch, rootState }, data) {
889
573
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -906,26 +590,9 @@ const actions = {
906
590
  msg: 'ok'
907
591
  }
908
592
  })
909
- .catch((error) => {
910
- if (error.response) {
911
- if (error.response.status == 422) {
912
- return {
913
- type: 'error',
914
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
915
-
916
- }
917
- }
918
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
919
-
920
- return {
921
- type: 'error',
922
- msg: error.response.data.message.body
923
-
924
- }
925
- }
926
-
927
- }
928
- });
593
+ .catch(
594
+ commonErrorCallback()
595
+ );
929
596
  },
930
597
  getOrderHistory({ commit }, data) {
931
598
  return axios
@@ -933,27 +600,9 @@ const actions = {
933
600
  .then((res) => {
934
601
  commit('setorderList', res.data.data)
935
602
  })
936
- .catch((error) => {
937
- if (error.response) {
938
- if (error.response.status == 422) {
939
- return {
940
- type: 'error',
941
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
942
-
943
- }
944
- }
945
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
946
-
947
- return {
948
- type: 'error',
949
- msg: error.response.data.message.body
950
-
951
- }
952
- }
953
-
954
- }
955
- console.clear();
956
- });
603
+ .catch(
604
+ commonErrorCallback()
605
+ );
957
606
  },
958
607
  addVoucher({ rootState, dispatch }, data) {
959
608
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -972,26 +621,9 @@ const actions = {
972
621
  type: 'success',
973
622
  msg: result.message
974
623
  }
975
- }).catch((error) => {
976
- if (error.response) {
977
- if (error.response.status == 422) {
978
- return {
979
- type: 'error',
980
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
981
-
982
- }
983
- }
984
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
985
-
986
- return {
987
- type: 'error',
988
- msg: error.response.data.message.body
989
-
990
- }
991
- }
992
-
993
- }
994
- });
624
+ }).catch(
625
+ commonErrorCallback()
626
+ );
995
627
  },
996
628
  removeVoucher({ rootState, dispatch }, restaurantId) {
997
629
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -1009,26 +641,9 @@ const actions = {
1009
641
  type: 'success',
1010
642
  msg: 'removed'
1011
643
  }
1012
- }).catch((error) => {
1013
- if (error.response) {
1014
- if (error.response.status == 422) {
1015
- return {
1016
- type: 'error',
1017
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
1018
-
1019
- }
1020
- }
1021
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
1022
-
1023
- return {
1024
- type: 'error',
1025
- msg: error.response.data.message.body
1026
-
1027
- }
1028
- }
1029
-
1030
- }
1031
- });
644
+ }).catch(
645
+ commonErrorCallback()
646
+ );
1032
647
  },
1033
648
  addTip({ rootState, dispatch }, data) {
1034
649
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -1045,26 +660,9 @@ const actions = {
1045
660
  type: 'success',
1046
661
  msg: 'removed'
1047
662
  }
1048
- }).catch((error) => {
1049
- if (error.response) {
1050
- if (error.response.status == 422) {
1051
- return {
1052
- type: 'error',
1053
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
1054
-
1055
- }
1056
- }
1057
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
1058
-
1059
- return {
1060
- type: 'error',
1061
- msg: error.response.data.message.body
1062
-
1063
- }
1064
- }
1065
-
1066
- }
1067
- });
663
+ }).catch(
664
+ commonErrorCallback()
665
+ );
1068
666
  },
1069
667
  removeTip({ rootState, dispatch }, restaurantId) {
1070
668
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -1080,26 +678,9 @@ const actions = {
1080
678
  type: 'success',
1081
679
  msg: 'removed'
1082
680
  }
1083
- }).catch((error) => {
1084
- if (error.response) {
1085
- if (error.response.status == 422) {
1086
- return {
1087
- type: 'error',
1088
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
1089
-
1090
- }
1091
- }
1092
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
1093
-
1094
- return {
1095
- type: 'error',
1096
- msg: error.response.data.message.body
1097
-
1098
- }
1099
- }
1100
-
1101
- }
1102
- });
681
+ }).catch(
682
+ commonErrorCallback()
683
+ );
1103
684
  },
1104
685
  checkOrderValidity({ rootState }, data) {
1105
686
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -1116,26 +697,9 @@ const actions = {
1116
697
  type: 'success',
1117
698
  msg: 'ok'
1118
699
  }
1119
- }).catch((error) => {
1120
- if (error.response) {
1121
- if (error.response.status == 422) {
1122
- return {
1123
- type: 'error',
1124
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
1125
-
1126
- }
1127
- }
1128
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
1129
-
1130
- return {
1131
- type: 'error',
1132
- msg: error.response.data.message.body
1133
-
1134
- }
1135
- }
1136
-
1137
- }
1138
- });
700
+ }).catch(
701
+ commonErrorCallback()
702
+ );
1139
703
  }
1140
704
  }
1141
705
  export default {