orderiom-api-package 0.2.51 → 0.2.53

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,42 +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
- }
21
-
22
- function commonErrorCallback(error){
23
- const status = error.response ? error.response.status : null;
24
- if (status === 422) {
25
- return {
26
- type: 'error',
27
- msg: Object.values(error.response.data.error.validation).map(m => m[0]).toString()
28
- }
29
- } else if ([401, 403, 404, 400].includes(status)) {
30
- return {
31
- type: 'error',
32
- msg: error.response.data.message.body
33
- }
34
- }
35
- return {
36
- type: 'error',
37
- msg: 'Something went wrong'
38
- }
39
- }
2
+ import { commonErrorCallback, calculateBasketIdParameter, restaurantId } from '../common';
40
3
 
41
4
  const state = () => ({
42
5
  productOrder: null,
@@ -132,26 +95,9 @@ const actions = {
132
95
  // localStorage.setItem("basketId", res.data.id);
133
96
  return true;
134
97
  })
135
- .catch((error) => {
136
- if (error.response) {
137
- if (error.response.status == 422) {
138
- return {
139
- type: 'error',
140
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
141
-
142
- }
143
- }
144
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
145
-
146
- return {
147
- type: 'error',
148
- msg: error.response.data.message.body
149
-
150
- }
151
- }
152
-
153
- }
154
- });
98
+ .catch(
99
+ commonErrorCallback()
100
+ );
155
101
  },
156
102
  createBasketFromOrder({ dispatch }, data) {
157
103
  const basketData = JSON.parse(localStorage.getItem("basket") || "[]");
@@ -169,31 +115,9 @@ const actions = {
169
115
  msg: result ? 'Basket created' : 'There was an error in fetching the basket info',
170
116
  }
171
117
  })
172
- .catch((error) => {
173
- if(!error.response){
174
- return {
175
- type: 'error',
176
- msg: 'There was an error in creating basket',
177
- }
178
- }
179
- const status = error.response.status;
180
- if (status === 422) {
181
- return {
182
- type: 'error',
183
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
184
- }
185
- }
186
- if ([401, 403, 404, 400].includes(status)) {
187
- return {
188
- type: 'error',
189
- msg: error.response.data.message.body
190
- }
191
- }
192
- return {
193
- type:'error',
194
- msg:'There was an error in creating basket'
195
- }
196
- });
118
+ .catch(
119
+ commonErrorCallback('There was an error in creating basket')
120
+ );
197
121
  },
198
122
  setTable({ rootState }, data) {
199
123
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -221,26 +145,9 @@ const actions = {
221
145
  type: 'success',
222
146
  msg: 'ok'
223
147
  }
224
- }).catch((error) => {
225
- if (error.response) {
226
- if (error.response.status == 422) {
227
- return {
228
- type: 'error',
229
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
230
-
231
- }
232
- }
233
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
234
-
235
- return {
236
- type: 'error',
237
- msg: error.response.data.message.body
238
-
239
- }
240
- }
241
-
242
- }
243
- });
148
+ }).catch(
149
+ commonErrorCallback()
150
+ );
244
151
  },
245
152
  addToBasket({ dispatch, rootState }, data) {
246
153
  // might be null
@@ -264,7 +171,7 @@ const actions = {
264
171
  }).then(async () => {
265
172
  return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
266
173
  }).catch(
267
- commonErrorCallback
174
+ commonErrorCallback()
268
175
  ).finally(() => {
269
176
  if(basketProduct) basketProduct.changingQuantity = false;
270
177
  });
@@ -296,7 +203,7 @@ const actions = {
296
203
  }).then(async () => {
297
204
  return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
298
205
  }).catch(
299
- commonErrorCallback
206
+ commonErrorCallback()
300
207
  ).finally(() => {
301
208
  basketProduct.changingQuantity = false;
302
209
  });
@@ -329,7 +236,7 @@ const actions = {
329
236
  }).then(async () => {
330
237
  return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
331
238
  }).catch(
332
- commonErrorCallback
239
+ commonErrorCallback()
333
240
  ).finally(() => {
334
241
  basketProduct.changingQuantity = false;
335
242
  });
