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,24 +1,6 @@
1
1
  import axios from "axios";
2
2
  import Vue from 'vue';
3
-
4
- const restaurantId = process.env.VUE_APP_RESTAURANT_ID;
5
-
6
- function calculateBasketIdParameter(isLogin) {
7
- if(isLogin) return undefined;
8
- // localStorage might fail
9
- let baskets = [];
10
- try{
11
- baskets = JSON.parse(localStorage.getItem("basket")) || [];
12
- }catch(e){
13
- console.error(e);
14
- throw new Error('Basket not found');
15
- }
16
- const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId);
17
- if(!foundBasket){
18
- throw new Error('Basket not found');
19
- }
20
- return foundBasket.basketId;
21
- }
3
+ import { commonErrorCallback, calculateBasketIdParameter, restaurantId } from '../common';
22
4
 
23
5
  const state = () => ({
24
6
  selectedTime: null,
@@ -176,25 +158,9 @@ const actions = {
176
158
 
177
159
  })
178
160
  })
179
- .catch((error) => {
180
- if (error.response) {
181
- if (error.response.status == 422) {
182
- return {
183
- type: 'error',
184
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
185
- }
186
- }
187
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
188
-
189
- return {
190
- type: 'error',
191
- msg: error.response.data.message.body
192
-
193
- }
194
- }
195
-
196
- }
197
- });
161
+ .catch(
162
+ commonErrorCallback()
163
+ );
198
164
  },
199
165
  getCategories({ commit, dispatch }, restaurantId) {
200
166
  return axios
@@ -236,25 +202,9 @@ const actions = {
236
202
  msg: 'ok'
237
203
  }
238
204
  })
239
- .catch((error) => {
240
- if (error.response) {
241
- if (error.response.status == 422) {
242
- return {
243
- type: 'error',
244
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
245
- }
246
- }
247
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
248
-
249
- return {
250
- type: 'error',
251
- msg: error.response.data.message.body
252
-
253
- }
254
- }
255
-
256
- }
257
- });
205
+ .catch(
206
+ commonErrorCallback()
207
+ );
258
208
  },
259
209
  getProducts({ commit, state, rootState }, data) {
260
210
  commit("setSelectedCategory", data.category);
@@ -302,24 +252,9 @@ const actions = {
302
252
  })
303
253
  commit("setProduct", products);
304
254
  return { type: 'success', data: products }
305
- }).catch(error => {
306
- const status = error.response ? error.response.status : null;
307
- if (status === 422) {
308
- return {
309
- type: 'error',
310
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
311
- }
312
- } else if ([401, 403, 404, 400].includes(status)) {
313
- return {
314
- type: 'error',
315
- msg: error.response.data.message.body
316
- }
317
- }
318
- return {
319
- type: 'error',
320
- msg: 'Something went wrong'
321
- }
322
- });
255
+ }).catch(
256
+ commonErrorCallback()
257
+ );
323
258
  },
324
259
  getBasket({ commit, rootState }, restaurantId) {
325
260
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -383,26 +318,9 @@ const actions = {
383
318
  }
384
319
  }).then((result) => {
385
320
  commit('setAttributeItems', result.data.data)
386
- }).catch((error) => {
387
- if (error.response) {
388
- if (error.response.status == 422) {
389
- return {
390
- type: 'error',
391
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
392
-
393
- }
394
- }
395
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
396
-
397
- return {
398
- type: 'error',
399
- msg: error.response.data.message.body
400
-
401
- }
402
- }
403
-
404
- }
405
- });
321
+ }).catch(
322
+ commonErrorCallback()
323
+ );
406
324
  },
407
325
  getPackage({ commit }, data) {
408
326
  return axios.get('api/restaurant/product-packages', {
@@ -412,26 +330,9 @@ const actions = {
412
330
  }
413
331
  }).then((result) => {
414
332
  commit('setProductPackage', result.data.data)
415
- }).catch((error) => {
416
- if (error.response) {
417
- if (error.response.status == 422) {
418
- return {
419
- type: 'error',
420
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
421
-
422
- }
423
- }
424
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
425
-
426
- return {
427
- type: 'error',
428
- msg: error.response.data.message.body
429
-
430
- }
431
- }
432
-
433
- }
434
- });
333
+ }).catch(
334
+ commonErrorCallback()
335
+ );
435
336
  },
