@infrab4a/connect-angular 3.7.4 → 3.7.6-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.
@@ -515,7 +515,7 @@
515
515
  // Verifica o limite de uso geral por usuario
516
516
  if (coupon.useLimit && orders.data.length >= coupon.useLimit)
517
517
  throw new InvalidCouponError('Limite de uso atingido.');
518
- validUser = this.userValidationAndSubscriptionStatus(coupon, checkout.user);
518
+ validUser = this.userValidationAndSubscriptionStatus(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
519
519
  if (!validUser)
520
520
  throw new InvalidCouponError('Usuário não elegível.');
521
521
  return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
@@ -644,6 +644,8 @@
644
644
  CouponService.prototype.userValidationAndSubscriptionStatus = function (coupon, user) {
645
645
  if (coupon.exclusivityType === i1$1.Exclusivities.ALL_USERS)
646
646
  return true;
647
+ if (!user)
648
+ return true;
647
649
  // Verifica se o email do usuário é coorporativo
648
650
  if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === i1$1.Exclusivities.COLLABORATORS)
649
651
  throw new InvalidCouponError('Você não é colaborador.');
@@ -794,12 +796,13 @@
794
796
  } });
795
797
 
796
798
  var CartService = /** @class */ (function () {
797
- function CartService(authService, checkoutService, defaultShop, productRepository) {
799
+ function CartService(authService, checkoutService, defaultShop, productRepository, variantRepository) {
798
800
  var _this = this;
799
801
  this.authService = authService;
800
802
  this.checkoutService = checkoutService;
801
803
  this.defaultShop = defaultShop;
802
804
  this.productRepository = productRepository;
805
+ this.variantRepository = variantRepository;
803
806
  this.cartSubject = new rxjs.Subject();
804
807
  this.updateLineItemInCart = function (lineItem, quantity, checkout) { return (i1$1.isNil(checkout) ? _this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
805
808
  var _a;
@@ -826,17 +829,17 @@
826
829
  this.buildLineItem = function (_h) {
827
830
  var checkout = _h.checkout, item = _h.item, quantity = _h.quantity;
828
831
  return __awaiter(_this, void 0, void 0, function () {
829
- var _a, _b, _c, _d, _e, _f, _g, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, type, isGift, pricePaid;
832
+ var _a, _b, _c, _d, _e, _f, _g, product, image, id, name, EAN, slug, stock, price, weight, sku, type, isGift, pricePaid;
830
833
  return __generator(this, function (_h) {
831
834
  switch (_h.label) {
832
- case 0: return [4 /*yield*/, this.productRepository.get({ id: item.id })];
835
+ case 0: return [4 /*yield*/, this.getProductData(item.id)];
833
836
  case 1:
834
837
  product = _h.sent();
835
838
  item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find(function (lineItem) { return lineItem.sku === item.sku; })) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
836
839
  if (this.checkMaxStock(item, quantity || 0))
837
840
  throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
838
841
  image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
839
- id = item.id, name = item.name, EAN = item.EAN, brand = item.brand, slug = item.slug, stock = item.stock, price = item.price, weight = item.weight, categories = item.categories, sku = item.sku, type = item.type;
842
+ id = item.id, name = item.name, EAN = item.EAN, slug = item.slug, stock = item.stock, price = item.price, weight = item.weight, sku = item.sku, type = item.type;
840
843
  isGift = item.isGift || null;
841
844
  pricePaid = this.getProductPrice({
842
845
  product: item,
@@ -933,7 +936,8 @@
933
936
  return __generator(this, function (_s) {
934
937
  switch (_s.label) {
935
938
  case 0:
936
- _j = (_h = this.checkoutService).updateCheckoutLineItems;
939
+ _j = (_h = this.checkoutService)
940
+ .updateCheckoutLineItems;
937
941
  _l = (_k = i1$1.Checkout).toInstance;
938
942
  _o = (_m = Object).assign;
939
943
  _p = [Object.assign({}, checkout.toPlain())];
@@ -951,7 +955,8 @@
951
955
  case 2:
952
956
  _r = [];
953
957
  _s.label = 3;
954
- case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])]).toPromise()];
958
+ case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])])
959
+ .toPromise()];
955
960
  }
956
961
  });
957
962
  }); }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
@@ -967,9 +972,36 @@
967
972
  var _this = this;
968
973
  return this.checkoutService.getCheckout(checkoutData).pipe(operators.map(function (checkout) { return checkout.lineItems; }), operators.concatMap(function (lineItems) { return rxjs.of(_this.generateCartObject(lineItems)); }));
969
974
  };
975
+ CartService.prototype.getProductData = function (productId) {
976
+ return __awaiter(this, void 0, void 0, function () {
977
+ var product, variant, error_1;
978
+ return __generator(this, function (_h) {
979
+ switch (_h.label) {
980
+ case 0:
981
+ _h.trys.push([0, 2, , 6]);
982
+ return [4 /*yield*/, this.productRepository.get({ id: productId })];
983
+ case 1:
984
+ product = _h.sent();
985
+ return [3 /*break*/, 6];
986
+ case 2:
987
+ error_1 = _h.sent();
988
+ if (!(error_1 instanceof i1$1.NotFoundError)) return [3 /*break*/, 5];
989
+ return [4 /*yield*/, this.variantRepository.get({ id: productId })];
990
+ case 3:
991
+ variant = _h.sent();
992
+ return [4 /*yield*/, this.productRepository.get({ id: variant.productId })];
993
+ case 4:
994
+ product = _h.sent();
995
+ _h.label = 5;
996
+ case 5: throw error_1;
997
+ case 6: return [2 /*return*/, Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())))];
998
+ }
999
+ });
1000
+ });
1001
+ };
970
1002
  return CartService;
971
1003
  }());
972
- CartService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1004
+ CartService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'VariantRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
973
1005
  CartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService });
974
1006
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, decorators: [{
975
1007
  type: i0.Injectable
@@ -980,6 +1012,9 @@
980
1012
  }] }, { type: undefined, decorators: [{
981
1013
  type: i0.Inject,
982
1014
  args: ['ProductRepository']
1015
+ }] }, { type: undefined, decorators: [{
1016
+ type: i0.Inject,
1017
+ args: ['VariantRepository']
983
1018
  }] }];
984
1019
  } });
985
1020
 
@@ -1015,7 +1050,9 @@
1015
1050
  };
1016
1051
  CheckoutSubscriptionService.prototype.checkCoupon = function (nickname, userEmail) {
1017
1052
  var _this = this;
1018
- return this.getCheckoutSubscription().pipe(operators.concatMap(function (checkout) { return _this.couponService.checkCoupon(nickname, userEmail, i1$1.CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, null, true).pipe(); }));
1053
+ return this.getCheckoutSubscription().pipe(operators.concatMap(function (checkout) { return _this.couponService
1054
+ .checkCoupon(nickname, userEmail, i1$1.CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
1055
+ .pipe(); }));
1019
1056
  };
1020
1057
  CheckoutSubscriptionService.prototype.calcDiscountSubscription = function (coupon) {
1021
1058
  var _this = this;