ng-miam 6.2.3 → 6.2.4

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.
@@ -3461,6 +3461,7 @@
3461
3461
  _this._basket$ = new rxjs.BehaviorSubject(null);
3462
3462
  _this._basketPreview$ = new rxjs.BehaviorSubject(null);
3463
3463
  _this.basketStats$ = new rxjs.BehaviorSubject(null);
3464
+ _this.canSaveBasket$ = new rxjs.BehaviorSubject(true);
3464
3465
  _this.basketIsFetching = false;
3465
3466
  _this.basketPreviewIsCalculating = false;
3466
3467
  _this.basketInitCalled = false;
@@ -3535,7 +3536,7 @@
3535
3536
  }), operators.switchMap(function (basket) {
3536
3537
  console.log('[Miam] Save basket with confirmed=true');
3537
3538
  basket.attributes.confirmed = true;
3538
- return basket.save();
3539
+ return _this.saveBasket(basket);
3539
3540
  }), operators.switchMap(function (resp) {
3540
3541
  confirmedBasket = _this.new();
3541
3542
  confirmedBasket.fill(resp);
@@ -3604,13 +3605,17 @@
3604
3605
  BasketsService.prototype.updatePricebook = function (pricebookName) {
3605
3606
  var _this = this;
3606
3607
  return this.basket$.pipe(operators.skipWhile(function (b) { return !b; }), operators.take(1), operators.switchMap(function (basket) {
3608
+ if (!pricebookName) {
3609
+ console.log("[Miam] no pricebook " + JSON.stringify(pricebookName));
3610
+ return rxjs.of(basket);
3611
+ }
3607
3612
  if (basket.pricebookKey === pricebookName) {
3608
3613
  console.log("[Miam] same pricebook " + JSON.stringify(pricebookName));
3609
3614
  return rxjs.of(basket);
3610
3615
  }
3611
3616
  console.log("[Miam] update pricebook to " + JSON.stringify(pricebookName));
3612
3617
  basket.pricebookKey = pricebookName;
3613
- return basket.save().pipe(operators.map(function (resp) {
3618
+ return _this.saveBasket(basket).pipe(operators.map(function (resp) {
3614
3619
  var updatedBasket = _this.new();
3615
3620
  updatedBasket.fill(resp);
3616
3621
  _this._basket$.next(updatedBasket);
@@ -3618,6 +3623,13 @@
3618
3623
  }));
3619
3624
  }));
3620
3625
  };
3626
+ BasketsService.prototype.saveBasket = function (basket) {
3627
+ var _this = this;
3628
+ return this.canSaveBasket$.pipe(operators.skipWhile(function (canSave) { return !canSave; }), operators.take(1), operators.switchMap(function () {
3629
+ _this.canSaveBasket$.next(false);
3630
+ return basket.save().pipe(operators.tap(function () { return _this.canSaveBasket$.next(true); }));
3631
+ }));
3632
+ };
3621
3633
  BasketsService.prototype.loadPreview = function () {
3622
3634
  var _this = this;
3623
3635
  return this.basket$.pipe(operators.skipWhile(function (b) { return !b; }), operators.switchMap(function () { return _this.recipesService.loadRecipes(); }), operators.switchMap(function (recipes) {