@infrab4a/connect-angular 3.11.0-beta.1 → 3.11.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.
@@ -865,11 +865,23 @@
865
865
  {
866
866
  provide: i1.CategoryCollectionChildrenHasuraGraphQLRepository,
867
867
  useFactory: function (options) { return new i1.CategoryCollectionChildrenHasuraGraphQLRepository(options.endpoint, options.credentials); },
868
+ deps: ['HasuraConfig'],
868
869
  },
869
870
  {
870
871
  provide: 'CategoryCollectionChildrenRepository',
871
872
  useExisting: i1.CategoryCollectionChildrenHasuraGraphQLRepository,
872
873
  },
874
+ {
875
+ provide: i1.WishlistHasuraGraphQLRepository,
876
+ useFactory: function (options, categoryFilterRepository) {
877
+ return new i1.WishlistHasuraGraphQLRepository(options.endpoint, options.credentials, categoryFilterRepository);
878
+ },
879
+ deps: ['HasuraConfig', i1.CategoryFilterHasuraGraphQLRepository],
880
+ },
881
+ {
882
+ provide: 'WishlistRepository',
883
+ useExisting: i1.WishlistHasuraGraphQLRepository,
884
+ },
873
885
  ] });
874
886
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularHasuraGraphQLModule, decorators: [{
875
887
  type: i0.NgModule,
@@ -944,11 +956,23 @@
944
956
  {
945
957
  provide: i1.CategoryCollectionChildrenHasuraGraphQLRepository,
946
958
  useFactory: function (options) { return new i1.CategoryCollectionChildrenHasuraGraphQLRepository(options.endpoint, options.credentials); },
959
+ deps: ['HasuraConfig'],
947
960
  },
948
961
  {
949
962
  provide: 'CategoryCollectionChildrenRepository',
950
963
  useExisting: i1.CategoryCollectionChildrenHasuraGraphQLRepository,
951
964
  },
965
+ {
966
+ provide: i1.WishlistHasuraGraphQLRepository,
967
+ useFactory: function (options, categoryFilterRepository) {
968
+ return new i1.WishlistHasuraGraphQLRepository(options.endpoint, options.credentials, categoryFilterRepository);
969
+ },
970
+ deps: ['HasuraConfig', i1.CategoryFilterHasuraGraphQLRepository],
971
+ },
972
+ {
973
+ provide: 'WishlistRepository',
974
+ useExisting: i1.WishlistHasuraGraphQLRepository,
975
+ },
952
976
  ],
953
977
  }]
954
978
  }] });
@@ -1035,7 +1059,7 @@
1035
1059
  };
