orderiom-api-package 0.2.58 → 0.3.1

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.58",
3
+ "version": "0.3.1",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -158,5 +158,9 @@
158
158
  "pattern_successfully_updated": "Muster erfolgreich aktualisiert.",
159
159
  "start_or_end_date_break_is_required": "Start oder Enddatum unterbrechung ist erforderlich.",
160
160
  "pattern_is_required": "Sie müssen Ihrem Muster Produkte hinzufügen.",
161
- "newsletter_successfully_added": "Ihre E-Mail wurde erfolgreich hinzugefügt."
161
+ "newsletter_successfully_added": "Ihre E-Mail wurde erfolgreich hinzugefügt.",
162
+ "There was an error in fetching the blogs": "Beim Abrufen der Blogs ist ein Fehler aufgetreten",
163
+ "There was an error in fetching the blog": "Beim Abrufen des Blogs ist ein Fehler aufgetreten",
164
+ "Something went wrong": "Etwas ist schief gelaufen",
165
+ "Basket not found": "Korb nicht gefunden"
162
166
  }
@@ -158,5 +158,9 @@
158
158
  "pattern_successfully_updated": "pattern successfully updated.",
159
159
  "start_or_end_date_break_is_required": "start or end date break is required.",
160
160
  "pattern_is_required": "you have to add products to your pattern.",
161
- "newsletter_successfully_added": "Your email has been added successfuly."
161
+ "newsletter_successfully_added": "Your email has been added successfuly.",
162
+ "There was an error in fetching the blogs": "There was an error in fetching the blogs",
163
+ "There was an error in fetching the blog": "There was an error in fetching the blog",
164
+ "Something went wrong": "Something went wrong",
165
+ "Basket not found": "Basket not found"
162
166
  }
@@ -703,14 +703,15 @@ const actions = {
703
703
  return {type: 'error', msg: 'Basket not found'};
704
704
  }
705
705
 
706
- axios.post('api/basket/update-extraInfo', {
706
+ return axios.post('api/basket/update-extraInfo', {
707
707
  basketId,
708
708
  ...data
709
709
  }).then(res =>
710
710
  updateBasket({commit, basketId, res, isOutsideProduct: true})
711
- ).catch(
712
- commonErrorCallback()
713
- );
711
+ ).catch(err => {
712
+ console.error(err);
713
+ return false;
714
+ });
714
715
  }
715
716
  }
716
717
  export default {
@@ -357,7 +357,56 @@ const actions = {
357
357
  }).finally(() => {
358
358
  commit('finishChangingDeliveryType');
359
359
  });
360
- }
360
+ },
361
+ getProductsFromAllCategories({ commit, state, rootState }, categories = null) {
362
+ let basketId = undefined;
363
+ try{
364
+ basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
365
+ } catch(e) {
366
+ console.error(e);
367
+ return { type: 'error', msg: 'Basket not found', data: [] }
368
+ }
369
+
370
+ const list = (categories || state.categories);
371
+
372
+ // TODO: It is recommended to use a new api instead of multiple api calls inside a loop.
373
+ return Promise.all(list.map(category =>
374
+ axios.get("api/restaurant/products", {
375
+ params: {
376
+ categoryId: category.id,
377
+ restaurantId,
378
+ basketId
379
+ }
380
+ })
381
+ )).then(resArray => ({
382
+ type: 'success',
383
+ msg: '',
384
+ data: resArray.map((res, resIndex) => ({
385
+ ...list[resIndex],
386
+ products: res.data.data
387
+ }))
388
+ })).catch(error => {
389
+ const status = error.response ? error.response.status : null;
390
+ if (status === 422) {
391
+ return {
392
+ type: 'error',
393
+ msg: Object.values(error.response.data.error.validation).map(m => m[0]).toString(),
394
+ data: []
395
+ }
396
+ } else if ([401, 403, 404, 400].includes(status)) {
397
+ return {
398
+ type: 'error',
399
+ msg: error.response.data.message.body,
400
+ data: []
401
+ }
402
+ }
403
+ return {
404
+ type: 'error',
405
+ msg: 'Something went wrong',
406
+ data: []
407
+ }
408
+ })
409
+ },
361
410
  };
362
411
 
363
412
  export default {