@infrab4a/connect-angular 3.3.0-beta.0 → 3.3.0-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.
@@ -849,15 +849,15 @@
849
849
  });
850
850
  return cart;
851
851
  };
852
- this.buildLineItem = function (_h) {
853
- var checkout = _h.checkout, item = _h.item, quantity = _h.quantity;
852
+ this.buildLineItem = function (_k) {
853
+ var checkout = _k.checkout, item = _k.item, quantity = _k.quantity;
854
854
  return __awaiter(_this, void 0, void 0, function () {
855
- var _a, _b, _c, _d, _e, _f, _g, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, type, isGift, pricePaid;
856
- return __generator(this, function (_h) {
857
- switch (_h.label) {
855
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, type, isGift, pricePaid;
856
+ return __generator(this, function (_k) {
857
+ switch (_k.label) {
858
858
  case 0: return [4 /*yield*/, this.productRepository.get({ id: item.id })];
859
859
  case 1:
860
- product = _h.sent();
860
+ product = _k.sent();
861
861
  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;
862
862
  if (this.checkMaxStock(item, quantity || 0))
863
863
  throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
@@ -869,7 +869,26 @@
869
869
  shop: checkout.shop || this.defaultShop,
870
870
  isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
871
871
  });
872
- console.log('teste', pricePaid);
872
+ console.log('checkout', checkout);
873
+ console.log('teste PricePaid', pricePaid);
874
+ console.log('LineItem return', i2.LineItem.toInstance({
875
+ id: id,
876
+ name: name !== null && name !== void 0 ? name : product.name,
877
+ EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
878
+ brand: product.brand,
879
+ slug: slug !== null && slug !== void 0 ? slug : product.slug,
880
+ sku: sku !== null && sku !== void 0 ? sku : product.sku,
881
+ stock: stock,
882
+ price: price,
883
+ image: image,
884
+ weight: weight !== null && weight !== void 0 ? weight : product.weight,
885
+ quantity: (item.quantity || 0) + (quantity || 0),
886
+ pricePaid: pricePaid,
887
+ categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
888
+ isGift: isGift !== null && isGift !== void 0 ? isGift : null,
889
+ costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
890
+ type: type,
891
+ }));
873
892
  return [2 /*return*/, {
874
893
  checkout: checkout,
875
894
  lineItem: i2.LineItem.toInstance({
@@ -885,9 +904,9 @@
885
904
  weight: weight !== null && weight !== void 0 ? weight : product.weight,
886
905
  quantity: (item.quantity || 0) + (quantity || 0),
887
906
  pricePaid: pricePaid,
888
- categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
907
+ categories: (_h = product.categories) !== null && _h !== void 0 ? _h : [],
889
908
  isGift: isGift !== null && isGift !== void 0 ? isGift : null,
890
- costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
909
+ costPrice: (_j = product.costPrice) !== null && _j !== void 0 ? _j : 0,
891
910
  type: type,
892
911
  }),
893
912
  }];
@@ -895,8 +914,8 @@
895
914
  });
896
915
  });
897
916
  };
898
- this.getProductPrice = function (_h) {
899
- var product = _h.product, isSubscriber = _h.isSubscriber;
917
+ this.getProductPrice = function (_k) {
918
+ var product = _k.product, isSubscriber = _k.isSubscriber;
900
919
  var info = product.price;
901
920
  if (product.isGift)
902
921
  return 0;
@@ -912,13 +931,14 @@
912
931
  CartService.prototype.addItem = function (item, quantity) {
913
932
  var _this = this;
914
933
  if (quantity === void 0) { quantity = 1; }
915
- return rxjs.from(this.checkoutService.getCheckout()).pipe(operators.concatMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_h) {
916
- switch (_h.label) {
934
+ console.log('teste');
935
+ return rxjs.from(this.checkoutService.getCheckout()).pipe(operators.concatMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_k) {
936
+ switch (_k.label) {
917
937
  case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 })];
918
- case 1: return [2 /*return*/, _h.sent()];
938
+ case 1: return [2 /*return*/, _k.sent()];
919
939
  }
920
- }); }); }), operators.mergeMap(function (_h) {
921
- var checkout = _h.checkout, lineItem = _h.lineItem;
940
+ }); }); }), operators.mergeMap(function (_k) {
941
+ var checkout = _k.checkout, lineItem = _k.lineItem;
922
942
  return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
923
943
  }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
924
944
  };
@@ -955,31 +975,31 @@
955
975
  CartService.prototype.updateUserCart = function (user) {
956
976
  var _this = this;
957
977
  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) { return __awaiter(_this, void 0, void 0, function () {
958
- var _a, _b, _h, _j, _k, _l, _m, _o, _p, _q, _r;
978
+ var _a, _b, _k, _l, _m, _o, _p, _q, _r, _s, _t;
959
979
  var _this = this;
960
- return __generator(this, function (_s) {
961
- switch (_s.label) {
980
+ return __generator(this, function (_u) {
981
+ switch (_u.label) {
962
982
  case 0:
963
- _j = (_h = this.checkoutService)
983
+ _l = (_k = this.checkoutService)
964
984
  .updateCheckoutLineItems;
965
- _l = (_k = i2.Checkout).toInstance;
966
- _o = (_m = Object).assign;
967
- _p = [Object.assign({}, checkout.toPlain())];
968
- _q = {};
985
+ _o = (_m = i2.Checkout).toInstance;
986
+ _q = (_p = Object).assign;
987
+ _r = [Object.assign({}, checkout.toPlain())];
988
+ _s = {};
969
989
  if (!((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 2];
970
- return [4 /*yield*/, Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_h) {
971
- switch (_h.label) {
990
+ return [4 /*yield*/, Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_k) {
991
+ switch (_k.label) {
972
992
  case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item })];
973
- case 1: return [2 /*return*/, (_h.sent()).lineItem];
993
+ case 1: return [2 /*return*/, (_k.sent()).lineItem];
974
994
  }
975
995
  }); }); }))];
976
996
  case 1:
977
- _r = _s.sent();
997
+ _t = _u.sent();
978
998
  return [3 /*break*/, 3];
979
999
  case 2:
980
- _r = [];
981
- _s.label = 3;
982
- case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])])
1000
+ _t = [];
1001
+ _u.label = 3;
1002
+ case 3: return [2 /*return*/, _l.apply(_k, [_o.apply(_m, [_q.apply(_p, _r.concat([(_s.lineItems = _t, _s)]))])])
983
1003
  .toPromise()];
984
1004
  }
985
1005
  });