@infrab4a/connect-angular 4.14.1 → 4.14.3

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.
@@ -5,7 +5,7 @@ import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular
5
5
  import * as i2 from '@angular/fire/storage';
6
6
  import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
7
7
  import * as i1$2 from '@infrab4a/connect';
8
- import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, PersonTypes, WishlistLogType, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
8
+ import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, isEmpty, Category, PersonTypes, WishlistLogType, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
9
9
  import * as i1 from '@angular/fire/auth';
10
10
  import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
11
11
  import { isPlatformBrowser, isPlatformServer } from '@angular/common';
@@ -1726,6 +1726,7 @@ class CatalogService {
1726
1726
  this.shop = shop;
1727
1727
  this.productSearch = productSearch;
1728
1728
  this.productsByTerm = {};
1729
+ this.brandsList = {};
1729
1730
  this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1730
1731
  const filters = {};
1731
1732
  if (clubDiscount?.length)
@@ -1778,6 +1779,15 @@ class CatalogService {
1778
1779
  this.hasProfile = (options) => 'profile' in options;
1779
1780
  this.hasTerm = (options) => 'term' in options;
1780
1781
  this.hasCategory = (options) => 'category' in options;
1782
+ this.buildIndexBrands = (options) => {
1783
+ if (this.hasCategory(options))
1784
+ return `category-${options.category.id}`;
1785
+ if (this.hasTerm(options))
1786
+ return `term-${options.term}`;
1787
+ if (this.hasProfile(options))
1788
+ return `profile-${options.profile.join(',')}`;
1789
+ return '';
1790
+ };
1781
1791
  }
1782
1792
  async fetchProducts(options) {
1783
1793
  const limits = this.buildLimitQuery(options);
@@ -1787,18 +1797,21 @@ class CatalogService {
1787
1797
  throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1788
1798
  if (this.hasTerm(options) && options.filters?.customOptions)
1789
1799
  throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1790
- return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
1791
- products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1792
- pages: Math.ceil(total / limits.limit),
1793
- prices: {
1794
- price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1795
- subscriberPrice: {
1796
- min: +minimal?.price?.subscriberPrice?.toFixed(2),
1797
- max: +maximum?.price?.subscriberPrice?.toFixed(2),
1800
+ return await this.findCatalog(options, limits).then(async ({ data, count: total, maximum, minimal, distinct }) => {
1801
+ await this.setBrandsList(options, distinct?.brand);
1802
+ return {
1803
+ products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1804
+ pages: Math.ceil(total / limits.limit),
1805
+ prices: {
1806
+ price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1807
+ subscriberPrice: {
1808
+ min: +minimal?.price?.subscriberPrice?.toFixed(2),
1809
+ max: +maximum?.price?.subscriberPrice?.toFixed(2),
1810
+ },
1798
1811
  },
1799
- },
1800
- brands: distinct?.brand,
1801
- }));
1812
+ brands: this.brandsList[this.buildIndexBrands(options)],
1813
+ };
1814
+ });
1802
1815
  }