1036
1060
  CouponService.prototype.couponRulesValidation = function (coupon, checkoutType, checkout, plan) {
1037
1061
  return __awaiter(this, void 0, void 0, function () {
1038
- var validUser, orders, ordersWithUser, couponUseLimits, hasProductCategories, hasMinSubTotal;
1062
+ var validUser, couponUseLimits, orders, ordersWithUser, hasProductCategories, hasMinSubTotal;
1039
1063
  return __generator(this, function (_c) {
1040
1064
  switch (_c.label) {
1041
1065
  case 0:
@@ -1047,22 +1071,26 @@
1047
1071
  validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
1048
1072
  if (!validUser)
1049
1073
  throw 'Usuário não elegível.';
1074
+ couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
1075
+ if (!(!couponUseLimits.unlimited || couponUseLimits.limitedPerUser)) return [3 /*break*/, 2];
1050
1076
  return [4 /*yield*/, this.getOrdersWithCoupon(coupon)];
1051
1077
  case 1:
1052
1078
  orders = _c.sent();
1053
- ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
1054
- couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
1055
- if (couponUseLimits.limitedPerUser && ordersWithUser > 0)
1056
- throw 'Limite de uso por usuário atingido.';
1057
1079
  if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
1058
1080
  throw 'Limite de uso atingido.';
1059
- return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
1060
- case 2:
1081
+ if (couponUseLimits.limitedPerUser) {
1082
+ ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
1083
+ if (ordersWithUser > 0)
1084
+ throw 'Limite de uso por usuário atingido.';
1085
+ }
1086
+ _c.label = 2;
1087
+ case 2: return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
1088
+ case 3:
1061
1089
  hasProductCategories = _c.sent();
1062
1090
  if (!hasProductCategories)
1063
1091
  throw 'Seu carrinho não possui produtos elegíveis para desconto.';
1064
1092
  return [4 /*yield*/, this.hasMinSubTotal(coupon, checkout)];
1065
- case 3:
1093
+ case 4:
1066
1094
  hasMinSubTotal = _c.sent();
1067
1095
  if (!hasMinSubTotal)
1068
1096
  throw "Valor m\u00EDnimo de " + Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue) + " n\u00E3o atingido";
@@ -1833,10 +1861,11 @@
1833
1861
  } });
1834
1862
 
1835
1863
  var CatalogService = /** @class */ (function () {
1836
- function CatalogService(productRepository, categoryStructureAdapter, shop) {
1864
+ function CatalogService(productRepository, categoryStructureAdapter, shop, productIndex) {
1837
1865
  this.productRepository = productRepository;
1838
1866
  this.categoryStructureAdapter = categoryStructureAdapter;
1839
1867
  this.shop = shop;
1868
+ this.productIndex = productIndex;
1840
1869
  this.buildFilterQuery = function (_j) {
1841
1870
  var clubDiscount = _j.clubDiscount, brands = _j.brands, prices = _j.prices, gender = _j.gender, tags = _j.tags, rate = _j.rate, customOptions = _j.customOptions;
1842
1871
  var filters = {};
@@ -1882,47 +1911,89 @@
1882
1911
  offset: (((options === null || options === void 0 ? void 0 : options.page) || 1) - 1) * limit,
1883
1912
  };
1884
1913
  };
1914
+ this.hasProfile = function (options) { return 'profile' in options; };
1915
+ this.hasTerm = function (options) { return 'term' in options; };
1916
+ this.hasCategory = function (options) { return 'category' in options; };
1885
1917
  }
1886
- CatalogService.prototype.fetchProducts = function (category, options) {
1918
+ CatalogService.prototype.fetchProducts = function (options) {
1919
+ var _a, _b, _c;
1887
1920
  return __awaiter(this, void 0, void 0, function () {
1888
- var limits, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
1889
- return __generator(this, function (_w) {
1890
- switch (_w.label) {
1921
+ var limits;
1922
+ return __generator(this, function (_j) {
1923
+ switch (_j.label) {
1891
1924
  case 0:
1892
1925
  limits = this.buildLimitQuery(options);
1893
- _k = (_j = this.productRepository)
1894
- .findCatalog;
1926
+ if (this.hasProfile(options) && ((_a = options.filters) === null || _a === void 0 ? void 0 : _a.customOptions))
1927
+ throw new i1.InvalidArgumentError("It couldn't filled customOptions when profile is given");
1928
+ if (this.hasProfile(options) && ((_b = options.filters) === null || _b === void 0 ? void 0 : _b.tags))
1929
+ throw new i1.InvalidArgumentError("It couldn't filled tags when profile is given");
1930
+ if (this.hasTerm(options) && ((_c = options.filters) === null || _c === void 0 ? void 0 : _c.customOptions))
1931
+ throw new i1.InvalidArgumentError("It couldn't filled customOptions when term is given");
1932
+ return [4 /*yield*/, this.findCatalog(options, limits).then(function (_j) {
1933
+ var data = _j.data, total = _j.count, maximum = _j.maximum, minimal = _j.minimal, distinct = _j.distinct;
1934
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1935
+ return ({
1936
+ products: { data: data.map(function (product) { return i1.RoundProductPricesHelper.roundProductPrices(product); }), total: total },
1937
+ pages: Math.ceil(total / limits.limit),
1938
+ prices: {
1939
+ price: { min: +((_b = (_a = minimal === null || minimal === void 0 ? void 0 : minimal.price) === null || _a === void 0 ? void 0 : _a.price) === null || _b === void 0 ? void 0 : _b.toFixed(2)), max: +((_d = (_c = maximum === null || maximum === void 0 ? void 0 : maximum.price) === null || _c === void 0 ? void 0 : _c.price) === null || _d === void 0 ? void 0 : _d.toFixed(2)) },
1940
+ subscriberPrice: {
1941
+ min: +((_f = (_e = minimal === null || minimal === void 0 ? void 0 : minimal.price) === null || _e === void 0 ? void 0 : _e.subscriberPrice) === null || _f === void 0 ? void 0 : _f.toFixed(2)),
1942
+ max: +((_h = (_g = maximum === null || maximum === void 0 ? void 0 : maximum.price) === null || _g === void 0 ? void 0 : _g.subscriberPrice) === null || _h === void 0 ? void 0 : _h.toFixed(2)),
1943
+ },
1944
+ },
1945
+ brands: distinct === null || distinct === void 0 ? void 0 : distinct.brand,
1946
+ });
1947
+ })];
1948
+ case 1: return [2 /*return*/, _j.sent()];
1949
+ }
1950
+ });
1951
+ });
1952
+ };
1953
+ CatalogService.prototype.findCatalog = function (options, limits) {
1954
+ return __awaiter(this, void 0, void 0, function () {
1955
+ var repoParams, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
1956
+ return __generator(this, function (_u) {
1957
+ switch (_u.label) {
1958
+ case 0:
1959
+ _k = (_j = Object).assign;
1895
1960
  _m = (_l = Object).assign;
1896
- _p = (_o = Object).assign;
1897
- _q = {};
1961
+ _o = {};
1962
+ _q = (_p = Object).assign;
1898
1963
  _s = (_r = Object).assign;
1899
- _u = (_t = Object).assign;
1900
- _v = [{}];
1901
- return [4 /*yield*/, this.categoryStructureAdapter.buildProductFilterByCategory(category)];
1902
- case 1: return [4 /*yield*/, _k.apply(_j, [_m.apply(_l, [_p.apply(_o, [(_q.filters = _s.apply(_r, [_u.apply(_t, _v.concat([(_w.sent())])), this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})]), _q), ((options === null || options === void 0 ? void 0 : options.sort) ? { orderBy: this.buildSortQuery(options === null || options === void 0 ? void 0 : options.sort) } : {})]), { limits: limits, options: { minimal: ['price'], maximum: ['price'] } }]), (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === i1.Shops.MENSMARKET ? 'male' : 'female'])
1903
- .then(function (_j) {
1904
- var data = _j.data, total = _j.count, maximum = _j.maximum, minimal = _j.minimal;
1905
- var _a, _b, _c, _d, _e, _f, _g, _h;
1906
- return ({
1907
- products: { data: data.map(function (product) { return i1.RoundProductPricesHelper.roundProductPrices(product); }), total: total },
1908
- pages: Math.ceil(total / limits.limit),
1909
- prices: {
1910
- price: { min: +((_b = (_a = minimal === null || minimal === void 0 ? void 0 : minimal.price) === null || _a === void 0 ? void 0 : _a.price) === null || _b === void 0 ? void 0 : _b.toFixed(2)), max: +((_d = (_c = maximum === null || maximum === void 0 ? void 0 : maximum.price) === null || _c === void 0 ? void 0 : _c.price) === null || _d === void 0 ? void 0 : _d.toFixed(2)) },
1911
- subscriberPrice: {
1912
- min: +((_f = (_e = minimal === null || minimal === void 0 ? void 0 : minimal.price) === null || _e === void 0 ? void 0 : _e.subscriberPrice) === null || _f === void 0 ? void 0 : _f.toFixed(2)),
1913
- max: +((_h = (_g = maximum === null || maximum === void 0 ? void 0 : maximum.price) === null || _g === void 0 ? void 0 : _g.subscriberPrice) === null || _h === void 0 ? void 0 : _h.toFixed(2)),
1914
- },
1915
- },
1916
- });
1917
- })];
1918
- case 2: return [2 /*return*/, _w.sent()];
1964
+ _t = [{}];
1965
+ return [4 /*yield*/, this.buildMainFilter(options)];
1966
+ case 1:
1967
+ repoParams = _k.apply(_j, [_m.apply(_l, [(_o.filters = _q.apply(_p, [_s.apply(_r, _t.concat([(_u.sent())])), this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})]), _o), ((options === null || options === void 0 ? void 0 : options.sort) ? { orderBy: this.buildSortQuery(options === null || options === void 0 ? void 0 : options.sort) } : {})]), { limits: limits, options: Object.assign({ minimal: ['price'], maximum: ['price'] }, (!this.hasCategory(options) ? { distinct: ['brand'] } : {})) }]);
1968
+ if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1969
+ return [2 /*return*/, this.productRepository.findCatalog(repoParams)];
1970
+ return [2 /*return*/, this.productRepository.findCatalog(repoParams, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === i1.Shops.MENSMARKET ? 'male' : 'female')];
1919
1971
  }
1920
1972
  });
1921
1973
  });
1922
1974
  };
1975
+ CatalogService.prototype.buildMainFilter = function (_j) {
1976
+ var category = _j.category, profile = _j.profile, term = _j.term;
1977
+ return __awaiter(this, void 0, void 0, function () {
1978
+ return __generator(this, function (_j) {
1979
+ if (category)
1980
+ return [2 /*return*/, this.categoryStructureAdapter.buildProductFilterByCategory(category)];
1981
+ if (profile)
1982
+ return [2 /*return*/, { tags: { operator: i1.Where.LIKE, value: profile } }];
1983
+ if (term)
1984
+ return [2 /*return*/, this.productIndex
1985
+ .search(term, 9999, this.shop)
1986
+ .then(function (data) { return ({ id: { operator: i1.Where.IN, value: data.hits.map(function (_j) {
1987
+ var _source = _j._source;
1988
+ return _source.id;
1989
+ }) } }); })];
1990
+ return [2 /*return*/];
1991
+ });
1992
+ });
1993
+ };
1923
1994
  return CatalogService;
1924
1995
  }());
1925
- CatalogService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1996
+ CatalogService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: i1__namespace$1.ProductsIndex }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1926
1997
  CatalogService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CatalogService });
