@infrab4a/connect-angular 4.14.1-beta.5 → 4.14.2
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.
- package/esm2020/services/catalog/catalog.service.mjs +70 -18
- package/fesm2015/infrab4a-connect-angular.mjs +59 -26
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +69 -17
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/catalog/catalog.service.d.ts +3 -0
|
@@ -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,29 @@ 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
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1800
|
+
return await this.findCatalog(options, limits).then(async ({ data, count: total, maximum, minimal, distinct }) => {
|
|
1801
|
+
const filterBrands = options.filters?.brands;
|
|
1802
|
+
if (isEmpty(distinct?.brand))
|
|
1803
|
+
delete options.filters?.brands;
|
|
1804
|
+
this.brandsList[this.buildIndexBrands(options)] =
|
|
1805
|
+
this.brandsList[this.buildIndexBrands(options)] || distinct?.brand || (await this.fetchBrandsOnly(options));
|
|
1806
|
+
options.filters = {
|
|
1807
|
+
...options.filters,
|
|
1808
|
+
brands: filterBrands,
|
|
1809
|
+
};
|
|
1810
|
+
return {
|
|
1811
|
+
products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
|
|
1812
|
+
pages: Math.ceil(total / limits.limit),
|
|
1813
|
+
prices: {
|
|
1814
|
+
price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
|
|
1815
|
+
subscriberPrice: {
|
|
1816
|
+
min: +minimal?.price?.subscriberPrice?.toFixed(2),
|
|
1817
|
+
max: +maximum?.price?.subscriberPrice?.toFixed(2),
|
|
1818
|
+
},
|
|
1798
1819
|
},
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
})
|
|
1820
|
+
brands: this.brandsList[this.buildIndexBrands(options)],
|
|
1821
|
+
};
|
|
1822
|
+
});
|
|
1802
1823
|
}
|
|
1803
1824
|
async addCustomerToStockNotification(shop, productId, name, email) {
|
|
1804
1825
|
return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
|
|
@@ -1831,7 +1852,9 @@ class CatalogService {
|
|
|
1831
1852
|
options: {
|
|
1832
1853
|
minimal: ['price'],
|
|
1833
1854
|
maximum: ['price'],
|
|
1834
|
-
...(!this.
|
|
1855
|
+
...(!this.brandsList[this.buildIndexBrands(options)] && isEmpty(options.filters?.brands)
|
|
1856
|
+
? { distinct: ['brand'] }
|
|
1857
|
+
: {}),
|
|
1835
1858
|
},
|
|
1836
1859
|
};
|
|
1837
1860
|
if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
|
|
@@ -1849,6 +1872,7 @@ class CatalogService {
|
|
|
1849
1872
|
.then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
|
|
1850
1873
|
}
|
|
1851
1874
|
async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
|
|
1875
|
+
const brandsList = this.brandsList[this.buildIndexBrands(options)];
|
|
1852
1876
|
const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
|
|
1853
1877
|
const totalResult = await this.productRepository.findCatalog({
|
|
1854
1878
|
filters: {
|
|
@@ -1859,7 +1883,7 @@ class CatalogService {
|
|
|
1859
1883
|
options: {
|
|
1860
1884
|
minimal: ['price'],
|
|
1861
1885
|
maximum: ['price'],
|
|
1862
|
-
distinct: ['brand'],
|
|
1886
|
+
...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
|
|
1863
1887
|
},
|
|
1864
1888
|
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1865
1889
|
const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
|
|
@@ -1871,15 +1895,21 @@ class CatalogService {
|
|
|
1871
1895
|
.concat(mostRelevantWithouyStock);
|
|
1872
1896
|
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
1873
1897
|
const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
|
|
1898
|
+
if (!brandsList && !isEmpty(options.filters?.brands))
|
|
1899
|
+
delete options.filters.brands;
|
|
1874
1900
|
return {
|
|
1875
1901
|
data: resultFinal,
|
|
1876
1902
|
count: totalResult.count,
|
|
1877
1903
|
maximum: totalResult.maximum,
|
|
1878
1904
|
minimal: totalResult.minimal,
|
|
1879
|
-
distinct:
|
|
1905
|
+
distinct: {
|
|
1906
|
+
...totalResult.distinct,
|
|
1907
|
+
brand: brandsList || totalResult.distinct?.brand || (await this.fetchBrandsOnly(options, productIds)),
|
|
1908
|
+
},
|
|
1880
1909
|
};
|
|
1881
1910
|
}
|
|
1882
1911
|
async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
|
|
1912
|
+
const brandsList = this.brandsList[this.buildIndexBrands(options)];
|
|
1883
1913
|
const totalResult = await this.productRepository.findCatalog({
|
|
1884
1914
|
fields: ['id', 'stock', 'gender'],
|
|
1885
1915
|
filters: {
|
|
@@ -1890,7 +1920,7 @@ class CatalogService {
|
|
|
1890
1920
|
options: {
|
|
1891
1921
|
minimal: ['price'],
|
|
1892
1922
|
maximum: ['price'],
|
|
1893
|
-
distinct: ['brand'],
|
|
1923
|
+
...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
|
|
1894
1924
|
},
|
|
1895
1925
|
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1896
1926
|
const defaultGender = options?.filters?.gender
|
|
@@ -1913,12 +1943,17 @@ class CatalogService {
|
|
|
1913
1943
|
id: { operator: Where.IN, value: orderedId },
|
|
1914
1944
|
},
|
|
1915
1945
|
});
|
|
1946
|
+
if (!brandsList && !isEmpty(options.filters?.brands))
|
|
1947
|
+
delete options.filters.brands;
|
|
1916
1948
|
return {
|
|
1917
1949
|
data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
|
|
1918
1950
|
count: totalResult.count,
|
|
1919
1951
|
maximum: totalResult.maximum,
|
|
1920
1952
|
minimal: totalResult.minimal,
|
|
1921
|
-
distinct:
|
|
1953
|
+
distinct: {
|
|
1954
|
+
...totalResult.distinct,
|
|
1955
|
+
brand: brandsList || totalResult.distinct?.brand || (await this.fetchBrandsOnly(options, productIds)),
|
|
1956
|
+
},
|
|
1922
1957
|
};
|
|
1923
1958
|
}
|
|
1924
1959
|
async findCatalogIdsBySearch(term, preview = false) {
|
|
@@ -1928,6 +1963,23 @@ class CatalogService {
|
|
|
1928
1963
|
.search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
|
|
1929
1964
|
.then((products) => [...new Set(products.map((product) => product.id))]));
|
|
1930
1965
|
}
|
|
1966
|
+
async fetchBrandsOnly(options, productIds = []) {
|
|
1967
|
+
return this.productRepository
|
|
1968
|
+
.findCatalog({
|
|
1969
|
+
fields: ['id'],
|
|
1970
|
+
filters: {
|
|
1971
|
+
...(!isEmpty(productIds) ? { id: { operator: Where.IN, value: productIds } } : {}),
|
|
1972
|
+
published: { operator: Where.EQUALS, value: true },
|
|
1973
|
+
...this.buildFilterQuery(options?.filters || {}),
|
|
1974
|
+
},
|
|
1975
|
+
options: {
|
|
1976
|
+
distinct: ['brand'],
|
|
1977
|
+
},
|
|
1978
|
+
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
|
|
1979
|
+
.then((result) => {
|
|
1980
|
+
return result.distinct.brand;
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1931
1983
|
}
|
|
1932
1984
|
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
1985
|
CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
|