@infrab4a/connect-angular 4.0.0-beta.32 → 4.0.0-beta.34

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.
Files changed (26) hide show
  1. package/angular-connect.module.d.ts +1 -0
  2. package/consts/category-structure.d.ts +1 -0
  3. package/consts/index.d.ts +1 -0
  4. package/esm2020/angular-connect.module.mjs +9 -2
  5. package/esm2020/angular-hasura-graphql.module.mjs +18 -2
  6. package/esm2020/consts/category-structure.mjs +2 -0
  7. package/esm2020/consts/index.mjs +2 -1
  8. package/esm2020/services/catalog/adapters/category-structure.adapter.mjs +2 -0
  9. package/esm2020/services/catalog/adapters/index.mjs +4 -0
  10. package/esm2020/services/catalog/adapters/new-category-structure.adapter.mjs +42 -0
  11. package/esm2020/services/catalog/adapters/old-category-structure.adapter.mjs +23 -0
  12. package/esm2020/services/catalog/catalog.service.mjs +28 -17
  13. package/esm2020/services/catalog/category.service.mjs +18 -17
  14. package/esm2020/services/catalog/enums/product-sorts.enum.mjs +2 -1
  15. package/fesm2015/infrab4a-connect-angular.mjs +154 -47
  16. package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
  17. package/fesm2020/infrab4a-connect-angular.mjs +133 -41
  18. package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
  19. package/package.json +2 -2
  20. package/services/catalog/adapters/category-structure.adapter.d.ts +4 -0
  21. package/services/catalog/adapters/index.d.ts +3 -0
  22. package/services/catalog/adapters/new-category-structure.adapter.d.ts +14 -0
  23. package/services/catalog/adapters/old-category-structure.adapter.d.ts +10 -0
  24. package/services/catalog/catalog.service.d.ts +8 -3
  25. package/services/catalog/category.service.d.ts +6 -5
  26. package/services/catalog/enums/product-sorts.enum.d.ts +2 -1
@@ -1,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, NgModule, PLATFORM_ID, Injectable, Inject } from '@angular/core';
3
- import * as i3 from '@infrab4a/connect';
4
- import { Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
3
+ import * as i1$3 from '@infrab4a/connect';
4
+ import { Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
5
5
  import * as i1 from '@angular/fire/app';
6
6
  import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
7
7
  import * as i1$1 from '@angular/fire/auth';
@@ -17,10 +17,12 @@ import { __awaiter, __decorate, __metadata } from 'tslib';
17
17
  import cookie from 'js-cookie';
18
18
  import { CustomError } from 'ts-custom-error';
19
19
  import { Type } from 'class-transformer';
20
- import * as i1$3 from '@angular/common/http';
20
+ import * as i1$4 from '@angular/common/http';
21
21
 
22
22
  const BACKEND_URL = 'BACKEND_URL';
23
23
 
24
+ const CATEGORY_STRUCTURE = 'CATEGORY_STRUCTURE';
25
+
24
26
  const DEFAULT_SHOP = 'DEFAULT_SHOP';
25
27
 
26
28
  const ES_CONFIG = 'ES_CONFIG';
@@ -717,6 +719,14 @@ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.
717
719
  },
718
720
  deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
719
721
  },
722
+ {
723
+ provide: CategoryCollectionChildrenHasuraGraphQLRepository,
724
+ useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options.endpoint, options.credentials),
725
+ },
726
+ {
727
+ provide: 'CategoryCollectionChildrenRepository',
728
+ useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
729
+ },
720
730
  ] });
721
731
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
722
732
  type: NgModule,
@@ -811,6 +821,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
811
821
  },
812
822
  deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
813
823
  },
824
+ {
825
+ provide: CategoryCollectionChildrenHasuraGraphQLRepository,
826
+ useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options.endpoint, options.credentials),
827
+ },
828
+ {
829
+ provide: 'CategoryCollectionChildrenRepository',
830
+ useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
831
+ },
814
832
  ],
815
833
  }]
816
834
  }] });
@@ -1070,7 +1088,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1070
1088
  return [{ type: undefined, decorators: [{
1071
1089
  type: Inject,
1072
1090
  args: ['CouponRepository']
1073
- }] }, { type: i3.Shops, decorators: [{
1091
+ }] }, { type: i1$3.Shops, decorators: [{
1074
1092
  type: Inject,
1075
1093
  args: [DEFAULT_SHOP]
1076
1094
  }] }, { type: undefined, decorators: [{
@@ -1142,7 +1160,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1142
1160
  }] }, { type: undefined, decorators: [{
1143
1161
  type: Inject,
1144
1162
  args: ['UserRepository']
1145
- }] }, { type: i3.Shops, decorators: [{
1163
+ }] }, { type: i1$3.Shops, decorators: [{
1146
1164
  type: Inject,
1147
1165
  args: [DEFAULT_SHOP]
1148
1166
  }] }];
