@infrab4a/connect-angular 2.0.6-beta.1 → 2.0.6-beta.2

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.
@@ -450,45 +450,56 @@
450
450
  nickname: { operator: i2.Where.EQUALS, value: nickname },
451
451
  active: { operator: i2.Where.EQUALS, value: true },
452
452
  },
453
- })).pipe(operators.concatMap(function (coupons) { return _this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription); }), operators.concatMap(function (coupon) { return _this.checkCouponUseAndLimit(coupon, userEmail); }), operators.map(function (coupon) { return _this.isValidCoupon(coupon, userEmail); }), operators.map(function (coupon) { return coupon; }));
453
+ })).pipe(operators.concatMap(function (coupons) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_d) {
454
+ switch (_d.label) {
455
+ case 0: return [4 /*yield*/, this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)];
456
+ case 1: return [2 /*return*/, _d.sent()];
457
+ }
458
+ }); }); }), operators.concatMap(function (coupon) { return _this.checkCouponUseAndLimit(coupon, userEmail); }), operators.map(function (coupon) { return _this.isValidCoupon(coupon, userEmail); }), operators.map(function (coupon) { return coupon; }));
454
459
  };
455
460
  CouponService.prototype.checkCouponRules = function (coupons, checkoutType, plan, checkout, isSubscription) {
456
- // Caso não ache nenhum cupom, retorna erro
457
- if (coupons.count < 1) {
458
- return rxjs.throwError('Cupom inválido.');
459
- }
460
- // Get Primeiro Cupom (o find do repository retorna um array)
461
- var coupon = coupons.data.shift();
462
- // Verifica se o cupom é aplicavel na loja
463
- var isInShop = coupon.shopAvailability === i2.Shops.ALL || coupon.shopAvailability === this.defaultShop;
464
- // Cupon não aplicavel a loja retorna erro
465
- if (!isInShop)
466
- return rxjs.throwError('Cupom inválido para loja.');
467
- // Verifica se o coupon é aplicado no checkout que está sendo realizado
468
- var isCheckoutType = coupon.checkoutType === i2.CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
469
- // Cupon não aplicavel ao checkout retorna erro
470
- if (!isCheckoutType)
471
- return rxjs.throwError('Cupom inválido. Erro de checkout.');
472
- // Verifica se o cupom é ou pode ser aplicado para subscription
473
- if (checkoutType === i2.CheckoutTypes.ALL || checkoutType === i2.CheckoutTypes.SUBSCRIPTION) {
474
- // Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
475
- if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
476
- return rxjs.throwError('Cupom inválido para sua assinatura.');
477
- }
478
- if (isSubscription)
479
- return rxjs.of(coupon);
480
- // Verifica se possui o valor minimo de compra para utilização do cupom
481
- var hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
482
- // Se não tem valor mínimo atingido, retorna erro
483
- if (!hasMinSubTotal)
484
- return rxjs.throwError('Valor mínimo não atingido');
485
- // Verifica se a compra possui produtos elegíveis para desconto
486
- var hasProductCategories = this.hasProductCategories(coupon, checkout);
487
- console.log('hasProductCategories', hasProductCategories);
488
- // Se não tem produtos elegíveis, retorna erro
489
- if (!hasProductCategories)
490
- return rxjs.throwError('Seu carrinho não possui produtos elegíveis para desconto.');
491
- return rxjs.of(coupon);
461
+ return __awaiter(this, void 0, void 0, function () {
462
+ var coupon, isInShop, isCheckoutType, hasMinSubTotal, hasProductCategories;
463
+ return __generator(this, function (_d) {
464
+ switch (_d.label) {
465
+ case 0:
466
+ // Caso não ache nenhum cupom, retorna erro
467
+ if (coupons.count < 1) {
468
+ return [2 /*return*/, rxjs.throwError('Cupom inválido.')];
469
+ }
470
+ coupon = coupons.data.shift();
471
+ isInShop = coupon.shopAvailability === i2.Shops.ALL || coupon.shopAvailability === this.defaultShop;
472
+ // Cupon não aplicavel a loja retorna erro
473
+ if (!isInShop)
474
+ return [2 /*return*/, rxjs.throwError('Cupom inválido para loja.')];
475
+ isCheckoutType = coupon.checkoutType === i2.CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
476
+ // Cupon não aplicavel ao checkout retorna erro
477
+ if (!isCheckoutType)
478
+ return [2 /*return*/, rxjs.throwError('Cupom inválido. Erro de checkout.')];
479
+ // Verifica se o cupom é ou pode ser aplicado para subscription
480
+ if (checkoutType === i2.CheckoutTypes.ALL || checkoutType === i2.CheckoutTypes.SUBSCRIPTION) {
481
+ // Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
482
+ if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
483
+ return [2 /*return*/, rxjs.throwError('Cupom inválido para sua assinatura.')];
484
+ }
485
+ if (isSubscription)
486
+ return [2 /*return*/, rxjs.of(coupon)];
487
+ hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
488
+ // Se não tem valor mínimo atingido, retorna erro
489
+ if (!hasMinSubTotal)
490
+ return [2 /*return*/, rxjs.throwError('Valor mínimo não atingido')];
491
+ return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
492
+ case 1:
493
+ hasProductCategories = _d.sent();
494
+ console.log('hasProductCategories', hasProductCategories);
495
+ // Se não tem produtos elegíveis, retorna erro
496
+ if (!hasProductCategories)
497
+ return [2 /*return*/, rxjs.throwError('Seu carrinho não possui produtos elegíveis para desconto.')];
498
+ // return of(coupon)
499
+ return [2 /*return*/, coupon];
500
+ }
501
+ });
502
+ });
492
503
  };