1927
1998
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CatalogService, decorators: [{
1928
1999
  type: i0.Injectable
@@ -1936,7 +2007,7 @@
1936
2007
  }] }, { type: i1__namespace$1.Shops, decorators: [{
1937
2008
  type: i0.Inject,
1938
2009
  args: [DEFAULT_SHOP]
1939
- }] }];
2010
+ }] }, { type: i1__namespace$1.ProductsIndex }];
1940
2011
  } });
1941
2012
 
1942
2013
  var CategoryService = /** @class */ (function () {
@@ -2042,6 +2113,268 @@
2042
2113
  __metadata("design:type", Array)
2043
2114
  ], CategoryWithTree.prototype, "children", void 0);
2044
2115
 
2116
+ var UtilHelper = /** @class */ (function () {
2117
+ function UtilHelper() {
2118
+ }
2119
+ UtilHelper.createSlug = function (name) {
2120
+ return name
2121
+ .toLowerCase()
2122
+ .replace(/\s+/g, '-') // Replace spaces with -
2123
+ .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
2124
+ .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
2125
+ .replace(/[ìíïî]/g, 'i') // Replace spaces with -
2126
+ .replace(/[õòóöô]/g, 'o') // Replace spaces with -
2127
+ .replace(/[ùúüû]/g, 'u') // Replace spaces with -
2128
+ .replace(/[ñ]/g, 'n') // Replace spaces with -
2129
+ .replace(/[ç]/g, 'c') // Replace spaces with -
2130
+ .replace(/[&]/g, 'and') // Replace spaces with -
2131
+ .replace(/[^\w\-]+/g, '') // Remove all non-word chars
2132
+ .replace(/\-\-+/g, '-'); // Replace multiple - with single -
2133
+ };
2134
+ return UtilHelper;
2135
+ }());
2136
+
2137
+ var NewCategoryStructureAdapter = /** @class */ (function () {
2138
+ function NewCategoryStructureAdapter(categoryRepository, categoryCollectionChildrenRepository) {
2139
+ this.categoryRepository = categoryRepository;
2140
+ this.categoryCollectionChildrenRepository = categoryCollectionChildrenRepository;
2141
+ }
2142
+ NewCategoryStructureAdapter.prototype.buildProductFilterByCategory = function (category) {
2143
+ return __awaiter(this, void 0, void 0, function () {
2144
+ var categoriesIds, _a, _b;
2145
+ return __generator(this, function (_c) {
2146
+ switch (_c.label) {
2147
+ case 0: return [4 /*yield*/, this.isCollection(category)];
2148
+ case 1:
2149
+ if (!(_c.sent())) return [3 /*break*/, 3];
2150
+ return [4 /*yield*/, this.getAllCategoriesIdFromCollection(category)];
2151
+ case 2:
2152
+ _a = _c.sent();
2153
+ return [3 /*break*/, 5];
2154
+ case 3:
2155
+ _b = [[]];
2156
+ return [4 /*yield*/, this.getAllCategoriesIdFromCategory(category)];
2157
+ case 4:
2158
+ _a = __spreadArray.apply(void 0, [__spreadArray.apply(void 0, _b.concat([__read.apply(void 0, [(_c.sent())])])), [category.id.toString()]]);
2159
+ _c.label = 5;
2160
+ case 5:
2161
+ categoriesIds = _a;
2162
+ return [2 /*return*/, { category: { id: { operator: i1.Where.IN, value: categoriesIds } } }];
2163
+ }
2164
+ });
2165
+ });
2166
+ };
2167
+ NewCategoryStructureAdapter.prototype.getAllCategoriesIdFromCategory = function (category) {
2168
+ return __awaiter(this, void 0, void 0, function () {
2169
+ return __generator(this, function (_a) {
2170
+ return [2 /*return*/, this.categoryRepository
2171
+ .getChildren(+category.id)
2172
+ .then(function (categories) { return categories.map(function (category) { return category.id.toString(); }); })];
2173
+ });
2174
+ });
2175
+ };
2176
+ NewCategoryStructureAdapter.prototype.getAllCategoriesIdFromCollection = function (category) {
2177
+ return __awaiter(this, void 0, void 0, function () {
2178
+ return __generator(this, function (_a) {
2179
+ return [2 /*return*/, this.categoryCollectionChildrenRepository
2180
+ .find({ filters: { collectionId: +category.id } })
2181
+ .then(function (_a) {
2182
+ var data = _a.data;
2183
+ return data.map(function (categoryCollection) { return categoryCollection.categoryId.toString(); });
2184
+ })];
2185
+ });
2186
+ });
2187
+ };
2188
+ NewCategoryStructureAdapter.prototype.isCollection = function (category) {
2189
+ return __awaiter(this, void 0, void 0, function () {
2190
+ return __generator(this, function (_a) {
2191
+ return [2 /*return*/, !i1.isNil(category.isCollection)
2192
+ ? category.isCollection
2193
+ : this.categoryRepository.get({ id: category.id }).then(function (category) { return category.isCollection; })];
2194
+ });
2195
+ });
2196
+ };
2197
+ return NewCategoryStructureAdapter;
2198
+ }());
2199
+ NewCategoryStructureAdapter.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }, { token: 'CategoryCollectionChildrenRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2200
+ NewCategoryStructureAdapter.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: NewCategoryStructureAdapter });
2201
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: NewCategoryStructureAdapter, decorators: [{
2202
+ type: i0.Injectable
2203
+ }], ctorParameters: function () {
2204
+ return [{ type: undefined, decorators: [{
2205
+ type: i0.Inject,
2206
+ args: ['CategoryRepository']
2207
+ }] }, { type: undefined, decorators: [{
2208
+ type: i0.Inject,
2209
+ args: ['CategoryCollectionChildrenRepository']
2210
+ }] }];
2211
+ } });
2212
+
2213
+ var OldCategoryStructureAdapter = /** @class */ (function () {
2214
+ function OldCategoryStructureAdapter(categoryRepository) {
2215
+ this.categoryRepository = categoryRepository;
2216
+ }
2217
+ OldCategoryStructureAdapter.prototype.buildProductFilterByCategory = function (category) {
2218
+ var _a;
2219
+ return __awaiter(this, void 0, void 0, function () {
2220
+ var productsIds, _b;
2221
+ return __generator(this, function (_c) {
2222
+ switch (_c.label) {
2223
+ case 0:
2224
+ if (!((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 1];
2225
+ _b = category.products;
2226
+ return [3 /*break*/, 3];
2227
+ case 1: return [4 /*yield*/, this.categoryRepository.get({ id: category.id }).then(function (categoryFound) { return categoryFound.products; })];
2228
+ case 2:
2229
+ _b = _c.sent();
2230
+ _c.label = 3;
2231
+ case 3:
2232
+ productsIds = _b;
2233
+ return [2 /*return*/, { id: { operator: i1.Where.IN, value: productsIds } }];
2234
+ }
2235
+ });
2236
+ });
2237
+ };
2238
+ return OldCategoryStructureAdapter;
2239
+ }());
2240
+ OldCategoryStructureAdapter.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2241
+ OldCategoryStructureAdapter.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: OldCategoryStructureAdapter });
2242
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: OldCategoryStructureAdapter, decorators: [{
2243
+ type: i0.Injectable
2244
+ }], ctorParameters: function () {
2245
+ return [{ type: undefined, decorators: [{
2246
+ type: i0.Inject,
2247
+ args: ['CategoryRepository']
2248
+ }] }];
2249
+ } });
2250
+
2251
+ var WishlistService = /** @class */ (function () {
2252
+ function WishlistService(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryCollectionChildrenRepository, productIndex) {
2253
+ this.wishlistRepository = wishlistRepository;
2254
+ this.shop = shop;
2255
+ var categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository, categoryCollectionChildrenRepository);
2256
+ this.catalogService = new CatalogService(productRepository, categoryStructureAdapter, shop, productIndex);
2257
+ this.categoryService = new CategoryService(productRepository, wishlistRepository, categoryFilterRepository, categoryStructureAdapter, shop);
2258
+ }
2259
+ WishlistService.prototype.getCatalogService = function () {
2260
+ return this.catalogService;
2261
+ };
2262
+ WishlistService.prototype.getCategoryService = function () {
2263
+ return this.categoryService;
2264
+ };
2265
+ WishlistService.prototype.create = function (personId, title, description, userFullName) {
2266
+ return __awaiter(this, void 0, void 0, function () {
2267
+ var data, newWishlist;
2268
+ return __generator(this, function (_a) {
2269
+ switch (_a.label) {
2270
+ case 0:
2271
+ data = {
2272
+ slug: UtilHelper.createSlug("favoritos " + userFullName + " " + title),
2273
+ name: title,
2274
+ description: description,
2275
+ metadata: {
2276
+ title: userFullName + " - " + title,
2277
+ description: userFullName + " - " + description,
2278
+ },
2279
+ shop: this.shop,
2280
+ shops: [this.shop],
2281
+ personId: personId,
2282
+ brandCategory: false,
2283
+ published: true,
2284
+ };
2285
+ return [4 /*yield*/, this.wishlistRepository.create(data)];
2286
+ case 1:
2287
+ newWishlist = _a.sent();
2288
+ return [2 /*return*/, this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id + "-" + newWishlist.slug })];
2289
+ }
2290
+ });
2291
+ });
2292
+ };
2293
+ WishlistService.prototype.update = function (id, title, description, userFullName) {
2294
+ var data = {
2295
+ id: id,
2296
+ slug: UtilHelper.createSlug(id + "-favoritos " + userFullName + " " + title),
2297
+ name: title,
2298
+ description: description,
2299
+ metadata: {
2300
+ title: userFullName + " - " + title,
2301
+ description: userFullName + " - " + description,
2302
+ },
2303
+ };
2304
+ return this.wishlistRepository.update(data);
2305
+ };
2306
+ WishlistService.prototype.delete = function (wishlistId) {
2307
+ return this.wishlistRepository.delete({ id: wishlistId });
2308
+ };
2309
+ WishlistService.prototype.getWishlistBySlug = function (slug) {
2310
+ return this.wishlistRepository.getWishlistBySlug(slug);
2311
+ };
2312
+ WishlistService.prototype.getWishlistsByPerson = function (personId) {
2313
+ return this.wishlistRepository.getWishlistByPerson(personId);
2314
+ };
2315
+ WishlistService.prototype.addProduct = function (wishlistId, productId) {
2316
+ return __awaiter(this, void 0, void 0, function () {
2317
+ var wishlist, hasProduct;
2318
+ return __generator(this, function (_a) {
2319
+ switch (_a.label) {
2320
+ case 0: return [4 /*yield*/, this.wishlistRepository.get({ id: wishlistId })];
2321
+ case 1:
2322
+ wishlist = _a.sent();
2323
+ hasProduct = wishlist.products.some(function (p) { return p == productId; });
2324
+ if (!hasProduct) {
2325
+ wishlist.products = __spreadArray(__spreadArray([], __read(wishlist.products)), [productId]);
2326
+ return [2 /*return*/, this.wishlistRepository.update({ id: wishlistId, products: wishlist.products })];
2327
+ }
2328
+ return [2 /*return*/, wishlist];
2329
+ }
2330
+ });
2331
+ });
2332
+ };
2333
+ WishlistService.prototype.removeProduct = function (wishlistId, productId) {
2334
+ return __awaiter(this, void 0, void 0, function () {
2335
+ var wishlist, productIndex;
2336
+ return __generator(this, function (_a) {
2337
+ switch (_a.label) {
2338
+ case 0: return [4 /*yield*/, this.wishlistRepository.get({ id: wishlistId })];
2339
+ case 1:
2340
+ wishlist = _a.sent();
2341
+ productIndex = wishlist.products.findIndex(function (p) { return p == productId; });
2342
+ if (productIndex != -1) {
2343
+ wishlist.products.splice(productIndex, 1);
2344
+ if (!wishlist.products.length)
2345
+ return [2 /*return*/, this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } })];
2346
+ return [2 /*return*/, this.wishlistRepository.update({ id: wishlistId, products: wishlist.products })];
2347
+ }
2348
+ return [2 /*return*/, wishlist];
2349
+ }
2350
+ });
2351
+ });
2352
+ };
2353
+ return WishlistService;
2354
+ }());
2355
+ WishlistService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryCollectionChildrenRepository' }, { token: i1__namespace$1.ProductsIndex }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2356
+ WishlistService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: WishlistService });
2357
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: WishlistService, decorators: [{
2358
+ type: i0.Injectable
2359
+ }], ctorParameters: function () {
2360
+ return [{ type: undefined, decorators: [{
2361
+ type: i0.Inject,
2362
+ args: ['WishlistRepository']
2363
+ }] }, { type: i1__namespace$1.Shops, decorators: [{
2364
+ type: i0.Inject,
2365
+ args: [DEFAULT_SHOP]
2366
+ }] }, { type: undefined, decorators: [{
2367
+ type: i0.Inject,
2368
+ args: ['ProductRepository']
2369
+ }] }, { type: undefined, decorators: [{
2370
+ type: i0.Inject,
2371
+ args: ['CategoryFilterRepository']
2372
+ }] }, { type: undefined, decorators: [{
2373
+ type: i0.Inject,
2374
+ args: ['CategoryCollectionChildrenRepository']
2375
+ }] }, { type: i1__namespace$1.ProductsIndex }];
2376
+ } });
2377
+
2045
2378
  var CheckoutSubscriptionService = /** @class */ (function () {
2046
2379
  function CheckoutSubscriptionService(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
2047
2380
  this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
@@ -2347,120 +2680,6 @@
2347
2680
  }] }, { type: HomeShopService }];