436
337
  searchOnProducts({ commit }, data) {
437
338
  return axios.get('api/restaurant/product/search', {
@@ -441,26 +342,9 @@ const actions = {
441
342
  }
442
343
  }).then((result) => {
443
344
  commit('setProduct', result.data.data)
444
- }).catch((error) => {
445
- if (error.response) {
446
- if (error.response.status == 422) {
447
- return {
448
- type: 'error',
449
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
450
-
451
- }
452
- }
453
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
454
-
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
  changeDeliveryMethod({ commit, dispatch, rootState, state }, deliveryType){
466
350
  let basketId = undefined;
@@ -1,6 +1,5 @@
1
1
  import axios from "axios";
2
-
3
- const restaurantId = process.env.VUE_APP_RESTAURANT_ID;
2
+ import { commonErrorCallback, calculateBasketIdParameter, restaurantId } from '../common';
4
3
 
5
4
  const state = () => ({
6
5
  restaurantInfo: {},
@@ -75,46 +74,16 @@ const actions = {
75
74
  }
76
75
  }).catch(error => {
77
76
  commit('setRestaurants', [])
78
- if (error.response) {
79
- if (error.response.status == 422) {
80
- return {
81
- type: 'error',
82
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
83
- }
84
- }
85
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
86
-
87
- return {
88
- type: 'error',
89
- msg: error.response.data.message.body
90
-
91
- }
92
- }
93
- }
77
+ return commonErrorCallback()(error);
94
78
  })
95
79
  },
96
80
  getRestaurantInfo({ commit }, restaurantId) {
97
81
  commit('startFetchingRestaurantInfo');
98
82
  return axios.get('api/restaurant/restaurant-by-id', { params: { restaurantId } }).then(result => {
99
83
  commit('setRestaurantInfo', result.data.data[0]);
100
- }).catch((error) => {
101
- if (error.response) {
102
- if (error.response.status == 422) {
103
- return {
104
- type: 'error',
105
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
106
- }
107
- }
108
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
109
-
110
- return {
111
- type: 'error',
112
- msg: error.response.data.message.body
113
-
114
- }
115
- }
116
- }
117
- }).finally(() => {
84
+ }).catch(
85
+ commonErrorCallback()
86
+ ).finally(() => {
118
87
  commit('finishFetchingRestaurantInfo');
119
88
  });
120
89
  },
@@ -125,24 +94,9 @@ const actions = {
125
94
  }
126
95
  }).then((result) => {
127
96
  commit('setRestaurantId', result.data.data.id)
128
- }).catch((error) => {
129
- if (error.response) {
130
- if (error.response.status == 422) {
131
- return {
132
- type: 'error',
133
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
134
- }
135
- }
136
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
137
-
138
- return {
139
- type: 'error',
140
- msg: error.response.data.message.body
141
-
142
- }
143
- }
144
- }
145
- });
97
+ }).catch(
98
+ commonErrorCallback()
99
+ );
146
100
  },
147
101
  contact({ }, data) {
148
102
  return axios.post('api/contact', data).then((result) => {
@@ -150,46 +104,16 @@ const actions = {
150
104
  type: 'success',
151
105
  msg: 'your message has been delivered successfully!'
152
106
  }
153
- }).catch((error) => {
154
- if (error.response) {
155
- if (error.response.status == 422) {
156
- return {
157
- type: 'error',
158
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
159
- }
160
- }
161
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
162
-
163
- return {
164
- type: 'error',
165
- msg: error.response.data.message.body
166
-
167
- }
168
- }
169
- }
170
- });
107
+ }).catch(
108
+ commonErrorCallback()
109
+ );
171
110
  },
172
111
  getImprint({ commit }, restaurantId) {
173
112
  return axios.get('api/restaurant/imprint', { params: { restaurantId: restaurantId } }).then(res => {
174
113
  commit('setImprint', res.data.data.imprint)
175
- }).catch(error => {
176
- if (error.response) {
177
- if (error.response.status == 422) {
178
- return {
179
- type: 'error',
180
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
181
- }
182
- }
183
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
184
-
185
- return {
186
- type: 'error',
187
- msg: error.response.data.message.body
188
-
189
- }
190
- }
191
- }
192
- })
114
+ }).catch(
115
+ commonErrorCallback()
116
+ )
193
117
  },
194
118
  Newsletter({ }, data) {
195
119
  return axios.post('api/newsletter/create', null, {
@@ -199,25 +123,9 @@ const actions = {
199
123
  type: 'success',
200
124
  msg: res.data.message.body
201
125
  }
202
- }).catch(error => {
203
- if (error.response) {
204
- if (error.response.status == 422) {
205
- return {
206
- type: 'error',
207
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
208
- }
209
- }
210
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
211
-
212
- return {
213
- type: 'error',
214
- msg: error.response.data.message.body
215
-
216
- }
217
- }
218
-
219
- }
220
- })
126
+ }).catch(
127
+ commonErrorCallback()
128
+ )
221
129
  },
