orderiom-api-package 0.4.9 → 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.9",
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",
@@ -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 {