@infrab4a/connect-angular 3.10.0-beta.2 → 3.10.0-beta.4

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.
@@ -561,7 +561,7 @@
561
561
  var _a;
562
562
  if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
563
563
  return true;
564
- return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat.id == c || cat.firestoreId == c; }); });
564
+ return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat == c; }); });
565
565
  });
566
566
  return [2 /*return*/, hasCategories.length ? true : false];
567
567
  }
@@ -590,7 +590,7 @@
590
590
  };
591
591
  CouponService.prototype.getCouponCategoriesId = function (productsCategories) {
592
592
  return __awaiter(this, void 0, void 0, function () {
593
- var couponCategories, index, c;
593
+ var couponCategories, index, category, children;
594
594
  return __generator(this, function (_c) {
595
595
  switch (_c.label) {
596
596
  case 0:
@@ -598,18 +598,22 @@
598
598
  index = 0;
599
599
  _c.label = 1;
600
600
  case 1:
601
- if (!(index < productsCategories.length)) return [3 /*break*/, 4];
601
+ if (!(index < productsCategories.length)) return [3 /*break*/, 5];
602
602
  return [4 /*yield*/, this.categoryRepository.get({
603
603
  id: productsCategories[index],
604
604
  })];
605
605
  case 2:
606
- c = _c.sent();
607
- couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
608
- _c.label = 3;
606
+ category = _c.sent();
607
+ if (!category) return [3 /*break*/, 4];
608
+ return [4 /*yield*/, this.categoryRepository.getChildren(parseInt(productsCategories[index]))];
609
609
  case 3:
610
+ children = _c.sent();
611
+ couponCategories.push.apply(couponCategories, __spreadArray([category.id], __read(children.map(function (c) { return c.id.toString(); }))));
612
+ _c.label = 4;
613
+ case 4:
610
614
  index++;
611
615
  return [3 /*break*/, 1];
612
- case 4: return [2 /*return*/, couponCategories];
616
+ case 5: return [2 /*return*/, __spreadArray([], __read(new Set(couponCategories)))];
613
617
  }
614
618
  });
615
619
  });
@@ -629,7 +633,7 @@
629
633
  lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
630
634
  var _a;
631
635
  if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
632
- return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat.id == c || cat.firestoreId == c; }); });
636
+ return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat == c; }); });
633
637
  }
634
638
  return true;
635
639
  });
@@ -773,12 +777,13 @@
773
777
  } });
774
778
 