222
130
  getTables({ commit }, restaurantId) {
223
131
  return axios.get('api/restaurant/tables', {
@@ -230,25 +138,9 @@ const actions = {
230
138
  type: 'success',
231
139
  msg: 'ok'
232
140
  }
233
- }).catch((error) => {
234
- if (error.response) {
235
- if (error.response.status == 422) {
236
- return {
237
- type: 'error',
238
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
239
- }
240
- }
241
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
242
-
243
- return {
244
- type: 'error',
245
- msg: error.response.data.message.body
246
-
247
- }
248
- }
249
-
250
- }
251
- });
141
+ }).catch(
142
+ commonErrorCallback()
143
+ );
252
144
  },
253
145
  addReservedTables({ commit }, data) {
254
146
  return axios
@@ -266,28 +158,9 @@ const actions = {
266
158
  type: 'success',
267
159
  msg: ''
268
160
  }
269
- }).catch((error) => {
270
- if(!error.response){
271
- return {
272
- type: 'error',
273
- msg: 'There was an error in adding reserved tables',
274
- }
275
- }
276
- const status = error.response.status;
277
- if (status === 422) {
278
- return {
279
- type: 'error',
280
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
281
- }
282
- }
283
- if ([401, 403, 404, 400].includes(status)) {
284
- return {
285
- type: 'error',
286
- msg: error.response.data.message.body,
287
- }
288
- }
289
-
290
- });
161
+ }).catch(
162
+ commonErrorCallback('There was an error in adding reserved tables')
163
+ );
291
164
  },
292
165
  getBlogs({ commit }, restaurantId) {
293
166
  return axios.get('api/blogs', {
@@ -300,22 +173,7 @@ const actions = {
300
173
  }
301
174
  }).catch(error => {
302
175
  commit('setBlogs', [])
303
- if (error.response) {
304
- if (error.response.status == 422) {
305
- return {
306
- type: 'error',
307
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
308
- }
309
- }
310
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
311
-
312
- return {
313
- type: 'error',
314
- msg: error.response.data.message.body
315
-
316
- }
317
- }
318
- }
176
+ return commonErrorCallback()(error);
319
177
  })
320
178
  },
321
179
  getBlogsByTag({ commit }, tagId) {
@@ -334,28 +192,7 @@ const actions = {
334
192
  }
335
193
  }).catch(error => {
336
194
  commit('setBlogs', [])
337
- if(!error.response){
338
- return {
339
- type: 'error',
340
- msg: 'There was an error in fetching the blogs',
341
- tagName: ''
342
- }
343
- }
344
- const status = error.response.status;
345
- if (status === 422) {
346
- return {
347
- type: 'error',
348
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString(),
349
- tagName: ''
350
- }
351
- }
352
- if ([401, 403, 404, 400].includes(status)) {
353
- return {
354
- type: 'error',
355
- msg: error.response.data.message.body,
356
- tagName: ''
357
- }
358
- }
195
+ return commonErrorCallback('There was an error in fetching the blogs')(error);
359
196
  }).finally(() => {
360
197
  commit('finishFetchingBlogs');
361
198
  })
@@ -371,22 +208,7 @@ const actions = {
371
208
  }
372
209
  }).catch(error => {
373
210
  commit('setBlog', [])
374
- if (error.response) {
375
- if (error.response.status == 422) {
376
- return {
377
- type: 'error',
378
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
379
- }
380
- }
381
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
382
-
383
- return {
384
- type: 'error',
385
- msg: error.response.data.message.body
386
-
387
- }
388
- }
389
- }
211
+ return commonErrorCallback()(error);
390
212
  })
391
213
  },
392
214
  getBlogBySlug({ commit }, blogSlug) {
@@ -395,20 +217,7 @@ const actions = {
395
217
  return { type: 'success', msg: 'ok' }
396
218
  }).catch(error => {
397
219
  commit('setBlog', []);
398
- if(!error.response) return;
399
- const status = error.response.status;
400
- if (status === 422) {
401
- return {
402
- type: 'error',
403
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
404
- }
405
- }
406
- if (status === 401 || status === 403 || status === 404 || status === 400) {
407
- return {
408
- type: 'error',
409
- msg: error.response.data.message.body
410
- }
411
- }
220
+ return commonErrorCallback()(error);
412
221
  })
413
222
  },
414
223
  getTestimonials({ commit }, restaurantId) {
@@ -421,23 +230,8 @@ const actions = {
421
230
  msg: 'ok'
422
231
  }
423
232
  }).catch(error => {
424
- commit('setTestimonials', [])
425
- if (error.response) {
426
- if (error.response.status == 422) {
427
- return {
428
- type: 'error',
429
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
430
- }
431
- }
432
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
433
-
434
- return {
435
- type: 'error',
436
- msg: error.response.data.message.body
437
-
438
- }
439
- }
440
- }
233
+ commit('setTestimonials', []);
234
+ return commonErrorCallback()(error);
441
235
  })
442
236
  },
443
237
  }