@@ -361,7 +268,7 @@ const actions = {
361
268
  }).then(async () => {
362
269
  return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
363
270
  }).catch(
364
- commonErrorCallback
271
+ commonErrorCallback()
365
272
  ).finally(() => {
366
273
  basketProduct.deleting = false;
367
274
  });
@@ -394,7 +301,7 @@ const actions = {
394
301
  }).then(async () => {
395
302
  return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
396
303
  }).catch(
397
- commonErrorCallback
304
+ commonErrorCallback()
398
305
  ).finally(() => {
399
306
  basketProduct.deleting = false;
400
307
  });
@@ -404,28 +311,21 @@ const actions = {
404
311
  f.RestaurantProductId === Number(data.productId)
405
312
  );
406
313
 
407
- if(!basketProduct){
408
- return {
409
- type: 'error',
410
- msg: 'Product not found'
411
- }
412
- }
413
-
414
314
  const basket = JSON.parse(localStorage.getItem("basket"));
415
315
  const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
416
316
  basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
417
317
  } : {}
418
318
 
419
- basketProduct.changingQuantity = true;
319
+ if(basketProduct) basketProduct.changingQuantity = true;
420
320
  return axios.post('api/basket/add-product-package-items', {
421
321
  ...basketId,
422
322
  ...data
423
323
  }).then(async () => {
424
324
  return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
425
325
  }).catch(
426
- commonErrorCallback
326
+ commonErrorCallback()
427
327
  ).finally(() => {
428
- basketProduct.changingQuantity = false;
328
+ if(basketProduct) basketProduct.changingQuantity = false;
429
329
  });
430
330
  },
431
331
  addAddress({ rootState }, data) {
@@ -442,25 +342,9 @@ const actions = {
442
342
  .then(() => {
443
343
  return true;
444
344
  })
445
- .catch((error) => {
446
- if (error.response) {
447
- if (error.response.status == 422) {
448
- return {
449
- type: 'error',
450
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
451
-
452
- }
453
- }
454
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
455
- return {
456
- type: 'error',
457
- msg: error.response.data.message.body
458
-
459
- }
460
- }
461
-
462
- }
463
- });
345
+ .catch(
346
+ commonErrorCallback()
347
+ );
464
348
  },
465
349
  checkAddress({ rootState }, data) {
466
350
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -483,26 +367,9 @@ const actions = {
483
367
  msg: 'ok'
484
368
  }
485
369
  })
486
- .catch((error) => {
487
- if (error.response) {
488
- if (error.response.status == 422) {
489
- return {
490
- type: 'error',
491
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
492
-
493
- }
494
- }
495
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
496
- return {
497
- type: 'error',
498
- msg: error.response.data.message.body
499
-
500
- }
501
- }
502
-
503
- }
504
- console.clear()
505
- });
370
+ .catch(
371
+ commonErrorCallback()
372
+ );
506
373
  },
507
374
  removeElement({ }, data) {
508
375
  var index = data.array.indexOf(data.item);
@@ -547,25 +414,9 @@ const actions = {
547
414
  msg: 'ok'
548
415
  }
549
416
  })
550
- .catch((error) => {
551
- if (error.response) {
552
- if (error.response.status == 422) {
553
- return {
554
- type: 'error',
555
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
556
-
557
- }
558
- }
559
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
560
- return {
561
- type: 'error',
562
- msg: error.response.data.message.body
563
-
564
- }
565
- }
566
-
567
- }
568
- });
417
+ .catch(
418
+ commonErrorCallback()
419
+ );
569
420
  },
570
421
  getOrder({ commit }, orderId) {
571
422
  return axios
@@ -590,27 +441,9 @@ const actions = {
590
441
  msg: "ok"
591
442
  }
592
443
  })
593
- .catch((error) => {
594
- if (error.response) {
595
- if (error.response.status == 422) {
596
- return {
597
- type: 'error',
598
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
599
-
600
- }
601
- }
602
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
603
-
604
- return {
605
- type: 'error',
606
- msg: error.response.data.message.body
607
-
608
- }
609
- }
610
-
611
- }
612
- });
613
-
444
+ .catch(
445
+ commonErrorCallback()
446
+ );
614
447
  },
