@infrab4a/connect-angular 1.0.1-beta.0 → 1.0.1

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.
@@ -595,18 +595,15 @@
595
595
  });
596
596
  return cart;
597
597
  };
598
- this.buildLineItem = function (_m) {
599
- var checkout = _m.checkout, item = _m.item, quantity = _m.quantity;
598
+ this.buildLineItem = function (_h) {
599
+ var checkout = _h.checkout, item = _h.item, quantity = _h.quantity;
600
600
  return __awaiter(_this, void 0, void 0, function () {
601
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, isGift, pricePaid;
602
- return __generator(this, function (_m) {
603
- switch (_m.label) {
604
- case 0:
605
- console.log('item', item);
606
- return [4 /*yield*/, this.productRepository.get({ id: item.id })];
601
+ var _a, _b, _c, _d, _e, _f, _g, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, isGift, pricePaid;
602
+ return __generator(this, function (_h) {
603
+ switch (_h.label) {
604
+ case 0: return [4 /*yield*/, this.productRepository.get({ id: item.id })];
607
605
  case 1:
608
- product = _m.sent();
609
- console.log('product', product);
606
+ product = _h.sent();
610
607
  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;
611
608
  if (this.checkMaxStock(item, quantity || 0))
612
609
  throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
@@ -618,40 +615,6 @@
618
615
  shop: checkout.shop || this.defaultShop,
619
616
  isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
620
617
  });
621
- console.log('LineItem', i2.LineItem.toInstance({
622
- id: id,
623
- name: name !== null && name !== void 0 ? name : product.name,
624
- EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
625
- brand: product.brand,
626
- slug: slug !== null && slug !== void 0 ? slug : product.slug,
627
- sku: sku !== null && sku !== void 0 ? sku : product.sku,
628
- stock: stock,
629
- price: price,
630
- image: image,
631
- weight: weight !== null && weight !== void 0 ? weight : product.weight,
632
- quantity: (item.quantity || 0) + (quantity || 0),
633
- pricePaid: pricePaid,
634
- categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
635
- isGift: isGift !== null && isGift !== void 0 ? isGift : null,
636
- costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 1,
637
- }));
638
- i2.LineItem.toInstance({
639
- id: id,
640
- name: name !== null && name !== void 0 ? name : product.name,
641
- EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
642
- brand: product.brand,
643
- slug: slug !== null && slug !== void 0 ? slug : product.slug,
644
- sku: sku !== null && sku !== void 0 ? sku : product.sku,
645
- stock: stock,
646
- price: price,
647
- image: image,
648
- weight: weight !== null && weight !== void 0 ? weight : product.weight,
649
- quantity: (item.quantity || 0) + (quantity || 0),
650
- pricePaid: pricePaid,
651
- categories: (_h = product.categories) !== null && _h !== void 0 ? _h : [],
652
- isGift: isGift !== null && isGift !== void 0 ? isGift : null,
653
- costPrice: (_j = product.costPrice) !== null && _j !== void 0 ? _j : 0,
654
- });
655
618
  return [2 /*return*/, {
656
619
  checkout: checkout,
657
620
  lineItem: i2.LineItem.toInstance({
@@ -667,17 +630,17 @@
667
630
  weight: weight !== null && weight !== void 0 ? weight : product.weight,
668
631
  quantity: (item.quantity || 0) + (quantity || 0),
669
632
  pricePaid: pricePaid,
670
- categories: (_k = product.categories) !== null && _k !== void 0 ? _k : [],
633
+ categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
671
634
  isGift: isGift !== null && isGift !== void 0 ? isGift : null,
672
- costPrice: (_l = product.costPrice) !== null && _l !== void 0 ? _l : 0,
635
+ costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
673
636
  }),
674
637
  }];
675
638
  }
676
639
  });
677
640
  });
678
641
  };
679
- this.getProductPrice = function (_m) {
680
- var product = _m.product, shop = _m.shop, isSubscriber = _m.isSubscriber;
642
+ this.getProductPrice = function (_h) {
643
+ var product = _h.product, shop = _h.shop, isSubscriber = _h.isSubscriber;
681
644
  var info = product.getInfoByShop(shop);
682
645
  if (product.isGift)
683
646
  return 0;
@@ -693,13 +656,13 @@
693
656
  CartService.prototype.addItem = function (item, quantity) {
694
657
  var _this = this;
695
658
  if (quantity === void 0) { quantity = 1; }
696
- return rxjs.from(this.checkoutService.getCheckout()).pipe(operators.concatMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_m) {
697
- switch (_m.label) {
659
+ return rxjs.from(this.checkoutService.getCheckout()).pipe(operators.concatMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_h) {
660
+ switch (_h.label) {
698
661
  case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 })];
699
- case 1: return [2 /*return*/, _m.sent()];
662
+ case 1: return [2 /*return*/, _h.sent()];
700
663
  }
701
- }); }); }), operators.mergeMap(function (_m) {
702
- var checkout = _m.checkout, lineItem = _m.lineItem;
664
+ }); }); }), operators.mergeMap(function (_h) {
665
+ var checkout = _h.checkout, lineItem = _h.lineItem;
703
666
  return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
704
667
  }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
705
668
  };
@@ -752,10 +715,10 @@
752
715
  var _this = this;
753
716
  return this.checkoutService.getCheckout().pipe(operators.concatMap(function (checkout) { return _this.checkoutService.updateCheckoutUser(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user: user }))); }), operators.concatMap(function (checkout) {
754
717
  var _a;
755
- return _this.checkoutService.updateCheckoutLineItems(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_m) {
756
- switch (_m.label) {
718
+ return _this.checkoutService.updateCheckoutLineItems(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_h) {
719
+ switch (_h.label) {
757
720
  case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item })];
758
- case 1: return [2 /*return*/, _m.sent()];
721
+ case 1: return [2 /*return*/, _h.sent()];
759
722
  }
760
723
  }); }); })) || [] })));
761
724
  }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));