orderiom-api-package 0.2.37 → 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.37",
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"));