1803
1816
  async addCustomerToStockNotification(shop, productId, name, email) {
1804
1817
  return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
@@ -1831,7 +1844,9 @@ class CatalogService {
1831
1844
  options: {
1832
1845
  minimal: ['price'],
1833
1846
  maximum: ['price'],
1834
- ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1847
+ ...(!this.brandsList[this.buildIndexBrands(options)] && isEmpty(options.filters?.brands)
1848
+ ? { distinct: ['brand'] }
1849
+ : {}),
1835
1850
  },
1836
1851
  };
1837
1852
  if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
@@ -1849,6 +1864,7 @@ class CatalogService {
1849
1864
  .then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
1850
1865
  }
1851
1866
  async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1867
+ const brandsList = this.brandsList[this.buildIndexBrands(options)];
1852
1868
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1853
1869
  const totalResult = await this.productRepository.findCatalog({
1854
1870
  filters: {
@@ -1859,7 +1875,7 @@ class CatalogService {
1859
1875
  options: {
1860
1876
  minimal: ['price'],
1861
1877
  maximum: ['price'],
1862
- distinct: ['brand'],
1878
+ ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1863
1879
  },
1864
1880
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1865
1881
  const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
@@ -1871,15 +1887,20 @@ class CatalogService {
1871
1887
  .concat(mostRelevantWithouyStock);
1872
1888
  const categoryMostRelevants = firstProducts.concat(lastProducts);
1873
1889
  const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1890
+ await this.setBrandsList(options, totalResult.distinct?.brand);
1874
1891
  return {
1875
1892
  data: resultFinal,
1876
1893
  count: totalResult.count,
1877
1894
  maximum: totalResult.maximum,
1878
1895
  minimal: totalResult.minimal,
1879
- distinct: totalResult.distinct,
1896
+ distinct: {
1897
+ ...totalResult.distinct,
1898
+ brand: this.brandsList[this.buildIndexBrands(options)],
1899
+ },
1880
1900
  };
1881
1901
  }
1882
1902
  async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1903
+ const brandsList = this.brandsList[this.buildIndexBrands(options)];
1883
1904
  const totalResult = await this.productRepository.findCatalog({
1884
1905
  fields: ['id', 'stock', 'gender'],
1885
1906
  filters: {
@@ -1890,7 +1911,7 @@ class CatalogService {
1890
1911
  options: {
1891
1912
  minimal: ['price'],
1892
1913
  maximum: ['price'],
1893
- distinct: ['brand'],
1914
+ ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1894
1915
  },
1895
1916
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1896
1917
  const defaultGender = options?.filters?.gender
@@ -1913,12 +1934,16 @@ class CatalogService {
1913
1934
  id: { operator: Where.IN, value: orderedId },
1914
1935
  },
1915
1936
  });
1937
+ await this.setBrandsList(options, totalResult.distinct?.brand);
1916
1938
  return {
1917
1939
  data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1918
1940
  count: totalResult.count,
1919
1941
  maximum: totalResult.maximum,
1920
1942
  minimal: totalResult.minimal,
1921
- distinct: totalResult.distinct,
1943
+ distinct: {
1944
+ ...totalResult.distinct,
1945
+ brand: this.brandsList[this.buildIndexBrands(options)],
1946
+ },
1922
1947
  };
1923
1948
  }
1924
1949
  async findCatalogIdsBySearch(term, preview = false) {
@@ -1928,6 +1953,35 @@ class CatalogService {
1928
1953
  .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1929
1954
  .then((products) => [...new Set(products.map((product) => product.id))]));
1930
1955
  }
1956
+ async fetchBrandsOnly(options, productIds = []) {
1957
+ return this.productRepository
1958
+ .findCatalog({
1959
+ fields: ['id'],
1960
+ filters: {
1961
+ ...(!isEmpty(productIds) ? { id: { operator: Where.IN, value: productIds } } : {}),
1962
+ published: { operator: Where.EQUALS, value: true },
1963
+ ...this.buildFilterQuery(options?.filters || {}),
1964
+ },
1965
+ options: {
1966
+ distinct: ['brand'],
1967
+ },
1968
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1969
+ .then((result) => {
1970
+ return result.distinct.brand;
1971
+ });
1972
+ }
1973
+ async setBrandsList(options, brands) {
1974
+ const filterBrands = options.filters?.brands;
1975
+ if (isEmpty(brands))
1976
+ delete options.filters?.brands;
1977
+ this.brandsList[this.buildIndexBrands(options)] =
1978
+ this.brandsList[this.buildIndexBrands(options)] || brands || (await this.fetchBrandsOnly(options));
1979
+ this.brandsList[this.buildIndexBrands(options)] = this.brandsList[this.buildIndexBrands(options)].filter(Boolean);
1980
+ options.filters = {
1981
+ ...options.filters,
1982
+ brands: filterBrands,
1983
+ };
1984
+ }
1931
1985
  }
1932
1986
  CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable });
1933
1987
  CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });