orderiom-api-package 0.2.49 → 0.2.50
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 +1 -1
- package/src/modules/order.js +56 -37
- package/src/modules/product.js +11 -6
package/package.json
CHANGED
package/src/modules/order.js
CHANGED
|
@@ -350,50 +350,69 @@ const actions = {
|
|
|
350
350
|
});
|
|
351
351
|
},
|
|
352
352
|
deleteFromBasket({ dispatch, rootState }, data) {
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
|
|
354
|
+
f.RestaurantProductId === Number(data.productId)
|
|
355
355
|
);
|
|
356
|
+
|
|
357
|
+
if(!basketProduct){
|
|
358
|
+
return {
|
|
359
|
+
type: 'error',
|
|
360
|
+
msg: 'Product not found'
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
356
364
|
const basket = JSON.parse(localStorage.getItem("basket"));
|
|
357
365
|
const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
|
|
358
366
|
basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
|
|
359
367
|
} : {}
|
|
360
|
-
axios
|
|
361
|
-
.get("api/basket/delete-basket-product", {
|
|
362
|
-
params: {
|
|
363
|
-
...basketId,
|
|
364
|
-
basketProductId: item.basketProductId,
|
|
365
|
-
restaurantId: data.restaurantId,
|
|
366
|
-
},
|
|
367
|
-
})
|
|
368
|
-
.then(() => {
|
|
369
|
-
dispatch("product/getBasket", data.restaurantId, { root: true }).then(() => {
|
|
370
|
-
dispatch(
|
|
371
|
-
"product/getProducts",
|
|
372
|
-
{ category: rootState.orderiomApiPackage.product.selectedCategory, restaurantId: data.restaurantId }, { root: true }
|
|
373
|
-
);
|
|
374
|
-
})
|
|
375
|
-
})
|
|
376
|
-
.catch((error) => {
|
|
377
|
-
if (error.response) {
|
|
378
|
-
if (error.response.status == 422) {
|
|
379
|
-
return {
|
|
380
|
-
type: 'error',
|
|
381
|
-
msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
if (error.response.status == 401 || error.response.status == 403 || error.response.status == 404 || error.response.status == 400) {
|
|
386
|
-
|
|
387
|
-
return {
|
|
388
|
-
type: 'error',
|
|
389
|
-
msg: error.response.data.message.body
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
368
|
|
|
369
|
+
basketProduct.deleting = true;
|
|
370
|
+
return axios.get("api/basket/delete-basket-product", {
|
|
371
|
+
params: {
|
|
372
|
+
...basketId,
|
|
373
|
+
basketProductId: basketProduct.basketProductId,
|
|
374
|
+
restaurantId: data.restaurantId,
|
|
375
|
+
},
|
|
376
|
+
}).then(async () => {
|
|
377
|
+
const getBasketSuccess = await dispatch("product/getBasket", data.restaurantId, { root: true });
|
|
378
|
+
const getProductsResult = await dispatch(
|
|
379
|
+
"product/getProducts",
|
|
380
|
+
{
|
|
381
|
+
category: rootState.orderiomApiPackage.product.selectedCategory,
|
|
382
|
+
restaurantId: data.restaurantId
|
|
383
|
+
},
|
|
384
|
+
{ root: true }
|
|
385
|
+
);
|
|
386
|
+
if(!getBasketSuccess || getProductsResult.type !== 'success'){
|
|
387
|
+
return {
|
|
388
|
+
type: 'error',
|
|
389
|
+
msg: 'There was an error in fetching basket and products'
|
|
394
390
|
}
|
|
395
|
-
|
|
396
|
-
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
type: 'success',
|
|
394
|
+
msg: ''
|
|
395
|
+
}
|
|
396
|
+
}).catch(error => {
|
|
397
|
+
const status = error.response ? error.response.status : null;
|
|
398
|
+
if (status === 422) {
|
|
399
|
+
return {
|
|
400
|
+
type: 'error',
|
|
401
|
+
msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
|
|
402
|
+
}
|
|
403
|
+
} else if ([401, 403, 404, 400].includes(status)) {
|
|
404
|
+
return {
|
|
405
|
+
type: 'error',
|
|
406
|
+
msg: error.response.data.message.body
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return {
|
|
410
|
+
type: 'error',
|
|
411
|
+
msg: 'Something went wrong'
|
|
412
|
+
}
|
|
413
|
+
}).finally(() => {
|
|
414
|
+
basketProduct.deleting = false;
|
|
415
|
+
});
|
|
397
416
|
},
|
|
398
417
|
deleteFromBasketWithAttr({ dispatch, rootState }, data) {
|
|
399
418
|
const basket = JSON.parse(localStorage.getItem("basket"));
|
package/src/modules/product.js
CHANGED
|
@@ -69,7 +69,11 @@ const mutations = {
|
|
|
69
69
|
state.selectedProduct = product
|
|
70
70
|
},
|
|
71
71
|
SetShoppingCart(state, products) {
|
|
72
|
-
state.ShoppingCart = products
|
|
72
|
+
state.ShoppingCart = products.map(item => ({
|
|
73
|
+
...item,
|
|
74
|
+
deleting: false,
|
|
75
|
+
changingQuantity: false,
|
|
76
|
+
}));
|
|
73
77
|
},
|
|
74
78
|
SetSubtotalPrice(state, SubtotalPrice) {
|
|
75
79
|
state.SubtotalPrice = SubtotalPrice;
|
|
@@ -299,21 +303,22 @@ const actions = {
|
|
|
299
303
|
commit("setProduct", products);
|
|
300
304
|
return { type: 'success', data: products }
|
|
301
305
|
}).catch(error => {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const status = error.response.status;
|
|
306
|
+
const status = error.response ? error.response.status : null;
|
|
305
307
|
if (status === 422) {
|
|
306
308
|
return {
|
|
307
309
|
type: 'error',
|
|
308
310
|
msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
|
|
309
311
|
}
|
|
310
|
-
}
|
|
311
|
-
if ([401, 403, 404, 400].includes(status)) {
|
|
312
|
+
} else if ([401, 403, 404, 400].includes(status)) {
|
|
312
313
|
return {
|
|
313
314
|
type: 'error',
|
|
314
315
|
msg: error.response.data.message.body
|
|
315
316
|
}
|
|
316
317
|
}
|
|
318
|
+
return {
|
|
319
|
+
type: 'error',
|
|
320
|
+
msg: 'Something went wrong'
|
|
321
|
+
}
|
|
317
322
|
});
|
|
318
323
|
},
|
|
319
324
|
getBasket({ commit, rootState }, restaurantId) {
|