2348
2681
  } });
2349
2682
 
2350
- var NewCategoryStructureAdapter = /** @class */ (function () {
2351
- function NewCategoryStructureAdapter(categoryRepository, categoryCollectionChildrenRepository) {
2352
- this.categoryRepository = categoryRepository;
2353
- this.categoryCollectionChildrenRepository = categoryCollectionChildrenRepository;
2354
- }
2355
- NewCategoryStructureAdapter.prototype.buildProductFilterByCategory = function (category) {
2356
- return __awaiter(this, void 0, void 0, function () {
2357
- var categoriesIds, _a, _b;
2358
- return __generator(this, function (_c) {
2359
- switch (_c.label) {
2360
- case 0: return [4 /*yield*/, this.isCollection(category)];
2361
- case 1:
2362
- if (!(_c.sent())) return [3 /*break*/, 3];
2363
- return [4 /*yield*/, this.getAllCategoriesIdFromCollection(category)];
2364
- case 2:
2365
- _a = _c.sent();
2366
- return [3 /*break*/, 5];
2367
- case 3:
2368
- _b = [[]];
2369
- return [4 /*yield*/, this.getAllCategoriesIdFromCategory(category)];
2370
- case 4:
2371
- _a = __spreadArray.apply(void 0, [__spreadArray.apply(void 0, _b.concat([__read.apply(void 0, [(_c.sent())])])), [category.id.toString()]]);
2372
- _c.label = 5;
2373
- case 5:
2374
- categoriesIds = _a;
2375
- return [2 /*return*/, { category: { id: { operator: i1.Where.IN, value: categoriesIds } } }];
2376
- }
2377
- });
2378
- });
2379
- };
2380
- NewCategoryStructureAdapter.prototype.getAllCategoriesIdFromCategory = function (category) {
2381
- return __awaiter(this, void 0, void 0, function () {
2382
- return __generator(this, function (_a) {
2383
- return [2 /*return*/, this.categoryRepository
2384
- .getChildren(+category.id)
2385
- .then(function (categories) { return categories.map(function (category) { return category.id.toString(); }); })];
2386
- });
2387
- });
2388
- };
2389
- NewCategoryStructureAdapter.prototype.getAllCategoriesIdFromCollection = function (category) {
2390
- return __awaiter(this, void 0, void 0, function () {
2391
- return __generator(this, function (_a) {
2392
- return [2 /*return*/, this.categoryCollectionChildrenRepository
2393
- .find({ filters: { collectionId: +category.id } })
2394
- .then(function (_a) {
2395
- var data = _a.data;
2396
- return data.map(function (categoryCollection) { return categoryCollection.categoryId.toString(); });
2397
- })];
2398
- });
2399
- });
2400
- };
2401
- NewCategoryStructureAdapter.prototype.isCollection = function (category) {
2402
- return __awaiter(this, void 0, void 0, function () {
2403
- return __generator(this, function (_a) {
2404
- return [2 /*return*/, !i1.isNil(category.isCollection)
2405
- ? category.isCollection
2406
- : this.categoryRepository.get({ id: category.id }).then(function (category) { return category.isCollection; })];
2407
- });
2408
- });
2409
- };
2410
- return NewCategoryStructureAdapter;
2411
- }());
2412
- NewCategoryStructureAdapter.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }, { token: 'CategoryCollectionChildrenRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2413
- NewCategoryStructureAdapter.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: NewCategoryStructureAdapter });
2414
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: NewCategoryStructureAdapter, decorators: [{
2415
- type: i0.Injectable
2416
- }], ctorParameters: function () {
2417
- return [{ type: undefined, decorators: [{
2418
- type: i0.Inject,
2419
- args: ['CategoryRepository']
2420
- }] }, { type: undefined, decorators: [{
2421
- type: i0.Inject,
2422
- args: ['CategoryCollectionChildrenRepository']
2423
- }] }];
2424
- } });
2425
-
2426
- var OldCategoryStructureAdapter = /** @class */ (function () {
2427
- function OldCategoryStructureAdapter(categoryRepository) {
2428
- this.categoryRepository = categoryRepository;
2429
- }
2430
- OldCategoryStructureAdapter.prototype.buildProductFilterByCategory = function (category) {
2431
- var _a;
2432
- return __awaiter(this, void 0, void 0, function () {
2433
- var productsIds, _b;
2434
- return __generator(this, function (_c) {
2435
- switch (_c.label) {
2436
- case 0:
2437
- if (!((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 1];
2438
- _b = category.products;
2439
- return [3 /*break*/, 3];
2440
- case 1: return [4 /*yield*/, this.categoryRepository.get({ id: category.id }).then(function (categoryFound) { return categoryFound.products; })];
2441
- case 2:
2442
- _b = _c.sent();
2443
- _c.label = 3;
2444
- case 3:
2445
- productsIds = _b;
2446
- return [2 /*return*/, { id: { operator: i1.Where.IN, value: productsIds } }];
2447
- }
2448
- });
2449
- });
2450
- };
2451
- return OldCategoryStructureAdapter;
2452
- }());
2453
- OldCategoryStructureAdapter.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2454
- OldCategoryStructureAdapter.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: OldCategoryStructureAdapter });
2455
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: OldCategoryStructureAdapter, decorators: [{
2456
- type: i0.Injectable
2457
- }], ctorParameters: function () {
2458
- return [{ type: undefined, decorators: [{
2459
- type: i0.Inject,
2460
- args: ['CategoryRepository']
2461
- }] }];
2462
- } });
2463
-
2464
2683
  var AngularConnectModule = /** @class */ (function () {
2465
2684
  function AngularConnectModule() {
2466
2685
  }
@@ -2480,7 +2699,7 @@
2480
2699
  return AngularConnectModule;
2481
2700
  }());
