orderiom-api-package 0.4.8 → 0.4.10

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.8",
3
+ "version": "0.4.10",
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",
@@ -197,7 +197,8 @@ const actions = {
197
197
  assignBasket({ dispatch }, restaurantId) {
198
198
  const basket = JSON.parse(localStorage.getItem("basket"));
199
199
  if(!basket || !Array.isArray(basket)) return;
200
- const basketId = basket.find(item => Number(item.restaurantId) === Number(restaurantId || restaurantIdEnv))?.basketId
200
+ const foundBasket = basket.find(item => Number(item.restaurantId) === Number(restaurantId || restaurantIdEnv))
201
+ const basketId = foundBasket ? foundBasket.basketId : undefined;
201
202
 
202
203
  basketId && $http
203
204
  .post(`api/basket/assign-basket`, null, { params: { basketId: basketId, restaurantId: restaurantId } })
@@ -214,7 +215,9 @@ const actions = {
214
215
  let baskets = [];
215
216
 
216
217
  if (restaurantId || restaurantIdEnv) {
217
- const basketId = basket.find(item => Number(item.restaurantId) === Number(restaurantId || restaurantIdEnv))?.basketId
218
+ const foundBasket = basket.find(item => Number(item.restaurantId) === Number(restaurantId || restaurantIdEnv))
219
+ const basketId = foundBasket ? foundBasket.basketId : undefined;
220
+
218
221
  if(basketId) baskets.push(basketId);
219
222
  } else {
220
223
  baskets = basket.map(m => m.basketId)
@@ -27,10 +27,20 @@ const state = () => ({
27
27
  fetchingBasket: false,
28
28
  changingDeliveryType: false,
29
29
  basketLoadedOnce: false,
30
+ pinnedProducts: null,
31
+ showPinnedProducts: false
30
32
  });
31
33
  const getters = {
32
34
  subCategories(state){
33
35
  if(!state.products) return []
36
+ if(state.showPinnedProducts) {
37
+ return [{
38
+ id: null,
39
+ imagePath:null,
40
+ name:null,
41
+ priority:null
42
+ }]
43
+ }
34
44
  const subCategories = [];
35
45
  const ids = Array.from(new Set(state.products.map(productInCategory=>
36
46
  productInCategory.subcategory_id
@@ -67,6 +77,12 @@ const mutations = {
67
77
  setProduct(state, product) {
68
78
  state.products = product
69
79
  },
80
+ setPinnedProducts(state, products) {
81
+ state.pinnedProducts = products
82
+ },
83
+ setShowPinnedProducts(state, show) {
84
+ state.showPinnedProducts = show;
85
+ },
70
86
  setSelectedProduct(state, product) {
71
87
  state.selectedProduct = product
72
88
  },
@@ -227,6 +243,46 @@ const actions = {
227
243
  commonErrorCallback()
228
244
  );
229
245
  },
246
+ getPinnedProducts({ commit, state, rootState }, data) {
247
+ let basketId = undefined;
248
+ try {
249
+ basketId = calculateBasketIdParameter(
250
+ !!rootState.orderiomApiPackage.auth.privateToken,
251
+ data ? data.restaurantId : undefined
252
+ );
253
+ } catch(e) {
254
+ console.error("getPinnedProducts: " + e);
255
+ }
256
+ return $http.get("api/restaurant/pinned-products", {
257
+ params: {
258
+ restaurantId: data.restaurantId,
259
+ basketId: basketId
260
+ }
261
+ }).then(res => {
262
+ if (res.status !== 200) {
263
+ return;
264
+ }
265
+ if (res.data.data.length) {
266
+ res.data.data.forEach(productInCategory => {
267
+ let quantity = 0;
268
+ state.ShoppingCart
269
+ .filter(itemInCart => Number(itemInCart.RestaurantProductId) === Number(productInCategory.id))
270
+ .forEach((item) => quantity += item.quantity);
271
+ productInCategory.quantity = quantity;
272
+ productInCategory.subcategory_id = null;
273
+ });
274
+ commit("setAttributeItems", []);
275
+ commit("setSelectedCategory", null);
276
+ commit("setPinnedProducts", res.data.data);
277
+ commit("setShowPinnedProducts", true);
278
+ } else {
279
+ commit("setShowPinnedProducts", false);
280
+ }
281
+ return { type: 'success', data: res.data.data }
282
+ }).catch(
283
+ commonErrorCallback()
284
+ );
285
+ },
230
286
  getBasket({ commit, rootState }, data) {
231
287
  if(typeof data === 'string' || typeof data === 'number') data = {restaurantId: data};
232
288
 
@@ -347,6 +403,10 @@ const actions = {
347
403
  dispatch('getCategories', (restaurantId || restaurantIdEnv));
348
404
  }
349
405
 
406
+ if (rootState.orderiomApiPackage.product.showPinnedProducts) {
407
+ dispatch("getPinnedProducts", restaurantId);
408
+ }
409
+
350
410
  const result = await dispatch("getBasket", (restaurantId || restaurantIdEnv));
351
411
 
352
412
  return {