615
448
  requestBill({ }, orderId) {
616
449
  return axios
@@ -625,26 +458,9 @@ const actions = {
625
458
  msg: res.data.message.body
626
459
  }
627
460
  })
628
- .catch((error) => {
629
- if (error.response) {
630
- if (error.response.status == 422) {
631
- return {
632
- type: 'error',
633
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
634
-
635
- }
636
- }
637
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
638
-
639
- return {
640
- type: 'error',
641
- msg: error.response.data.message.body
642
-
643
- }
644
- }
645
-
646
- }
647
- });
461
+ .catch(
462
+ commonErrorCallback()
463
+ );
648
464
 
649
465
  },
650
466
  preparePayment({ rootState }, data) {
@@ -661,26 +477,9 @@ const actions = {
661
477
  }
662
478
  }).then((result) => {
663
479
  window.location = result.data.data.mollieLink;
664
- }).catch((error) => {
665
- if (error.response) {
666
- if (error.response.status == 422) {
667
- return {
668
- type: 'error',
669
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
670
-
671
- }
672
- }
673
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
674
-
675
- return {
676
- type: 'error',
677
- msg: error.response.data.message.body
678
-
679
- }
680
- }
681
-
682
- }
683
- });
480
+ }).catch(
481
+ commonErrorCallback()
482
+ );
684
483
  },
685
484
  updatePaymentStatus({ dispatch, commit }, data) {
686
485
  return axios
@@ -700,26 +499,9 @@ const actions = {
700
499
  // msg: 'ok'
701
500
  // }
702
501
  })
703
- .catch((error) => {
704
- if (error.response) {
705
- if (error.response.status == 422) {
706
- return {
707
- type: 'error',
708
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
709
-
710
- }
711
- }
712
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
713
-
714
- return {
715
- type: 'error',
716
- msg: error.response.data.message.body
717
-
718
- }
719
- }
720
-
721
- }
722
- });
502
+ .catch(
503
+ commonErrorCallback()
504
+ );
723
505
  },
724
506
  getShippingPrice({ commit, rootState }, data) {
725
507
  let basketId = undefined;
@@ -748,27 +530,9 @@ const actions = {
748
530
  msg: 'ok'
749
531
  }
750
532
  })
751
- .catch((error) => {
752
- if (error.response) {
753
- if (error.response.status == 422) {
754
- return {
755
- type: 'error',
756
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
757
-
758
- }
759
- }
760
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
761
-
762
- return {
763
- type: 'error',
764
- msg: error.response.data.message.body
765
-
766
- }
767
- }
768
-
769
- }
770
- console.clear();
771
- });
533
+ .catch(
534
+ commonErrorCallback()
535
+ );
772
536
  },
773
537
  getTotalPrice({ commit, rootState }, data) {
774
538
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -794,27 +558,9 @@ const actions = {
794
558
  msg: 'ok'
795
559
  }
796
560
  })
797
- .catch((error) => {
798
- if (error.response) {
799
- if (error.response.status == 422) {
800
- return {
801
- type: 'error',
802
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
803
-
804
- }
805
- }
806
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
807
-
808
- return {
809
- type: 'error',
810
- msg: error.response.data.message.body
811
-
812
- }
813
- }
814
-
815
- }
816
- console.clear();
817
- });
561
+ .catch(
562
+ commonErrorCallback()
563
+ );
818
564
  },
819
565
  addDeliveryTimeToBasket({ dispatch, rootState }, data) {
820
566
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -837,26 +583,9 @@ const actions = {
837
583
  msg: 'ok'
838
584
  }
839
585
  })
840
- .catch((error) => {
841
- if (error.response) {
842
- if (error.response.status == 422) {
843
- return {
844
- type: 'error',
845
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
846
-
847
- }
848
- }
849
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
850
-
851
- return {
852
- type: 'error',
853
- msg: error.response.data.message.body
854
-
855
- }
856
- }
857
-
858
- }
859
- });
586
+ .catch(
587
+ commonErrorCallback()
588
+ );
860
589
  },