2482
2701
  AngularConnectModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularConnectModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
2483
- AngularConnectModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularConnectModule, imports: [fire.AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
2702
+ AngularConnectModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularConnectModule, imports: [AngularElasticSeachModule, fire.AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
2484
2703
  AngularConnectModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularConnectModule, providers: [
2485
2704
  AuthService,
2486
2705
  CartService,
@@ -2492,11 +2711,12 @@
2492
2711
  HomeShopService,
2493
2712
  OrderService,
2494
2713
  ShippingService,
2495
- ], imports: [[fire.AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
2714
+ WishlistService,
2715
+ ], imports: [[AngularElasticSeachModule, fire.AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
2496
2716
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularConnectModule, decorators: [{
2497
2717
  type: i0.NgModule,
2498
2718
  args: [{
2499
- imports: [fire.AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
2719
+ imports: [AngularElasticSeachModule, fire.AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
2500
2720
  providers: [
2501
2721
  AuthService,
2502
2722
  CartService,
@@ -2508,6 +2728,7 @@
2508
2728
  HomeShopService,
2509
2729
  OrderService,
2510
2730
  ShippingService,
2731
+ WishlistService,
2511
2732
  ],
2512
2733
  }]
2513
2734
  }] });
@@ -2642,6 +2863,8 @@
2642
2863
  exports.HomeShopService = HomeShopService;
2643
2864
  exports.OrderService = OrderService;
2644
2865
  exports.ShippingService = ShippingService;
2866
+ exports.UtilHelper = UtilHelper;
2867
+ exports.WishlistService = WishlistService;
2645
2868
 
2646
2869
  Object.defineProperty(exports, '__esModule', { value: true });
2647
2870