@infrab4a/connect-angular 3.6.0 → 3.7.0-beta.0

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.
@@ -516,11 +516,13 @@
516
516
  // Verifica o limite de uso geral por usuario
517
517
  if (coupon.useLimit && orders.data.length >= coupon.useLimit)
518
518
  throw new InvalidCouponError('Limite de uso atingido.');
519
- validUser = this.userValidationAndSubscriptionStatus(coupon, checkout.user);
519
+ return [4 /*yield*/, this.userValidationAndSubscriptionStatus(coupon, userEmail)];
520
+ case 2:
521
+ validUser = _d.sent();
520
522
  if (!validUser)
521
523
  throw new InvalidCouponError('Usuário não elegível.');
522
524
  return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
523
- case 2:
525
+ case 3:
524
526
  hasProductCategories = _d.sent();
525
527
  if (!hasProductCategories)
526
528
  throw 'Seu carrinho não possui produtos elegíveis para desconto.';
@@ -583,7 +585,7 @@
583
585
  lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
584
586
  var _a;
585
587
  if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
586
- return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat.id == c || cat.firestoreId == c; }); });
588
+ return i.categories.some(function (c) { return couponCategories.some(function (cat) { return (cat.id == c || cat.firestoreId == c); }); });
587
589
  }
588
590
  return true;
589
591
  });
@@ -635,31 +637,56 @@
635
637
  var _a;
636
638
  if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
637
639
  return true;
638
- return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat.id == c || cat.firestoreId == c; }); });
640
+ return i.categories.some(function (c) { return couponCategories.some(function (cat) { return (cat.id == c || cat.firestoreId == c); }); });
639
641
  });
640
642
  return [2 /*return*/, hasCategories.length ? true : false];
641
643
  }
642
644
  });
643
645
  });
644
646
  };
645
- CouponService.prototype.userValidationAndSubscriptionStatus = function (coupon, user) {
646
- if (coupon.exclusivityType === i1$1.Exclusivities.ALL_USERS)
647
- return true;
648
- // Verifica se o email do usuário é coorporativo
649
- if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === i1$1.Exclusivities.COLLABORATORS)
650
- throw new InvalidCouponError('Você não é colaborador.');
651
- // Verifica se o email do usuário é associado ao cupom de uso por usuario
652
- if (coupon.exclusivityType === i1$1.Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== user.email)
653
- throw new InvalidCouponError('Cupom não é válido para este usuário.');
654
- switch (coupon.exclusivityType) {
655
- case i1$1.Exclusivities.ACTIVE_SUBSCRIBER:
656
- return user.isSubscriber ? true : false;
657
- case i1$1.Exclusivities.INACTIVE_SUBSCRIBER:
658
- return user.isSubscriber ? false : true;
659
- case i1$1.Exclusivities.NON_SUBSCRIBER:
660
- return user.isSubscriber ? false : true;
661
- }
662
- return true;
647
+ CouponService.prototype.userValidationAndSubscriptionStatus = function (coupon, userEmail) {
648
+ return __awaiter(this, void 0, void 0, function () {
649
+ var couponRuleSubscription, sub, activeSubs;
650
+ return __generator(this, function (_d) {
651
+ switch (_d.label) {
652
+ case 0:
653
+ // Verifica se o email do usuário é coorporativo
654
+ if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === i1$1.Exclusivities.COLLABORATORS)
655
+ throw new InvalidCouponError('Você não é colaborador.');
656
+ // Verifica se o email do usuário é associado ao cupom de uso por usuario
657
+ if (coupon.exclusivityType === i1$1.Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== userEmail)
658
+ throw new InvalidCouponError('Cupom não é válido para este usuário.');
659
+ couponRuleSubscription = coupon.exclusivityType === i1$1.Exclusivities.ACTIVE_SUBSCRIBER ||
660
+ coupon.exclusivityType === i1$1.Exclusivities.INACTIVE_SUBSCRIBER ||
661
+ coupon.exclusivityType === i1$1.Exclusivities.NON_SUBSCRIBER;
662
+ if (!(couponRuleSubscription && userEmail)) return [3 /*break*/, 2];
663
+ return [4 /*yield*/, this.subscriptionRepository
664
+ .find({
665
+ filters: {
666
+ user: {
667
+ email: { operator: i1$1.Where.EQUALS, value: userEmail },
668
+ },
669
+ },
670
+ })
671
+ .then(function (sub) { return sub.data; })];
672
+ case 1:
673
+ sub = _d.sent();
674
+ activeSubs = sub === null || sub === void 0 ? void 0 : sub.filter(function (s) { return s.status === i1$1.Status.ACTIVE; });
675
+ switch (coupon.exclusivityType) {
676
+ case i1$1.Exclusivities.ACTIVE_SUBSCRIBER:
677
+ return [2 /*return*/, activeSubs.length > 0];
678
+ case i1$1.Exclusivities.INACTIVE_SUBSCRIBER:
679
+ return [2 /*return*/, activeSubs.length === 0];
680
+ case i1$1.Exclusivities.NON_SUBSCRIBER:
681
+ return [2 /*return*/, sub.length === 0];
682
+ default:
683
+ return [2 /*return*/, false];
684
+ }
685
+ _d.label = 2;
686
+ case 2: return [2 /*return*/, true];
687
+ }
688
+ });
689
+ });
663
690
  };
664
691
  CouponService.prototype.getCouponCategoriesId = function (coupon) {
665
692
  return __awaiter(this, void 0, void 0, function () {
@@ -672,9 +699,7 @@
672
699
  _d.label = 1;
673
700
  case 1:
674
701
  if (!(index < coupon.productsCategories.length)) return [3 /*break*/, 4];
675
- return [4 /*yield*/, this.categoryRepository.get({
676
- id: coupon.productsCategories[index],
677
- })];
702
+ return [4 /*yield*/, this.categoryRepository.get({ id: coupon.productsCategories[index] })];
678
703
  case 2:
679
704
  c = _d.sent();
680
705
  couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
@@ -1207,8 +1232,9 @@
1207
1232
  var _this = this;
1208
1233
  return rxjs.combineLatest([
1209
1234
  this.homeService.getHomeData(),
1210
- this.http.get(this.apiUrl + "open/checkshippingcompany?personId=" + personId + "&postalCode=" + zip + "&weightGrams=" + weightGrams),
1211
- ]).pipe(operators.map(function (_a) {
1235
+ this.http.get(this.apiUrl + "open/checkshippingcompany?personId=" + personId + "&postalCode=" + zip + "&weightGrams=" + weightGrams)
1236
+ ])
1237
+ .pipe(operators.map(function (_a) {
1212
1238
  var _b = __read(_a, 2), datas = _b[0], shippingMethodsResponse = _b[1];
1213
1239
  var shippingMethods = shippingMethodsResponse.result;
1214
1240
  if (!shippingMethods.length)
@@ -1820,10 +1846,10 @@
1820
1846
  },
1821
1847
  {
1822
1848
  provide: i1$1.CategoryHasuraGraphQLRepository,
1823
- useFactory: function (options, productRepository, categoryFilterRepository) {
1824
- return new i1$1.CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1849
+ useFactory: function (options, productRepository) {
1850
+ return new i1$1.CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
1825
1851
  },
1826
- deps: [HASURA_OPTIONS, i1$1.ProductHasuraGraphQLRepository, i1$1.CategoryFilterHasuraGraphQLRepository],
1852
+ deps: [HASURA_OPTIONS, i1$1.ProductHasuraGraphQLRepository],
1827
1853
  },
1828
1854
  {
1829
1855
  provide: 'ProductRepository',
@@ -1847,39 +1873,6 @@
1847
1873
  },
1848
1874
  deps: [HASURA_OPTIONS],
1849
1875
  },
1850
- {
1851
- provide: 'CategoryFilterRepository',
1852
- useExisting: i1$1.CategoryFilterHasuraGraphQLRepository,
1853
- },
1854
- {
1855
- provide: i1$1.CategoryFilterHasuraGraphQLRepository,
1856
- useFactory: function (options) {
1857
- return new i1$1.CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1858
- },
1859
- deps: [HASURA_OPTIONS],
1860
- },
1861
- {
1862
- provide: 'FilterOptionRepository',
1863
- useExisting: i1$1.FilterOptionHasuraGraphQLRepository,
1864
- },
1865
- {
1866
- provide: i1$1.FilterOptionHasuraGraphQLRepository,
1867
- useFactory: function (options) {
1868
- return new i1$1.FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1869
- },
1870
- deps: [HASURA_OPTIONS],
1871
- },
1872
- {
1873
- provide: 'FilterRepository',
1874
- useExisting: i1$1.FilterHasuraGraphQLRepository,
1875
- },
1876
- {
1877
- provide: i1$1.FilterHasuraGraphQLRepository,
1878
- useFactory: function (options, filterOptionRepository, categoryFilterRepository) {
1879
- return new i1$1.FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1880
- },
1881
- deps: [HASURA_OPTIONS, i1$1.FilterOptionHasuraGraphQLRepository, i1$1.CategoryFilterHasuraGraphQLRepository],
1882
- },
1883
1876
  ] });
1884
1877
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularHasuraGraphQLModule, decorators: [{
1885
1878
  type: i0.NgModule,
@@ -1891,10 +1884,10 @@
1891
1884
  },
1892
1885
  {
1893
1886
  provide: i1$1.CategoryHasuraGraphQLRepository,
1894
- useFactory: function (options, productRepository, categoryFilterRepository) {
1895
- return new i1$1.CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1887
+ useFactory: function (options, productRepository) {
1888
+ return new i1$1.CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
1896
1889
  },
1897
- deps: [HASURA_OPTIONS, i1$1.ProductHasuraGraphQLRepository, i1$1.CategoryFilterHasuraGraphQLRepository],
1890
+ deps: [HASURA_OPTIONS, i1$1.ProductHasuraGraphQLRepository],
1898
1891
  },
1899
1892
  {
1900
1893
  provide: 'ProductRepository',
@@ -1918,39 +1911,6 @@
1918
1911
  },
1919
1912
  deps: [HASURA_OPTIONS],
1920
1913
  },
1921
- {
1922
- provide: 'CategoryFilterRepository',
1923
- useExisting: i1$1.CategoryFilterHasuraGraphQLRepository,
1924
- },
1925
- {
1926
- provide: i1$1.CategoryFilterHasuraGraphQLRepository,
1927
- useFactory: function (options) {
1928
- return new i1$1.CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1929
- },
1930
- deps: [HASURA_OPTIONS],
1931
- },
1932
- {
1933
- provide: 'FilterOptionRepository',
1934
- useExisting: i1$1.FilterOptionHasuraGraphQLRepository,
1935
- },
1936
- {
1937
- provide: i1$1.FilterOptionHasuraGraphQLRepository,
1938
- useFactory: function (options) {
1939
- return new i1$1.FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1940
- },
1941
- deps: [HASURA_OPTIONS],
1942
- },
1943
- {
1944
- provide: 'FilterRepository',
1945
- useExisting: i1$1.FilterHasuraGraphQLRepository,
1946
- },
1947
- {
1948
- provide: i1$1.FilterHasuraGraphQLRepository,
1949
- useFactory: function (options, filterOptionRepository, categoryFilterRepository) {
1950
- return new i1$1.FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1951
- },
1952
- deps: [HASURA_OPTIONS, i1$1.FilterOptionHasuraGraphQLRepository, i1$1.CategoryFilterHasuraGraphQLRepository],
1953
- },
1954
1914
  ],
1955
1915
  }]
1956
1916
  }] });
@@ -1976,7 +1936,7 @@
1976
1936
  CouponService,
1977
1937
  HomeShopService,
1978
1938
  OrderService,
1979
- ShippingService,
1939
+ ShippingService
1980
1940
  ], imports: [[fire.AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1981
1941
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularConnectModule, decorators: [{
1982
1942
  type: i0.NgModule,
@@ -1990,7 +1950,7 @@
1990
1950
  CouponService,
1991
1951
  HomeShopService,
1992
1952
  OrderService,
1993
- ShippingService,
1953
+ ShippingService
1994
1954
  ],
1995
1955
  }]
1996
1956
  }] });