@@ -1399,7 +1417,7 @@ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version:
1399
1417
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
1400
1418
  type: Injectable
1401
1419
  }], ctorParameters: function () {
1402
- return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
1420
+ return [{ type: AuthService }, { type: CheckoutService }, { type: i1$3.Shops, decorators: [{
1403
1421
  type: Inject,
1404
1422
  args: [DEFAULT_SHOP]
1405
1423
  }] }, { type: undefined, decorators: [{
@@ -1411,17 +1429,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1411
1429
  }] }, { type: undefined, decorators: [{
1412
1430
  type: Inject,
1413
1431
  args: ['VariantRepository']
1414
- }] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
1432
+ }] }, { type: i1$3.Buy2WinFirestoreRepository, decorators: [{
1415
1433
  type: Inject,
1416
1434
  args: ['Buy2WinRepository']
1417
1435
  }] }];
1418
1436
  } });
1419
1437
 
1420
1438
  class CatalogService {
1421
- constructor(productRepository, categoryRepository) {
1439
+ constructor(productRepository, categoryStructureAdapter, shop) {
1422
1440
  this.productRepository = productRepository;
1423
- this.categoryRepository = categoryRepository;
1424
- this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, }) => {
1441
+ this.categoryStructureAdapter = categoryStructureAdapter;
1442
+ this.shop = shop;
1443
+ this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, }) => {
1425
1444
  const filters = {};
1426
1445
  if (clubDiscount === null || clubDiscount === void 0 ? void 0 : clubDiscount.length)
1427
1446
  set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
@@ -1439,6 +1458,10 @@ class CatalogService {
1439
1458
  ...(prices.min ? [{ operator: Where.GTE, value: prices.min }] : []),
1440
1459
  ...(prices.max ? [{ operator: Where.LTE, value: prices.max }] : []),
1441
1460
  ]);
1461
+ if (rate)
1462
+ filters.rate = { operator: Where.GTE, value: rate };
1463
+ if (tags === null || tags === void 0 ? void 0 : tags.length)
1464
+ filters.tags = { operator: Where.LIKE, value: tags };
1442
1465
  return filters;
1443
1466
  };
1444
1467
  this.buildSortQuery = (sort) => {
@@ -1452,6 +1475,8 @@ class CatalogService {
1452
1475
  return { price: 'asc' };
1453
1476
  if (sort === 'best-rating')
1454
1477
  return { rate: 'desc' };
1478
+ if (sort === 'news')
1479
+ return { createdAt: 'desc' };
1455
1480
  };
1456
1481
  this.buildLimitQuery = (options) => {
1457
1482
  const limit = (options === null || options === void 0 ? void 0 : options.perPage) || 20;
@@ -1462,26 +1487,28 @@ class CatalogService {
1462
1487
  };
1463
1488
  }
1464
1489
  fetchProducts(category, options) {
1465
- var _a;
1466
1490
  return __awaiter(this, void 0, void 0, function* () {
1467
- const productsIds = ((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)
1468
- ? category.products
1469
- : yield this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1470
1491
  const limits = this.buildLimitQuery(options);
1471
1492
  return yield this.productRepository
1472
- .find(Object.assign(Object.assign({ filters: Object.assign({ id: { operator: Where.IN, value: productsIds }, published: true }, this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})) }, ((options === null || options === void 0 ? void 0 : options.sort) ? { orderBy: this.buildSortQuery(options === null || options === void 0 ? void 0 : options.sort) } : {})), { limits, options: { minimal: ['price'], maximum: ['price'] } }))
1473
- .then(({ data, count: total, maximum, minimal }) => ({
1474
- products: { data, total },
1475
- pages: Math.ceil(total / limits.limit),
1476
- prices: {
1477
- price: { min: minimal.price.price, max: maximum.price.price },
1478
- subscriberPrice: { min: minimal.price.subscriberPrice, max: maximum.price.subscriberPrice },
1479
- },
1480
- }));
1493
+ .findCatalog(Object.assign(Object.assign({ filters: Object.assign(Object.assign({}, (yield this.categoryStructureAdapter.buildProductFilterByCategory(category))), this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})) }, ((options === null || options === void 0 ? void 0 : options.sort) ? { orderBy: this.buildSortQuery(options === null || options === void 0 ? void 0 : options.sort) } : {})), { limits, options: { minimal: ['price'], maximum: ['price'] } }), (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1494
+ .then(({ data, count: total, maximum, minimal }) => {
1495
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1496
+ return ({
1497
+ products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1498
+ pages: Math.ceil(total / limits.limit),
1499
+ prices: {
1500
+ 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)) },
1501
+ subscriberPrice: {
1502
+ 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)),
1503
+ 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)),
1504
+ },
1505
+ },
1506
+ });
1507
+ });
1481
1508
  });
1482
1509
  }
1483
1510
  }
1484
- CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1511
+ CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1485
1512
  CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1486
1513
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1487
1514
  type: Injectable
@@ -1491,41 +1518,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1491
1518
  args: ['ProductRepository']
1492
1519
  }] }, { type: undefined, decorators: [{
1493
1520
  type: Inject,
1494
- args: ['CategoryRepository']
1521
+ args: [CATEGORY_STRUCTURE]
1522
+ }] }, { type: i1$3.Shops, decorators: [{
1523
+ type: Inject,
1524
+ args: [DEFAULT_SHOP]
1495
1525
  }] }];
1496
1526
  } });
1497
1527
 
1498
1528
  class CategoryService {
1499
- constructor(productRepository, categoryRepository, categoryFilterRepository) {
1529
+ constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1500
1530
  this.productRepository = productRepository;
1501
1531
  this.categoryRepository = categoryRepository;
1502
1532
  this.categoryFilterRepository = categoryFilterRepository;
1533
+ this.categoryStructureAdapter = categoryStructureAdapter;
1534
+ this.shop = shop;
1503
1535
  }
1504
- fetchBrands(category) {
1505
- var _a;
1536
+ fetchBrands(category, mainGender) {
1506
1537
  return __awaiter(this, void 0, void 0, function* () {
1507
- const productsIds = ((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)
1508
- ? category.products
1509
- : yield this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1510
1538
  const brands = yield this.productRepository
1511
- .find({
1512
- filters: {
1513
- id: { operator: Where.IN, value: productsIds },
1514
- published: true,
1515
- },
1539
+ .findCatalog({
1540
+ filters: yield this.categoryStructureAdapter.buildProductFilterByCategory(category),
1516
1541
  fields: ['brand'],
1517
- })
1542
+ }, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1518
1543
  .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => (Object.assign(Object.assign({}, brands), { [brand]: true })), {})));
1519
1544
  return this.categoryRepository
1520
1545
  .find({ filters: { brandCategory: true }, orderBy: { name: 'asc' } })
1521
1546
  .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1522
1547
  });
1523
1548
  }
1524
- fetchSubCategories(category) {
1525
- return __awaiter(this, void 0, void 0, function* () {
1526
- return [];
1527
- });
1528
- }
1529
1549
  fetchFilterOptions(category, filters) {
1530
1550
  return __awaiter(this, void 0, void 0, function* () {
1531
1551
  const categoryFilters = category.filters && category.filters.length
@@ -1539,7 +1559,7 @@ class CategoryService {
1539
1559
  });
1540
1560
  }
1541
1561
  }
1542
- CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'CategoryFilterRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1562
+ CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'CategoryFilterRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1543
1563
  CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1544
1564
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1545
1565
  type: Injectable
@@ -1553,6 +1573,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1553
1573
  }] }, { type: undefined, decorators: [{
1554
1574
  type: Inject,
1555
1575
  args: ['CategoryFilterRepository']
1576
+ }] }, { type: undefined, decorators: [{
1577
+ type: Inject,
1578
+ args: [CATEGORY_STRUCTURE]
1579
+ }] }, { type: i1$3.Shops, decorators: [{
1580
+ type: Inject,
1581
+ args: [DEFAULT_SHOP]
1556
1582
  }] }];
1557
1583
  } });
1558
1584
 
@@ -1564,6 +1590,7 @@ var ProductSorts;
1564
1590
  ProductSorts["LOWEST_PRICE"] = "lowest-price";
1565
1591
  ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1566
1592
  ProductSorts["BEST_RATING"] = "best-rating";
1593
+ ProductSorts["NEWS"] = "news";
1567
1594
  })(ProductSorts || (ProductSorts = {}));
1568
1595
 
1569
1596
  class CategoryWithTree extends Category {
@@ -1725,7 +1752,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1725
1752
  }] }, { type: undefined, decorators: [{
1726
1753
  type: Inject,
1727
1754
  args: ['ProductRepository']
1728
- }] }, { type: i3.Shops, decorators: [{
1755
+ }] }, { type: i1$3.Shops, decorators: [{
1729
1756
  type: Inject,
1730
1757
  args: [DEFAULT_SHOP]
1731
1758
  }] }];
@@ -1749,7 +1776,7 @@ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version
1749
1776
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
1750
1777
  type: Injectable