861
590
  getOrderHistory({ commit }, data) {
862
591
  return axios
@@ -864,27 +593,9 @@ const actions = {
864
593
  .then((res) => {
865
594
  commit('setorderList', res.data.data)
866
595
  })
867
- .catch((error) => {
868
- if (error.response) {
869
- if (error.response.status == 422) {
870
- return {
871
- type: 'error',
872
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
873
-
874
- }
875
- }
876
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
877
-
878
- return {
879
- type: 'error',
880
- msg: error.response.data.message.body
881
-
882
- }
883
- }
884
-
885
- }
886
- console.clear();
887
- });
596
+ .catch(
597
+ commonErrorCallback()
598
+ );
888
599
  },
889
600
  addVoucher({ rootState, dispatch }, data) {
890
601
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -903,26 +614,9 @@ const actions = {
903
614
  type: 'success',
904
615
  msg: result.message
905
616
  }
906
- }).catch((error) => {
907
- if (error.response) {
908
- if (error.response.status == 422) {
909
- return {
910
- type: 'error',
911
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
912
-
913
- }
914
- }
915
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
916
-
917
- return {
918
- type: 'error',
919
- msg: error.response.data.message.body
920
-
921
- }
922
- }
923
-
924
- }
925
- });
617
+ }).catch(
618
+ commonErrorCallback()
619
+ );
926
620
  },
927
621
  removeVoucher({ rootState, dispatch }, restaurantId) {
928
622
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -940,26 +634,9 @@ const actions = {
940
634
  type: 'success',
941
635
  msg: 'removed'
942
636
  }
943
- }).catch((error) => {
944
- if (error.response) {
945
- if (error.response.status == 422) {
946
- return {
947
- type: 'error',
948
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
949
-
950
- }
951
- }
952
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
953
-
954
- return {
955
- type: 'error',
956
- msg: error.response.data.message.body
957
-
958
- }
959
- }
960
-
961
- }
962
- });
637
+ }).catch(
638
+ commonErrorCallback()
639
+ );
963
640
  },
964
641
  addTip({ rootState, dispatch }, data) {
965
642
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -976,26 +653,9 @@ const actions = {
976
653
  type: 'success',
977
654
  msg: 'removed'
978
655
  }
979
- }).catch((error) => {
980
- if (error.response) {
981
- if (error.response.status == 422) {
982
- return {
983
- type: 'error',
984
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
985
-
986
- }
987
- }
988
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
989
-
990
- return {
991
- type: 'error',
992
- msg: error.response.data.message.body
993
-
994
- }
995
- }
996
-
997
- }
998
- });
656
+ }).catch(
657
+ commonErrorCallback()
658
+ );
999
659
  },
1000
660
  removeTip({ rootState, dispatch }, restaurantId) {
1001
661
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -1011,26 +671,9 @@ const actions = {
1011
671
  type: 'success',
1012
672
  msg: 'removed'
1013
673
  }
1014
- }).catch((error) => {
1015
- if (error.response) {
1016
- if (error.response.status == 422) {
1017
- return {
1018
- type: 'error',
1019
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
1020
-
1021
- }
1022
- }
1023
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
1024
-
1025
- return {
1026
- type: 'error',
1027
- msg: error.response.data.message.body
1028
-
1029
- }
1030
- }
1031
-
1032
- }
1033
- });
674
+ }).catch(
675
+ commonErrorCallback()
676
+ );
1034
677
  },
1035
678
  checkOrderValidity({ rootState }, data) {
1036
679
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -1047,26 +690,9 @@ const actions = {
1047
690
  type: 'success',
1048
691
  msg: 'ok'
1049
692
  }
1050
- }).catch((error) => {
1051
- if (error.response) {
1052
- if (error.response.status == 422) {
1053
- return {
1054
- type: 'error',
1055
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
1056
-
1057
- }
1058
- }
1059
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
1060
-
1061
- return {
1062
- type: 'error',
1063
- msg: error.response.data.message.body
1064
-
1065
- }
1066
- }
1067
-
1068
- }
1069
- });
693
+ }).catch(
694
+ commonErrorCallback()
695
+ );
1070
696
  }
1071
697
  }
1072
698
  export default {