775
779
  var CartService = /** @class */ (function () {
776
- function CartService(authService, checkoutService, defaultShop, productRepository, variantRepository, buy2WinRepository) {
780
+ function CartService(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
777
781
  var _this = this;
778
782
  this.authService = authService;
779
783
  this.checkoutService = checkoutService;
780
784
  this.defaultShop = defaultShop;
781
785
  this.productRepository = productRepository;
786
+ this.categoryRepository = categoryRepository;
782
787
  this.variantRepository = variantRepository;
783
788
  this.buy2WinRepository = buy2WinRepository;
784
789
  this.cartSubject = new rxjs.Subject();
@@ -958,7 +963,7 @@
958
963
  };
959
964
  CartService.prototype.getProductData = function (productId) {
960
965
  return __awaiter(this, void 0, void 0, function () {
961
- var product, variant, error_1;
966
+ var product, variant, error_1, variants;
962
967
  return __generator(this, function (_h) {
963
968
  switch (_h.label) {
964
969
  case 0:
@@ -971,9 +976,12 @@
971
976
  error_1 = _h.sent();
972
977
  if (!(error_1 instanceof i3.NotFoundError))
973
978
  throw error_1;
974
- return [4 /*yield*/, this.variantRepository.get({ id: productId })];
979
+ return [4 /*yield*/, this.variantRepository.find({ filters: { id: productId } })];
975
980
  case 3:
976
- variant = _h.sent();
981
+ variants = (_h.sent()).data;
982
+ variant = variants.shift();
983
+ if (!variant)
984
+ throw error_1;
977
985
  return [4 /*yield*/, this.productRepository.get({ id: variant.productId })];
978
986
  case 4:
979
987
  product = _h.sent();
@@ -986,8 +994,8 @@
986
994
  CartService.prototype.getGifts = function () {
987
995
  var _this = this;
988
996
  return this.checkoutService.getCheckout().pipe(operators.mergeMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () {
989
- var notGiftItems, cartTotal, campaigns, elegibleCampaigns, _loop_1, campaigns_1, campaigns_1_1, campaign, campaingnProducts, elegibleCampaigns_1, elegibleCampaigns_1_1, campaign, elegibleProducts, _h, _j, product, productData, gift, e_1_1, e_2_1, gifts;
990
- var e_3, _k, e_2, _l, e_1, _m;
997
+ var notGiftItems, cartTotal, campaigns, elegibleCampaigns, _loop_1, this_1, campaigns_1, campaigns_1_1, campaign, e_1_1, campaingnProducts, elegibleCampaigns_1, elegibleCampaigns_1_1, campaign, elegibleProducts, _h, _j, product, productData, gift, e_2_1, e_3_1, gifts;
998
+ var e_1, _k, e_3, _l, e_2, _m;
991
999
  return __generator(this, function (_o) {
992
1000
  switch (_o.label) {
993
1001
  case 0:
@@ -1009,105 +1017,158 @@
1009
1017
  return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
1010
1018
  elegibleCampaigns = [];
1011
1019
  _loop_1 = function (campaign) {
1012
- var today = new Date();
1013
- if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
1014
- return "continue";
1015
- if (campaign.activeCategory) {
1016
- var categoriesCampaing_1 = campaign.categories.map(function (c) { return c.id; });
1017
- var filterProductsCategories = checkout.lineItems.filter(function (l) {
1018
- var _a;
1019
- if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
1020
- return true;
1021
- return l.categories.some(function (c) { return categoriesCampaing_1.some(function (cat) { return cat == c; }); });
1022
- });
1023
- if (filterProductsCategories.length) {
1024
- var cartTotalCategories = filterProductsCategories.reduce(function (a, b) { return a + b.pricePaid * b.quantity; }, 0);
1025
- if (cartTotalCategories >= campaign.cartValueMin)
1026
- elegibleCampaigns.push(campaign);
1020
+ var today, categoriesCampaing, categoriesCampaingFullTree, categoriesCampaing_1, categoriesCampaing_1_1, id, children, e_4_1, categoriesCampaingTree_1, filterProductsCategories, cartTotalCategories;
1021
+ var e_4, _p;
1022
+ return __generator(this, function (_q) {
1023
+ switch (_q.label) {
1024
+ case 0:
1025
+ today = new Date();
1026
+ if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
1027
+ return [2 /*return*/, "continue"];
1028
+ if (!campaign.activeCategory) return [3 /*break*/, 9];
1029
+ categoriesCampaing = campaign.categories.map(function (c) { return c.id.toString(); });
1030
+ categoriesCampaingFullTree = [];
1031
+ _q.label = 1;
1032
+ case 1:
1033
+ _q.trys.push([1, 6, 7, 8]);
1034
+ categoriesCampaing_1 = (e_4 = void 0, __values(categoriesCampaing)), categoriesCampaing_1_1 = categoriesCampaing_1.next();
1035
+ _q.label = 2;
1036
+ case 2:
1037
+ if (!!categoriesCampaing_1_1.done) return [3 /*break*/, 5];
1038
+ id = categoriesCampaing_1_1.value;
1039
+ return [4 /*yield*/, this_1.categoryRepository.getChildren(parseInt(id))];
1040
+ case 3:
1041
+ children = _q.sent();
1042
+ categoriesCampaingFullTree.push.apply(categoriesCampaingFullTree, __spreadArray([id], __read(children.map(function (c) { return c.id.toString(); }))));
1043
+ _q.label = 4;
1044
+ case 4:
1045
+ categoriesCampaing_1_1 = categoriesCampaing_1.next();
1046
+ return [3 /*break*/, 2];
1047
+ case 5: return [3 /*break*/, 8];
1048
+ case 6:
1049
+ e_4_1 = _q.sent();
1050
+ e_4 = { error: e_4_1 };
1051
+ return [3 /*break*/, 8];
1052
+ case 7:
1053
+ try {
1054
+ if (categoriesCampaing_1_1 && !categoriesCampaing_1_1.done && (_p = categoriesCampaing_1.return)) _p.call(categoriesCampaing_1);
1055
+ }
1056
+ finally { if (e_4) throw e_4.error; }
1057
+ return [7 /*endfinally*/];
1058
+ case 8:
1059
+ categoriesCampaingTree_1 = __spreadArray([], __read(new Set(categoriesCampaingFullTree)));
1060
+ filterProductsCategories = checkout.lineItems.filter(function (l) {
1061
+ var _a;
1062
+ if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
1063
+ return true;
1064
+ return l.categories.some(function (c) { return categoriesCampaingTree_1.some(function (cat) { return cat == c; }); });
1065
+ });
1066
+ if (filterProductsCategories.length) {
1067
+ cartTotalCategories = filterProductsCategories.reduce(function (a, b) { return a + b.pricePaid * b.quantity; }, 0);
1068
+ if (cartTotalCategories >= campaign.cartValueMin)
1069
+ elegibleCampaigns.push(campaign);
1070
+ }
1071
+ return [3 /*break*/, 10];
1072
+ case 9:
1073
+ if (campaign.cartValue && campaign.cartValue > 0) {
1074
+ if (campaign.cartValue <= cartTotal)
1075
+ elegibleCampaigns.push(campaign);
1076
+ }
1077
+ _q.label = 10;
1078
+ case 10: return [2 /*return*/];
1027
1079
  }
1028
- }
1029
- else {
1030
- if (campaign.cartValue && campaign.cartValue > 0) {
1031
- if (campaign.cartValue <= cartTotal)
1032
- elegibleCampaigns.push(campaign);
1033
- }
1034
- }
1080
+ });
1035
1081
  };
1082
+ this_1 = this;
1083
+ _o.label = 2;
1084
+ case 2:
1085
+ _o.trys.push([2, 7, 8, 9]);
1086
+ campaigns_1 = __values(campaigns), campaigns_1_1 = campaigns_1.next();
1087
+ _o.label = 3;
1088
+ case 3:
1089
+ if (!!campaigns_1_1.done) return [3 /*break*/, 6];
1090
+ campaign = campaigns_1_1.value;
1091
+ return [5 /*yield**/, _loop_1(campaign)];
1092
+ case 4:
1093
+ _o.sent();
1094
+ _o.label = 5;
1095
+ case 5:
1096
+ campaigns_1_1 = campaigns_1.next();
1097
+ return [3 /*break*/, 3];
1098
+ case 6: return [3 /*break*/, 9];
1099
+ case 7:
1100
+ e_1_1 = _o.sent();
1101
+ e_1 = { error: e_1_1 };
1102
+ return [3 /*break*/, 9];
1103
+ case 8:
1036
1104
  try {
1037
- for (campaigns_1 = __values(campaigns), campaigns_1_1 = campaigns_1.next(); !campaigns_1_1.done; campaigns_1_1 = campaigns_1.next()) {
1038
- campaign = campaigns_1_1.value;
1039
- _loop_1(campaign);
1040
- }
1041
- }
1042
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1043
- finally {
1044
- try {
1045
- if (campaigns_1_1 && !campaigns_1_1.done && (_k = campaigns_1.return)) _k.call(campaigns_1);
1046
- }
1047
- finally { if (e_3) throw e_3.error; }
1105
+ if (campaigns_1_1 && !campaigns_1_1.done && (_k = campaigns_1.return)) _k.call(campaigns_1);
1048
1106
  }
1107
+ finally { if (e_1) throw e_1.error; }
1108
+ return [7 /*endfinally*/];
1109
+ case 9:
1049
1110
  if (!elegibleCampaigns.length)
1050
1111
  return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
1051
1112
  campaingnProducts = [];
1052
- _o.label = 2;
1053
- case 2:
1054
- _o.trys.push([2, 14, 15, 16]);
1113
+ _o.label = 10;
1114
+ case 10:
1115
+ _o.trys.push([10, 22, 23, 24]);
1055
1116
  elegibleCampaigns_1 = __values(elegibleCampaigns), elegibleCampaigns_1_1 = elegibleCampaigns_1.next();
1056
- _o.label = 3;
1057
- case 3:
1058
- if (!!elegibleCampaigns_1_1.done) return [3 /*break*/, 13];
1117
+ _o.label = 11;
1118
+ case 11:
1119
+ if (!!elegibleCampaigns_1_1.done) return [3 /*break*/, 21];
1059
1120
  campaign = elegibleCampaigns_1_1.value;
1060
1121
  elegibleProducts = [];
1061
- _o.label = 4;
1062
- case 4:
1063
- _o.trys.push([4, 9, 10, 11]);
1064
- _h = (e_1 = void 0, __values(campaign.products)), _j = _h.next();
1065
- _o.label = 5;
1066
- case 5:
1067
- if (!!_j.done) return [3 /*break*/, 8];
1122
+ _o.label = 12;
1123
+ case 12:
1124
+ _o.trys.push([12, 17, 18, 19]);
1125
+ _h = (e_2 = void 0, __values(campaign.products)), _j = _h.next();
1126
+ _o.label = 13;
1127
+ case 13:
1128
+ if (!!_j.done) return [3 /*break*/, 16];
1068
1129
  product = _j.value;
1069
1130
  return [4 /*yield*/, this.productRepository.find({ filters: { sku: product } })];
1070
- case 6:
1131
+ case 14:
1071
1132
  productData = (_o.sent()).data;
1072
1133
  if (!productData.length)
1073
- return [3 /*break*/, 7];
1134
+ return [3 /*break*/, 15];
1074
1135
  gift = productData.shift();
1075
1136
  if (gift.stock.quantity < 1)
1076
- return [3 /*break*/, 7];
1137
+ return [3 /*break*/, 15];
1077
1138
  elegibleProducts.push(gift);
1078
- _o.label = 7;
1079
- case 7:
1139
+ _o.label = 15;
1140
+ case 15:
1080
1141
  _j = _h.next();
1081
- return [3 /*break*/, 5];
1082
- case 8: return [3 /*break*/, 11];
1083
- case 9:
1084
- e_1_1 = _o.sent();
1085
- e_1 = { error: e_1_1 };
1086
- return [3 /*break*/, 11];
1087
- case 10:
1142
+ return [3 /*break*/, 13];
1143
+ case 16: return [3 /*break*/, 19];
1144
+ case 17:
1145
+ e_2_1 = _o.sent();
1146
+ e_2 = { error: e_2_1 };
1147
+ return [3 /*break*/, 19];
1148
+ case 18:
1088
1149
  try {
1089
1150
  if (_j && !_j.done && (_m = _h.return)) _m.call(_h);
1090
1151
  }
1091
- finally { if (e_1) throw e_1.error; }
1152
+ finally { if (e_2) throw e_2.error; }
1092
1153
  return [7 /*endfinally*/];
1093
- case 11:
1154
+ case 19:
1094
1155
  campaingnProducts.push(elegibleProducts);
1095
- _o.label = 12;
1096
- case 12:
1156
+ _o.label = 20;
1157
+ case 20:
1097
1158
  elegibleCampaigns_1_1 = elegibleCampaigns_1.next();
1098
- return [3 /*break*/, 3];
1099
- case 13: return [3 /*break*/, 16];
1100
- case 14:
1101
- e_2_1 = _o.sent();
1102
- e_2 = { error: e_2_1 };
1103
- return [3 /*break*/, 16];
1104
- case 15:
1159
+ return [3 /*break*/, 11];
1160
+ case 21: return [3 /*break*/, 24];
1161
+ case 22:
1162
+ e_3_1 = _o.sent();
1163
+ e_3 = { error: e_3_1 };
1164
+ return [3 /*break*/, 24];
1165
+ case 23:
1105
1166
  try {
1106
1167
  if (elegibleCampaigns_1_1 && !elegibleCampaigns_1_1.done && (_l = elegibleCampaigns_1.return)) _l.call(elegibleCampaigns_1);
1107
1168
  }
1108
- finally { if (e_2) throw e_2.error; }
1169
+ finally { if (e_3) throw e_3.error; }
1109
1170
  return [7 /*endfinally*/];
1110
- case 16:
1171
+ case 24:
1111
1172
  if (!campaingnProducts.length)
1112
1173
  return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
1113
1174
  gifts = this.giftToLineItems([].concat.apply([], __spreadArray([], __read(campaingnProducts))));
@@ -1141,7 +1202,7 @@
1141
1202
  };
1142
1203
  return CartService;
1143
1204
  }());
1144
- 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' }, { token: 'Buy2WinRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1205
+ 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: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1145
1206
  CartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService });
1146
1207
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, decorators: [{
1147
1208
  type: i0.Injectable
@@ -1152,6 +1213,9 @@
1152
1213
  }] }, { type: undefined, decorators: [{
1153
1214
  type: i0.Inject,
1154
1215
  args: ['ProductRepository']
1216
+ }] }, { type: undefined, decorators: [{
1217
+ type: i0.Inject,
1218
+ args: ['CategoryRepository']
1155
1219
  }] }, { type: undefined, decorators: [{
1156
1220
  type: i0.Inject,
1157
1221
  args: ['VariantRepository']