@infrab4a/connect-angular 3.10.0-beta.7 → 3.10.0-beta.8

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.
@@ -439,7 +439,7 @@
439
439
  };
440
440
  CouponService.prototype.couponRulesValidation = function (coupon, checkoutType, checkout, plan) {
441
441
  return __awaiter(this, void 0, void 0, function () {
442
- var orders, ordersWithUser, validUser, hasProductCategories, hasMinSubTotal;
442
+ var validUser, orders, ordersWithUser, couponUseLimits, hasProductCategories, hasMinSubTotal;
443
443
  return __generator(this, function (_c) {
444
444
  switch (_c.label) {
445
445
  case 0:
@@ -448,17 +448,18 @@
448
448
  throw 'Cupom inválido para sua assinatura.';
449
449
  return [2 /*return*/, coupon];
450
450
  }
451
+ validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
452
+ if (!validUser)
453
+ throw 'Usuário não elegível.';
451
454
  return [4 /*yield*/, this.getOrdersWithCoupon(coupon)];
452
455
  case 1:
453
456
  orders = _c.sent();
454
457
  ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
455
- if (coupon.useLimitPerUser && ordersWithUser > 0)
458
+ couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
459
+ if (couponUseLimits.useLimitPerUser && ordersWithUser > 0)
456
460
  throw 'Limite de uso por usuário atingido.';
457
- if (!coupon.unlimited && coupon.useLimit && orders.length >= coupon.useLimit)
461
+ if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
458
462
  throw 'Limite de uso atingido.';
459
- validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
460
- if (!validUser)
461
- throw 'Usuário não elegível.';
462
463
  return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
463
464
  case 2:
464
465
  hasProductCategories = _c.sent();
@@ -674,6 +675,16 @@
674
675
  CouponService.prototype.countOrdersWithUser = function (orders, email) {
675
676
  return orders.filter(function (o) { return o.user.email == email; }).length;
676
677
  };
678
+ CouponService.prototype.getCouponUseLimits = function (coupon, checkoutType, user) {
679
+ var couponUseLimits;
680
+ if (checkoutType == i3.CheckoutTypes.ECOMMERCE || checkoutType == i3.CheckoutTypes.ALL) {
681
+ couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
682
+ }
683
+ else {
684
+ couponUseLimits = coupon.useLimits.subscription;
685
+ }
686
+ return couponUseLimits;
687
+ };
677
688
  return CouponService;
678
689
  }());
679
690
  CouponService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });