ng-miam 9.0.11 → 9.0.12

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.
@@ -5709,20 +5709,13 @@
5709
5709
  * Fetches the BasketEntry for an ingredient if it exists
5710
5710
  * Returns a fake BasketEntry with id = -1 if it doesn't exist
5711
5711
  */
5712
- BasketsService.prototype.basketEntryFromIngredient = function (ingredientId, guests, onlyQuantity, selectedItemId) {
5712
+ BasketsService.prototype.basketEntryFromIngredient = function (ingredientId, guests, selectedItemId) {
5713
5713
  var _this = this;
5714
- if (onlyQuantity === void 0) { onlyQuantity = false; }
5715
5714
  return this.waitForBasket.pipe(operators.switchMap(function (basket) {
5716
- var url = environment$1.miamAPI + "/api/v1/baskets/" + basket.id + "/basket-entries/from-ingredient?ingredient_id=" + ingredientId + "&guests=" + guests;
5715
+ var url = environment$1.miamAPI + "/api/v1/baskets/" + basket.id + "/basket-entries/from-ingredient?ingredient_id=" + ingredientId + "&guests=" + guests + "&include=selected-item";
5717
5716
  if (selectedItemId) {
5718
5717
  url += "&selected_item_id=" + selectedItemId;
5719
5718
  }
5720
- if (onlyQuantity) {
5721
- url += '&fields[basket-entries]=quantity,quantity-to-add';
5722
- }
5723
- else {
5724
- url += '&include=selected-item';
5725
- }
5726
5719
  return _this.http.get(url);
5727
5720
  }), operators.skipWhile(function (result) { return !result; }), operators.map(function (res) {
5728
5721
  var entry = _this.basketEntriesService.new();
@@ -10032,14 +10025,24 @@
10032
10025
  if (!fromInit) {
10033
10026
  this.ingredientToBasketLoading = true;
10034
10027
  }
10035
- var basketEntries$ = this.recipe.ingredients.map(function (ingredient) { return _this.basketsService.basketEntryFromIngredient(ingredient.id, _this.recipe.modifiedGuests, !fromInit).pipe(operators.map(function (basketEntry) { return ({ ingredient: ingredient, basketEntry: basketEntry }); })); });
10028
+ var basketEntries$ = this.recipe.ingredients.map(function (ingredient) { return _this.basketsService.basketEntryFromIngredient(ingredient.id, _this.recipe.modifiedGuests).pipe(operators.map(function (basketEntry) { return ({ ingredient: ingredient, basketEntry: basketEntry }); })); });
10036
10029
  return rxjs.forkJoin(basketEntries$).pipe(operators.switchMap(function (basketEntriesResult) {
10037
- if (fromInit) {
10030
+ var updateProducts = function () {
10038
10031
  _this.products = basketEntriesResult;
10039
- return _this.setProductsByCategory();
10032
+ _this.setProductsByCategory();
10033
+ };
10034
+ if (fromInit) {
10035
+ updateProducts();
10036
+ return rxjs.of([]);
10040
10037
  }
10041
10038
  else {
10042
- _this.updatePriceOnGuestChange(basketEntriesResult);
10039
+ var hasSelectedItemChanged = basketEntriesResult.some(function (incomingProduct) { return _this.products.some(function (p) { return p.basketEntry.attributes['selected-item-id'] ===
10040
+ incomingProduct.basketEntry.attributes['selected-item-id']; }); });
10041
+ // If at least one selected item has changed, we need to refresh categories
10042
+ // and prices entirely instead of only updating quantities
10043
+ hasSelectedItemChanged
10044
+ ? updateProducts()
10045
+ : _this.updatePriceOnGuestChange(basketEntriesResult);
10043
10046
  return rxjs.of(_this.products);
10044
10047
  }
10045
10048
  }), operators.switchMap(function () { return rxjs.of(_this.products); }));
@@ -17011,7 +17014,7 @@
17011
17014
  _this.rollbackReplace();
17012
17015
  });
17013
17016
  this.basketSynchroService.addToActionList([removeIngredient]);
17014
- this.subscriptions.push(this.basketsService.basketEntryFromIngredient(this.ingredient.id, +this.recipe.modifiedGuests, true, item.id).pipe(operators.switchMap(function (newEntry) {
17017
+ this.subscriptions.push(this.basketsService.basketEntryFromIngredient(this.ingredient.id, +this.recipe.modifiedGuests, item.id).pipe(operators.switchMap(function (newEntry) {
17015
17018
  var newBasketEntry = deepCloneWithClass(_this.basketEntry);
17016
17019
  newBasketEntry.quantityToAdd = newEntry.quantityToAdd;
17017
17020
  _this.replaceRelationship(newBasketEntry, item);
@@ -17039,7 +17042,7 @@
17039
17042
  };
17040
17043
  ReplaceItemComponent.prototype.addToBasket = function (item) {
17041
17044
  var _this = this;
17042
- this.subscriptions.push(this.recipeDetailsService.canAddProductToBasket(this.getAddIngredientMethod(), this.eventTrace).pipe(operators.filter(function (passed) { return passed; }), operators.switchMap(function () { return _this.basketsService.basketEntryFromIngredient(_this.ingredient.id, +_this.recipe.modifiedGuests, true, item.id); })).subscribe(function (newEntry) { return _this.handleAddToBasketResponse(newEntry); }));
17045
+ this.subscriptions.push(this.recipeDetailsService.canAddProductToBasket(this.getAddIngredientMethod(), this.eventTrace).pipe(operators.filter(function (passed) { return passed; }), operators.switchMap(function () { return _this.basketsService.basketEntryFromIngredient(_this.ingredient.id, +_this.recipe.modifiedGuests, item.id); })).subscribe(function (newEntry) { return _this.handleAddToBasketResponse(newEntry); }));
17043
17046
  this.cdr.detectChanges();
17044
17047
  };
17045
17048
  ReplaceItemComponent.prototype.getAddIngredientMethod = function () {