493
504
  CouponService.prototype.isValidCoupon = function (coupon, userEmail) {
494
505
  // Verifica a data de inicio de validade do cupom
@@ -594,36 +605,42 @@
594
605
  return false;
595
606
  };
596
607
  CouponService.prototype.hasProductCategories = function (coupon, checkout) {
597
- var _this = this;
598
608
  var _a;
599
- if (coupon.productsCategories && coupon.productsCategories.length) {
600
- var hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
601
- var _a;
602
- if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
603
- // buscar categoria por id
604
- // filtrar por id ou firestore id
605
- return i.categories.some(function (c) { return __awaiter(_this, void 0, void 0, function () {
606
- var categoria;
607
- return __generator(this, function (_d) {
608
- switch (_d.label) {
609
- case 0: return [4 /*yield*/, this.categoryRepository.get({ id: c })];
610
- case 1:
611
- categoria = _d.sent();
612
- console.log(categoria);
613
- console.log(coupon.productsCategories.includes(categoria.id), coupon.productsCategories.includes(categoria.firestoreId), i.isGift);
614
- console.log('validation', (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift);
615
- return [2 /*return*/, (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift];
616
- }
617
- });
618
- }); });
609
+ return __awaiter(this, void 0, void 0, function () {
610
+ var hasCategories;
611
+ var _this = this;
612
+ return __generator(this, function (_d) {
613
+ if (coupon.productsCategories && coupon.productsCategories.length) {
614
+ hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
615
+ var _a;
616
+ if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
617
+ // buscar categoria por id
618
+ // filtrar por id ou firestore id
619
+ return i.categories.some(function (c) { return __awaiter(_this, void 0, void 0, function () {
620
+ var categoria;
621
+ return __generator(this, function (_d) {
622
+ switch (_d.label) {
623
+ case 0: return [4 /*yield*/, this.categoryRepository.get({ id: c })];
624
+ case 1:
625
+ categoria = _d.sent();
626
+ console.log(categoria);
627
+ console.log(coupon.productsCategories.includes(categoria.id), coupon.productsCategories.includes(categoria.firestoreId), i.isGift);
628
+ console.log('validation', (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift);
629
+ return [2 /*return*/, (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift];
630
+ }
631
+ });
632
+ }); });
633
+ }
634
+ return true;
635
+ });
636
+ return [2 /*return*/, hasCategories.length ? true : false];
619
637
  }
620
- return true;
638
+ else {
639
+ return [2 /*return*/, true];
640
+ }
641
+ return [2 /*return*/];
621
642
  });
622
- return hasCategories.length ? true : false;
623
- }
624
- else {
625
- return true;
626
- }
643
+ });
627
644
  };
628
645
  CouponService.prototype.userValidationAndSubscriptionStatus = function (coupon, userEmail) {
629
646
  return __awaiter(this, void 0, void 0, function () {