@infrab4a/connect-angular 2.0.6-beta.5 → 2.0.6-beta.7

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.
@@ -597,41 +597,41 @@
597
597
  CouponService.prototype.hasProductCategories = function (coupon, checkout) {
598
598
  var _a;
599
599
  return __awaiter(this, void 0, void 0, function () {
600
- var hasCategories;
601
- var _this = this;
600
+ var couponCategories, hasCategories;
602
601
  return __generator(this, function (_d) {
603
- if (!coupon.productsCategories && !coupon.productsCategories.length) {
604
- console.log('não possui categories');
605
- return [2 /*return*/, true];
606
- }
607
- hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) { return __awaiter(_this, void 0, void 0, function () {
608
- var _b;
609
- var _this = this;
610
- return __generator(this, function (_d) {
611
- if (!i.categories || !((_b = i.categories) === null || _b === void 0 ? void 0 : _b.length)) {
612
- console.log('produto não tem categorias');
602
+ switch (_d.label) {
603
+ case 0:
604
+ if (!coupon.productsCategories && !coupon.productsCategories.length) {
605
+ console.log('não possui categories');
613
606
  return [2 /*return*/, true];
614
607
  }
615
- return [2 /*return*/, i.categories.some(function (c) { return __awaiter(_this, void 0, void 0, function () {
616
- var categoria;
617
- return __generator(this, function (_d) {
618
- switch (_d.label) {
619
- case 0:
620
- console.log('some category c', c);
621
- return [4 /*yield*/, this.categoryRepository.get({ id: c })];
622
- case 1:
623
- categoria = _d.sent();
624
- console.log(categoria);
625
- console.log(coupon.productsCategories.includes(categoria.id), coupon.productsCategories.includes(categoria.firestoreId), i.isGift);
626
- console.log('validation', (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift);
627
- return [2 /*return*/, (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift];
628
- }
629
- });
630
- }); })];
631
- });
632
- }); });
633
- console.log('final return', hasCategories, hasCategories.length);
634
- return [2 /*return*/, hasCategories.length ? true : false];
608
+ return [4 /*yield*/, this.getCouponCategoriesId(coupon)];
609
+ case 1:
610
+ couponCategories = _d.sent();
611
+ console.log('couponCategories', couponCategories.length, couponCategories);
612
+ hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
613
+ var _a;
614
+ console.log('entrou no filter');
615
+ if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length)) {
616
+ console.log('produto não tem categorias');
617
+ return true;
618
+ }
619
+ return i.categories.some(function (c) {
620
+ console.log('entrou no some 1', c);
621
+ return couponCategories.some(function (cat) { return (cat.id == c || cat.firestoreId == c); });
622
+ });
623
+ // return i.categories.some(async (c) => {
624
+ // console.log('some category c', c)
625
+ // const categoria: Category & { firestoreId?: string } = await this.categoryRepository.get({id: c})
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 (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift
630
+ // })
631
+ });
632
+ console.log('final return', hasCategories, hasCategories.length);
633
+ return [2 /*return*/, hasCategories.length ? true : false];
634
+ }
635
635
  });
636
636
  });
637
637
  };
@@ -679,6 +679,30 @@
679
679
  });
680
680
  });
681
681
  };
682
+ CouponService.prototype.getCouponCategoriesId = function (coupon) {
683
+ return __awaiter(this, void 0, void 0, function () {
684
+ var couponCategories, index, c;
685
+ return __generator(this, function (_d) {
686
+ switch (_d.label) {
687
+ case 0:
688
+ couponCategories = [];
689
+ index = 0;
690
+ _d.label = 1;
691
+ case 1:
692
+ if (!(index < coupon.productsCategories.length)) return [3 /*break*/, 4];
693
+ return [4 /*yield*/, this.categoryRepository.get({ id: coupon.productsCategories[index] })];
694
+ case 2:
695
+ c = _d.sent();
696
+ couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
697
+ _d.label = 3;
698
+ case 3:
699
+ index++;
700
+ return [3 /*break*/, 1];
701
+ case 4: return [2 /*return*/, couponCategories];
702
+ }
703
+ });
704
+ });
705
+ };
682
706
  return CouponService;
683
707
  }());
684
708
  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: 'SubscriptionRepository' }, { token: 'CategoryRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });