@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 cookie from 'js-cookie';
17
17
  import { CustomError } from 'ts-custom-error';
18
18
  import { __decorate, __metadata } from 'tslib';
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
  }] });
@@ -1050,7 +1068,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1050
1068
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1051
1069
  type: Inject,
1052
1070
  args: ['CouponRepository']
1053
- }] }, { type: i3.Shops, decorators: [{
1071
+ }] }, { type: i1$3.Shops, decorators: [{
1054
1072
  type: Inject,
1055
1073
  args: [DEFAULT_SHOP]
1056
1074
  }] }, { type: undefined, decorators: [{
@@ -1119,7 +1137,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1119
1137
  }] }, { type: undefined, decorators: [{
1120
1138
  type: Inject,
1121
1139
  args: ['UserRepository']
1122
- }] }, { type: i3.Shops, decorators: [{
1140
+ }] }, { type: i1$3.Shops, decorators: [{
1123
1141
  type: Inject,
1124
1142
  args: [DEFAULT_SHOP]
1125
1143
  }] }]; } });
@@ -1377,7 +1395,7 @@ CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15
1377
1395
  CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
1378
1396
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
1379
1397
  type: Injectable
1380
- }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
1398
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$3.Shops, decorators: [{
1381
1399
  type: Inject,
1382
1400
  args: [DEFAULT_SHOP]
1383
1401
  }] }, { type: undefined, decorators: [{
@@ -1389,16 +1407,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1389
1407
  }] }, { type: undefined, decorators: [{
1390
1408
  type: Inject,
1391
1409
  args: ['VariantRepository']
1392
- }] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
1410
+ }] }, { type: i1$3.Buy2WinFirestoreRepository, decorators: [{
1393
1411
  type: Inject,
1394
1412
  args: ['Buy2WinRepository']
1395
1413
  }] }]; } });
1396
1414
 
1397
1415
  class CatalogService {
1398
- constructor(productRepository, categoryRepository) {
1416
+ constructor(productRepository, categoryStructureAdapter, shop) {
1399
1417
  this.productRepository = productRepository;
1400
- this.categoryRepository = categoryRepository;
1401
- this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, }) => {
1418
+ this.categoryStructureAdapter = categoryStructureAdapter;
1419
+ this.shop = shop;
1420
+ this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, }) => {
1402
1421
  const filters = {};
1403
1422
  if (clubDiscount?.length)
1404
1423
  set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
@@ -1416,6 +1435,10 @@ class CatalogService {
1416
1435
  ...(prices.min ? [{ operator: Where.GTE, value: prices.min }] : []),
1417
1436
  ...(prices.max ? [{ operator: Where.LTE, value: prices.max }] : []),
1418
1437
  ]);
1438
+ if (rate)
1439
+ filters.rate = { operator: Where.GTE, value: rate };
1440
+ if (tags?.length)
1441
+ filters.tags = { operator: Where.LIKE, value: tags };
1419
1442
  return filters;
1420
1443
  };
1421
1444
  this.buildSortQuery = (sort) => {
@@ -1429,6 +1452,8 @@ class CatalogService {
1429
1452
  return { price: 'asc' };
1430
1453
  if (sort === 'best-rating')
1431
1454
  return { rate: 'desc' };
1455
+ if (sort === 'news')
1456
+ return { createdAt: 'desc' };
1432
1457
  };
1433
1458
  this.buildLimitQuery = (options) => {
1434
1459
  const limit = options?.perPage || 20;
@@ -1439,32 +1464,31 @@ class CatalogService {
1439
1464
  };
1440
1465
  }
1441
1466
  async fetchProducts(category, options) {
1442
- const productsIds = category.products?.length
1443
- ? category.products
1444
- : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1445
1467
  const limits = this.buildLimitQuery(options);
1446
1468
  return await this.productRepository
1447
- .find({
1469
+ .findCatalog({
1448
1470
  filters: {
1449
- id: { operator: Where.IN, value: productsIds },
1450
- published: true,
1471
+ ...(await this.categoryStructureAdapter.buildProductFilterByCategory(category)),
1451
1472
  ...this.buildFilterQuery(options?.filters || {}),
1452
1473
  },
1453
1474
  ...(options?.sort ? { orderBy: this.buildSortQuery(options?.sort) } : {}),
1454
1475
  limits,
1455
1476
  options: { minimal: ['price'], maximum: ['price'] },
1456
- })
1477
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1457
1478
  .then(({ data, count: total, maximum, minimal }) => ({
1458
- products: { data, total },
1479
+ products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1459
1480
  pages: Math.ceil(total / limits.limit),
1460
1481
  prices: {
1461
- price: { min: minimal.price.price, max: maximum.price.price },
1462
- subscriberPrice: { min: minimal.price.subscriberPrice, max: maximum.price.subscriberPrice },
1482
+ price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1483
+ subscriberPrice: {
1484
+ min: +minimal?.price?.subscriberPrice?.toFixed(2),
1485
+ max: +maximum?.price?.subscriberPrice?.toFixed(2),
1486
+ },
1463
1487
  },
1464
1488
  }));
1465
1489
  }
1466
1490
  }
1467
- 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 });
1491
+ 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 });
1468
1492
  CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1469
1493
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1470
1494
  type: Injectable
@@ -1473,35 +1497,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1473
1497
  args: ['ProductRepository']
1474
1498
  }] }, { type: undefined, decorators: [{
1475
1499
  type: Inject,
1476
- args: ['CategoryRepository']
1500
+ args: [CATEGORY_STRUCTURE]
1501
+ }] }, { type: i1$3.Shops, decorators: [{
1502
+ type: Inject,
1503
+ args: [DEFAULT_SHOP]
1477
1504
  }] }]; } });
1478
1505
 
1479
1506
  class CategoryService {
1480
- constructor(productRepository, categoryRepository, categoryFilterRepository) {
1507
+ constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1481
1508
  this.productRepository = productRepository;
1482
1509
  this.categoryRepository = categoryRepository;
1483
1510
  this.categoryFilterRepository = categoryFilterRepository;
1511
+ this.categoryStructureAdapter = categoryStructureAdapter;
1512
+ this.shop = shop;
1484
1513
  }
1485
- async fetchBrands(category) {
1486
- const productsIds = category.products?.length
1487
- ? category.products
1488
- : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1514
+ async fetchBrands(category, mainGender) {
1489
1515
  const brands = await this.productRepository
1490
- .find({
1491
- filters: {
1492
- id: { operator: Where.IN, value: productsIds },
1493
- published: true,
1494
- },
1516
+ .findCatalog({
1517
+ filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1495
1518
  fields: ['brand'],
1496
- })
1519
+ }, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1497
1520
  .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1498
1521
  return this.categoryRepository
1499
1522
  .find({ filters: { brandCategory: true }, orderBy: { name: 'asc' } })
1500
1523
  .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1501
1524
  }
1502
- async fetchSubCategories(category) {
1503
- return [];
1504
- }
1505
1525
  async fetchFilterOptions(category, filters) {
1506
1526
  const categoryFilters = category.filters && category.filters.length
1507
1527
  ? category.filters
@@ -1513,7 +1533,7 @@ class CategoryService {
1513
1533
  : categoryFilters;
1514
1534
  }
1515
1535
  }
1516
- 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 });
1536
+ 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 });
1517
1537
  CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1518
1538
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1519
1539
  type: Injectable
@@ -1526,6 +1546,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1526
1546
  }] }, { type: undefined, decorators: [{
1527
1547
  type: Inject,
1528
1548
  args: ['CategoryFilterRepository']
1549
+ }] }, { type: undefined, decorators: [{
1550
+ type: Inject,
1551
+ args: [CATEGORY_STRUCTURE]
1552
+ }] }, { type: i1$3.Shops, decorators: [{
1553
+ type: Inject,
1554
+ args: [DEFAULT_SHOP]
1529
1555
  }] }]; } });
1530
1556
 
1531
1557
  var ProductSorts;
@@ -1536,6 +1562,7 @@ var ProductSorts;
1536
1562
  ProductSorts["LOWEST_PRICE"] = "lowest-price";
1537
1563
  ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1538
1564
  ProductSorts["BEST_RATING"] = "best-rating";
1565
+ ProductSorts["NEWS"] = "news";
1539
1566
  })(ProductSorts || (ProductSorts = {}));
1540
1567
 
1541
1568
  class CategoryWithTree extends Category {
@@ -1692,7 +1719,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1692
1719
  }] }, { type: undefined, decorators: [{
1693
1720
  type: Inject,
1694
1721
  args: ['ProductRepository']
1695
- }] }, { type: i3.Shops, decorators: [{
1722
+ }] }, { type: i1$3.Shops, decorators: [{
1696
1723
  type: Inject,
1697
1724
  args: [DEFAULT_SHOP]
1698
1725
  }] }]; } });
@@ -1714,7 +1741,7 @@ OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "1
1714
1741
  OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
1715
1742
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
1716
1743
  type: Injectable
1717
- }], ctorParameters: function () { return [{ type: i1$2.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
1744
+ }], ctorParameters: function () { return [{ type: i1$2.Firestore }, { type: i1$3.OrderFirestoreRepository, decorators: [{
1718
1745
  type: Inject,
1719
1746
  args: ['OrderRepository']
1720
1747
  }] }]; } });
@@ -1796,20 +1823,85 @@ class ShippingService {
1796
1823
  return false;
1797
1824
  }
1798
1825
  }
1799
- 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 });
1826
+ 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 });
1800
1827
  ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
1801
1828
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
1802
1829
  type: Injectable
1803
- }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
1830
+ }], ctorParameters: function () { return [{ type: i1$4.HttpClient }, { type: undefined, decorators: [{
1804
1831
  type: Inject,
1805
1832
  args: [BACKEND_URL]
1806
1833
  }] }, { type: HomeShopService }]; } });
1807
1834
 
1835
+ class NewCategoryStructureAdapter {
1836
+ constructor(categoryRepository, categoryCollectionChildrenRepository) {
1837
+ this.categoryRepository = categoryRepository;
1838
+ this.categoryCollectionChildrenRepository = categoryCollectionChildrenRepository;
1839
+ }
1840
+ async buildProductFilterByCategory(category) {
1841
+ const categoriesIds = (await this.isCollection(category))
1842
+ ? await this.getAllCategoriesIdFromCollection(category)
1843
+ : [...(await this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1844
+ return { category: { id: { operator: Where.IN, value: categoriesIds } } };
1845
+ }
1846
+ async getAllCategoriesIdFromCategory(category) {
1847
+ return this.categoryRepository
1848
+ .getChildren(+category.id)
1849
+ .then((categories) => categories.map((category) => category.id.toString()));
1850
+ }
1851
+ async getAllCategoriesIdFromCollection(category) {
1852
+ return this.categoryCollectionChildrenRepository
1853
+ .find({ filters: { collectionId: +category.id } })
1854
+ .then(({ data }) => data.map((categoryCollection) => categoryCollection.categoryId.toString()));
1855
+ }
1856
+ async isCollection(category) {
1857
+ return !isNil(category.isCollection)
1858
+ ? category.isCollection
1859
+ : this.categoryRepository.get({ id: category.id }).then((category) => category.isCollection);
1860
+ }
1861
+ }
1862
+ 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 });
1863
+ NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
1864
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1865
+ type: Injectable
1866
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1867
+ type: Inject,
1868
+ args: ['CategoryRepository']
1869
+ }] }, { type: undefined, decorators: [{
1870
+ type: Inject,
1871
+ args: ['CategoryCollectionChildrenRepository']
1872
+ }] }]; } });
1873
+
1874
+ class OldCategoryStructureAdapter {
1875
+ constructor(categoryRepository) {
1876
+ this.categoryRepository = categoryRepository;
1877
+ }
1878
+ async buildProductFilterByCategory(category) {
1879
+ const productsIds = category.products?.length
1880
+ ? category.products
1881
+ : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1882
+ return { id: { operator: Where.IN, value: productsIds } };
1883
+ }
1884
+ }
1885
+ OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1886
+ OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
1887
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1888
+ type: Injectable
1889
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1890
+ type: Inject,
1891
+ args: ['CategoryRepository']
1892
+ }] }]; } });
1893
+
1808
1894
  class AngularConnectModule {
1809
1895
  static initializeApp(defaultShop, options, nameOrConfig) {
1810
1896
  return {
1811
1897
  ngModule: AngularConnectModule,
1812
1898
  providers: [
1899
+ {
1900
+ provide: CATEGORY_STRUCTURE,
1901
+ useClass: isNil(options?.oldCategoryStructure) || options?.oldCategoryStructure
1902
+ ? OldCategoryStructureAdapter
1903
+ : NewCategoryStructureAdapter,
1904
+ },
1813
1905
  ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1814
1906
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
1815
1907
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),