1751
1778
  }], ctorParameters: function () {
1752
- return [{ type: i1$2.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
1779
+ return [{ type: i1$2.Firestore }, { type: i1$3.OrderFirestoreRepository, decorators: [{
1753
1780
  type: Inject,
1754
1781
  args: ['OrderRepository']
1755
1782
  }] }];
@@ -1832,22 +1859,102 @@ class ShippingService {
1832
1859
  return false;
1833
1860
  }
1834
1861
  }
1835
- ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i1$3.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
1862
+ ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i1$4.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
1836
1863
  ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
1837
1864
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
1838
1865
  type: Injectable
1839
1866
  }], ctorParameters: function () {
1840
- return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
1867
+ return [{ type: i1$4.HttpClient }, { type: undefined, decorators: [{
1841
1868
  type: Inject,
1842
1869
  args: [BACKEND_URL]
1843
1870
  }] }, { type: HomeShopService }];
1844
1871
  } });
1845
1872
 
1873
+ class NewCategoryStructureAdapter {
1874
+ constructor(categoryRepository, categoryCollectionChildrenRepository) {
1875
+ this.categoryRepository = categoryRepository;
1876
+ this.categoryCollectionChildrenRepository = categoryCollectionChildrenRepository;
1877
+ }
1878
+ buildProductFilterByCategory(category) {
1879
+ return __awaiter(this, void 0, void 0, function* () {
1880
+ const categoriesIds = (yield this.isCollection(category))
1881
+ ? yield this.getAllCategoriesIdFromCollection(category)
1882
+ : [...(yield this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1883
+ return { category: { id: { operator: Where.IN, value: categoriesIds } } };
1884
+ });
1885
+ }
1886
+ getAllCategoriesIdFromCategory(category) {
1887
+ return __awaiter(this, void 0, void 0, function* () {
1888
+ return this.categoryRepository
1889
+ .getChildren(+category.id)
1890
+ .then((categories) => categories.map((category) => category.id.toString()));
1891
+ });
1892
+ }
1893
+ getAllCategoriesIdFromCollection(category) {
1894
+ return __awaiter(this, void 0, void 0, function* () {
1895
+ return this.categoryCollectionChildrenRepository
1896
+ .find({ filters: { collectionId: +category.id } })
1897
+ .then(({ data }) => data.map((categoryCollection) => categoryCollection.categoryId.toString()));
1898
+ });
1899
+ }
1900
+ isCollection(category) {
1901
+ return __awaiter(this, void 0, void 0, function* () {
1902
+ return !isNil(category.isCollection)
1903
+ ? category.isCollection
1904
+ : this.categoryRepository.get({ id: category.id }).then((category) => category.isCollection);
1905
+ });
1906
+ }
1907
+ }
1908
+ NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }, { token: 'CategoryCollectionChildrenRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1909
+ NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
1910
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1911
+ type: Injectable
1912
+ }], ctorParameters: function () {
1913
+ return [{ type: undefined, decorators: [{
1914
+ type: Inject,
1915
+ args: ['CategoryRepository']
1916
+ }] }, { type: undefined, decorators: [{
1917
+ type: Inject,
1918
+ args: ['CategoryCollectionChildrenRepository']
1919
+ }] }];
1920
+ } });
1921
+
1922
+ class OldCategoryStructureAdapter {
1923
+ constructor(categoryRepository) {
1924
+ this.categoryRepository = categoryRepository;
1925
+ }
1926
+ buildProductFilterByCategory(category) {
1927
+ var _a;
1928
+ return __awaiter(this, void 0, void 0, function* () {
1929
+ const productsIds = ((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)
1930
+ ? category.products
1931
+ : yield this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1932
+ return { id: { operator: Where.IN, value: productsIds } };
1933
+ });
1934
+ }
1935
+ }
1936
+ OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1937
+ OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
1938
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1939
+ type: Injectable
1940
+ }], ctorParameters: function () {
1941
+ return [{ type: undefined, decorators: [{
1942
+ type: Inject,
1943
+ args: ['CategoryRepository']
1944
+ }] }];
1945
+ } });
1946
+
1846
1947
  class AngularConnectModule {
1847
1948
  static initializeApp(defaultShop, options, nameOrConfig) {
1848
1949
  return {
1849
1950
  ngModule: AngularConnectModule,
1850
1951
  providers: [
1952
+ {
1953
+ provide: CATEGORY_STRUCTURE,
1954
+ useClass: isNil(options === null || options === void 0 ? void 0 : options.oldCategoryStructure) || (options === null || options === void 0 ? void 0 : options.oldCategoryStructure)
1955
+ ? OldCategoryStructureAdapter
1956
+ : NewCategoryStructureAdapter,
1957
+ },
1851
1958
  ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1852
1959
  ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1853
1960
  ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),