orderiom-api-package 0.4.79 → 0.4.80

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.4.79",
3
+ "version": "0.4.80",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -31,7 +31,8 @@ const state = () => ({
31
31
  showPinnedProducts: false,
32
32
  fetchingProducts: false,
33
33
  categoriesFetchedOnce: false,
34
- pinnedProductsFetchedOnce: false
34
+ pinnedProductsFetchedOnce: false,
35
+ fetchingProductsHappyHour: false,
35
36
  });
36
37
  const getters = {
37
38
  fetchingProducts(state){
@@ -39,7 +40,7 @@ const getters = {
39
40
  },
40
41
  subCategories(state){
41
42
  if(state.showPinnedProducts) {
42
- if(state.pinnedProducts?.length){
43
+ if(state.pinnedProducts && state.pinnedProducts.length){
43
44
  return [{
44
45
  id: null,
45
46
  imagePath:null,
@@ -50,7 +51,7 @@ const getters = {
50
51
  return []
51
52
  }
52
53
  }
53
- if(!state.products?.length) return []
54
+ if(!state.products || !state.products.length) return [];
54
55
  const subCategories = [];
55
56
  const ids = Array.from(new Set(state.products.map(productInCategory=>
56
57
  productInCategory.subcategory_id
@@ -270,6 +271,9 @@ const mutations = {
270
271
  },
271
272
  setSubCategories(state , subCategories){
272
273
  state.subCategories = subCategories;
274
+ },
275
+ setFetchingProductsHappyHour(state, value){
276
+ state.fetchingProductsHappyHour = value;
273
277
  }
274
278
  };
275
279
  const actions = {
@@ -321,7 +325,7 @@ const actions = {
321
325
  commonErrorCallback()
322
326
  );
323
327
  },
324
- getProducts({ commit, state, rootState }, data) {
328
+ getProducts({ commit, dispatch, state, rootState }, data) {
325
329
  commit("setSelectedCategory", data.category);
326
330
  let basketId = undefined;
327
331
  try {
@@ -359,6 +363,11 @@ const actions = {
359
363
  productInCategory.quantity = quantity;
360
364
  });
361
365
  commit("setProduct", res.data.data);
366
+
367
+ if(rootState.orderiomApiPackage.restaurant.restaurantInfo.ignore_pre_order_timing_by_display){
368
+ dispatch('getProductsHappyHourTime');
369
+ }
370
+
362
371
  return { ...res, data: res.data.data }
363
372
  }).catch(
364
373
  commonErrorCallback()
@@ -366,7 +375,7 @@ const actions = {
366
375
  commit('setFetchingProducts', false);
367
376
  });
368
377
  },
369
- getPinnedProducts({ commit, state, rootState }, data) {
378
+ getPinnedProducts({ commit, state, dispatch, rootState }, data) {
370
379
  let basketId = undefined;
371
380
  try {
372
381
  basketId = calculateBasketIdParameter(
@@ -398,6 +407,10 @@ const actions = {
398
407
  commit("setSelectedCategory", null);
399
408
  commit("setPinnedProducts", res.data.data);
400
409
  commit("setShowPinnedProducts", true);
410
+
411
+ if(rootState.orderiomApiPackage.restaurant.restaurantInfo.ignore_pre_order_timing_by_display){
412
+ dispatch('getProductsHappyHourTime');
413
+ }
401
414
  } else {
402
415
  commit("setShowPinnedProducts", false);
403
416
  }
@@ -408,6 +421,54 @@ const actions = {
408
421
  commit('setPinnedProductsFetchedOnce');
409
422
  });
410
423
  },
424
+ getProductsHappyHourTime({commit, state}){
425
+ if(!state.showPinnedProducts){
426
+ if((!state.products || !state.products.length)) {
427
+ console.error('getProductsHappyHourTime:', 'It is impossible to get products happy hour time before loading the products.');
428
+ return;
429
+ }
430
+ }else{
431
+ if((!state.pinnedProducts || !state.pinnedProducts.length)) {
432
+ console.error('getProductsHappyHourTime:', 'It is impossible to get products happy hour time before loading the products.');
433
+ return;
434
+ }
435
+ }
436
+
437
+ if(!state.showPinnedProducts && (!state.selectedCategory || !state.selectedCategory.id)){
438
+ console.error('getProductsHappyHourTime:', 'selected category is unavailable while showPinnedProducts is false too.');
439
+ }
440
+
441
+ commit('setFetchingProductsHappyHour', true);
442
+ return $http.get('api/restaurant/products-happyHour-time', {
443
+ params: {
444
+ [state.showPinnedProducts ? 'pinned' : 'categoryId']:
445
+ state.showPinnedProducts ? true : state.selectedCategory.id
446
+ }
447
+ }).then(res => {
448
+ const data = res.data.data || [];
449
+ if(!Array.isArray(data)) return {...res, data: []};
450
+
451
+ data.forEach(({happyHour, id: productId}) => {
452
+ if(!happyHour?.length) return;
453
+ const product = state.products.find(product => product.id === productId);
454
+ if(!product) {
455
+ console.log(`Could not assign happyHour:${happyHour.id} to product:${productId}`);
456
+ return;
457
+ }
458
+ product.happyHour = {
459
+ weekday_id: happyHour.weekday_id,
460
+ start_date: happyHour.start_date,
461
+ end_date: happyHour.end_date,
462
+ }
463
+ })
464
+
465
+ return {...res, data};
466
+ }).catch(
467
+ commonErrorCallback()
468
+ ).finally(() => {
469
+ commit('setFetchingProductsHappyHour', false);
470
+ })
471
+ },
411
472
  getBasket({ commit, rootState }, data) {
412
473
  if(['string', 'number', 'undefined'].includes(typeof data)) data = {restaurantId: data};
413
474