orderiom-api-package 0.3.0 → 0.3.2

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.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -364,49 +364,48 @@ const actions = {
364
364
  basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
365
365
  } catch(e) {
366
366
  console.error(e);
367
- return { type: 'error', msg: 'Basket not found' }
367
+ return { type: 'error', msg: 'Basket not found', data: [] }
368
368
  }
369
369
 
370
- const result = [];
370
+ const list = (categories || state.categories);
371
371
 
372
372
  // TODO: It is recommended to use a new api instead of multiple api calls inside a loop.
373
- (categories || state.categories).forEach(category => {
373
+ return Promise.all(list.map(category =>
374
374
  axios.get("api/restaurant/products", {
375
375
  params: {
376
- categoryId: data.category.id,
376
+ categoryId: category.id,
377
377
  restaurantId,
378
378
  basketId
379
379
  }
380
- }).then(res => {
381
- const products = res.data.data;
382
- products.forEach(m => {
383
- const productFoundInShoppingCart = state.ShoppingCart.find(p => p.RestaurantProductId === m.id);
384
- if (!productFoundInShoppingCart) {
385
- m.quantity = 0;
386
- return;
387
- }
388
-
389
- if (!m.is_package) {
390
- m.quantity = productFoundInShoppingCart.quantity;
391
- return;
392
- }
393
-
394
- let qty = 0;
395
- state.ShoppingCart.forEach(b => {
396
- if (b.RestaurantProductId !== m.id) return;
397
- qty += b.quantity;
398
- });
399
- m.quantity = qty;
400
- })
401
-
402
- result.push({...category, products});
403
-
404
- }).catch(
405
- commonErrorCallback()
406
- );
407
- });
408
-
409
- return result
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
+ })
410
409
  },
411
410
  };
412
411
 
@@ -212,7 +212,7 @@ const actions = {
212
212
  })
213
213
  },
214
214
  getBlogBySlug({ commit }, blogSlug) {
215
- return axios.get('api/blogs/show/slug', { params: {blogSlug}}).then(res => {
215
+ return axios.get('api/blogs/show/slug', { params: {blogSlug, restaurantId}}).then(res => {
216
216
  commit('setBlog', res.data.data);
217
217
  return { type: 'success', msg: 'ok' }
218
218
  }).catch(error => {