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 +1 -1
- package/src/modules/product.js +53 -53
- package/src/modules/restaurant.js +1 -1
package/package.json
CHANGED
package/src/modules/product.js
CHANGED
|
@@ -232,61 +232,61 @@ const actions = {
|
|
|
232
232
|
},
|
|
233
233
|
getProducts({ commit, state }, data) {
|
|
234
234
|
commit("setSelectedCategory", data.category);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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: '
|
|
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
|
-
'
|
|
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: '
|
|
476
|
+
return { type: 'error', msg: 'There was an error in updating the delivery type' }
|
|
477
477
|
}).finally(() => {
|
|
478
478
|
commit('finishChangingDeliveryType');
|
|
479
479
|
});
|