orderiom-api-package 0.2.36 → 0.2.38

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.36",
3
+ "version": "0.2.38",
4
4
  "description": "this package will install all neccessary api calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -232,61 +232,61 @@ const actions = {
232
232
  },
233
233
  getProducts({ commit, state }, data) {
234
234
  commit("setSelectedCategory", data.category);
235
- return axios
236
- .get("api/restaurant/products", { params: { categoryId: data.category.id, restaurantId: data.restaurantId } })
237
- .then((res) => {
238
- let products = res.data.data;
239
- products.map(m => {
240
- if (state.ShoppingCart.find(
241
- (p) => p.RestaurantProductId == m.id
242
- )) {
243
- if (!m.is_package) {
244
- Vue.set(m, 'quantity', state.ShoppingCart.find(
245
- (p) => p.RestaurantProductId == m.id
246
- ).quantity)
247
- }
248
- else {
249
- const productsInBasket = [];
250
- state.ShoppingCart.map(b => {
251
- if (b.RestaurantProductId == m.id) {
252
- productsInBasket.push(
253
- b.quantity
254
- );
255
- }
256
- });
257
- let qty = productsInBasket.reduce(function (a, b) {
258
- return a + b;
259
- }, 0);
260
- Vue.set(m, 'quantity', qty)
261
- }
262
- } else {
263
- Vue.set(m, 'quantity', 0)
235
+
236
+ const params = {
237
+ categoryId: data.category.id,
238
+ restaurantId: data.restaurantId,
239
+ };
240
+ if(data.deliveryType) params.deliveryType = data.deliveryType;
241
+
242
+ return axios.get("api/restaurant/products", params).then(res => {
243
+ let products = res.data.data;
244
+ products.map(m => {
245
+ if (state.ShoppingCart.find(
246
+ (p) => p.RestaurantProductId == m.id
247
+ )) {
248
+ if (!m.is_package) {
249
+ Vue.set(m, 'quantity', state.ShoppingCart.find(
250
+ (p) => p.RestaurantProductId == m.id
251
+ ).quantity)
264
252
  }
265
- })
266
- commit("setProduct", products);
267
- return {
268
- type: 'success',
269
- data: products
253
+ else {
254
+ const productsInBasket = [];
255
+ state.ShoppingCart.map(b => {
256
+ if (b.RestaurantProductId == m.id) {
257
+ productsInBasket.push(
258
+ b.quantity
259
+ );
260
+ }
261
+ });
262
+ let qty = productsInBasket.reduce(function (a, b) {
263
+ return a + b;
264
+ }, 0);
265
+ Vue.set(m, 'quantity', qty)
266
+ }
267
+ } else {
268
+ Vue.set(m, 'quantity', 0)
270
269
  }
271
270
  })
272
- .catch((error) => {
273
- if (error.response) {
274
- if (error.response.status == 422) {
275
- return {
276
- type: 'error',
277
- msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
278
- }
279
- }
280
- if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
281
-
282
- return {
283
- type: 'error',
284
- msg: error.response.data.message.body
285
- }
286
- }
271
+ commit("setProduct", products);
272
+ return { type: 'success', data: products }
273
+ }).catch(error => {
274
+ if(!error.response) return;
287
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()
288
281
  }
289
- });
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
290
  },
291
291
  getBasket({ commit, rootState }, restaurantId) {
292
292
  const basket = JSON.parse(localStorage.getItem("basket"));
@@ -456,7 +456,7 @@ const actions = {
456
456
  restaurantId: !basketId ? restaurantId : undefined
457
457
  }).then(async res => {
458
458
  if(res.data.message.type !== 'success'){
459
- return { type: 'error', msg: 'Could not update delivery type' }
459
+ return { type: 'error', msg: 'There was an error in updating the delivery type' }
460
460
  }
461
461
 
462
462
  const result = await dispatch("getBasket", restaurantId);
@@ -464,7 +464,7 @@ const actions = {
464
464
  return {
465
465
  type: result ? 'success' : 'error',
466
466
  msg: !result ?
467
- 'Could not get basket info'
467
+ 'There was an error in fetching the basket info'
468
468
  :
469
469
  rootState.orderiomApiPackage.product.ShoppingCart.length < shoppingCartItems ?
470
470
  'Some items are removed from the cart'
@@ -473,7 +473,7 @@ const actions = {
473
473
  }
474
474
  }).catch(err => {
475
475
  console.error(err);
476
- return { type: 'error', msg: 'Could not update delivery type' }
476
+ return { type: 'error', msg: 'There was an error in updating the delivery type' }
477
477
  }).finally(() => {
478
478
  commit('finishChangingDeliveryType');
479
479
  });
@@ -294,7 +294,7 @@ const actions = {
294
294
  if(!error.response){
295
295
  return {
296
296
  type: 'error',
297
- msg: 'Could not fetch blogs',
297
+ msg: 'There was an error in fetching the blogs',
298
298
  tagName: ''
299
299
  }
300
300
  }