@infrab4a/connect-angular 4.15.0-beta.0 → 4.15.0-beta.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/cart.service.mjs +1 -5
- package/esm2020/services/catalog/catalog.service.mjs +72 -18
- package/esm2020/services/coupon.service.mjs +3 -3
- package/fesm2015/infrab4a-connect-angular.mjs +69 -36
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +73 -23
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/catalog/catalog.service.d.ts +4 -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, SequenceFirestoreRepository, 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, SequenceFirestoreRepository, 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';
|
|
@@ -1151,7 +1151,7 @@ class CouponService {
|
|
|
1151
1151
|
let discount = 0;
|
|
1152
1152
|
if (type == CouponTypes.SHIPPING) {
|
|
1153
1153
|
const subTotal = checkout.shipping.ShippingPrice;
|
|
1154
|
-
const discount = subTotal * ((value > 100 ? 100 : value) / 100);
|
|
1154
|
+
const discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
|
|
1155
1155
|
return { discount, lineItems: checkout.lineItems };
|
|
1156
1156
|
}
|
|
1157
1157
|
const lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
|
|
@@ -1160,7 +1160,7 @@ class CouponService {
|
|
|
1160
1160
|
discount = value > subTotal ? subTotal : value;
|
|
1161
1161
|
}
|
|
1162
1162
|
else {
|
|
1163
|
-
discount = subTotal * ((value > 100 ? 100 : value) / 100);
|
|
1163
|
+
discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
|
|
1164
1164
|
}
|
|
1165
1165
|
const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
|
|
1166
1166
|
return { discount, lineItems };
|
|
@@ -1513,10 +1513,6 @@ class CartService {
|
|
|
1513
1513
|
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1514
1514
|
}
|
|
1515
1515
|
updateUserCart(user) {
|
|
1516
|
-
const isSameUserId = !user?.id || this.user?.id === user?.id;
|
|
1517
|
-
const isSameUser = isSameUserId && !!this.user?.isSubscriber === !!user?.isSubscriber;
|
|
1518
|
-
if (isSameUser)
|
|
1519
|
-
return this.getCart();
|
|
1520
1516
|
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
|
|
1521
1517
|
.updateCheckoutLineItems(Checkout.toInstance({
|
|
1522
1518
|
...checkout.toPlain(),
|
|
@@ -1750,6 +1746,7 @@ class CatalogService {
|
|
|
1750
1746
|
this.shop = shop;
|
|
1751
1747
|
this.productSearch = productSearch;
|
|
1752
1748
|
this.productsByTerm = {};
|
|
1749
|
+
this.brandsList = {};
|
|
1753
1750
|
this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
|
|
1754
1751
|
const filters = {};
|
|
1755
1752
|
if (clubDiscount?.length)
|
|
@@ -1802,6 +1799,15 @@ class CatalogService {
|
|
|
1802
1799
|
this.hasProfile = (options) => 'profile' in options;
|
|
1803
1800
|
this.hasTerm = (options) => 'term' in options;
|
|
1804
1801
|
this.hasCategory = (options) => 'category' in options;
|
|
1802
|
+
this.buildIndexBrands = (options) => {
|
|
1803
|
+
if (this.hasCategory(options))
|
|
1804
|
+
return `category-${options.category.id}`;
|
|
1805
|
+
if (this.hasTerm(options))
|
|
1806
|
+
return `term-${options.term}`;
|
|
1807
|
+
if (this.hasProfile(options))
|
|
1808
|
+
return `profile-${options.profile.join(',')}`;
|
|
1809
|
+
return '';
|
|
1810
|
+
};
|
|
1805
1811
|
}
|
|
1806
1812
|
async fetchProducts(options) {
|
|
1807
1813
|
const limits = this.buildLimitQuery(options);
|
|
@@ -1811,18 +1817,21 @@ class CatalogService {
|
|
|
1811
1817
|
throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
|
|
1812
1818
|
if (this.hasTerm(options) && options.filters?.customOptions)
|
|
1813
1819
|
throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
|
|
1814
|
-
return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) =>
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
min: +minimal?.price?.
|
|
1821
|
-
|
|
1820
|
+
return await this.findCatalog(options, limits).then(async ({ data, count: total, maximum, minimal, distinct }) => {
|
|
1821
|
+
await this.setBrandsList(options, distinct?.brand);
|
|
1822
|
+
return {
|
|
1823
|
+
products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
|
|
1824
|
+
pages: Math.ceil(total / limits.limit),
|
|
1825
|
+
prices: {
|
|
1826
|
+
price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
|
|
1827
|
+
subscriberPrice: {
|
|
1828
|
+
min: +minimal?.price?.subscriberPrice?.toFixed(2),
|
|
1829
|
+
max: +maximum?.price?.subscriberPrice?.toFixed(2),
|
|
1830
|
+
},
|
|
1822
1831
|
},
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
})
|
|
1832
|
+
brands: this.brandsList[this.buildIndexBrands(options)],
|
|
1833
|
+
};
|
|
1834
|
+
});
|
|
1826
1835
|
}
|
|
1827
1836
|
async addCustomerToStockNotification(shop, productId, name, email) {
|
|
1828
1837
|
return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
|
|
@@ -1855,7 +1864,9 @@ class CatalogService {
|
|
|
1855
1864
|
options: {
|
|
1856
1865
|
minimal: ['price'],
|
|
1857
1866
|
maximum: ['price'],
|
|
1858
|
-
...(!this.
|
|
1867
|
+
...(!this.brandsList[this.buildIndexBrands(options)] && isEmpty(options.filters?.brands)
|
|
1868
|
+
? { distinct: ['brand'] }
|
|
1869
|
+
: {}),
|
|
1859
1870
|
},
|
|
1860
1871
|
};
|
|
1861
1872
|
if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
|
|
@@ -1873,6 +1884,7 @@ class CatalogService {
|
|
|
1873
1884
|
.then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
|
|
1874
1885
|
}
|
|
1875
1886
|
async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
|
|
1887
|
+
const brandsList = this.brandsList[this.buildIndexBrands(options)];
|
|
1876
1888
|
const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
|
|
1877
1889
|
const totalResult = await this.productRepository.findCatalog({
|
|
1878
1890
|
filters: {
|
|
@@ -1883,7 +1895,7 @@ class CatalogService {
|
|
|
1883
1895
|
options: {
|
|
1884
1896
|
minimal: ['price'],
|
|
1885
1897
|
maximum: ['price'],
|
|
1886
|
-
distinct: ['brand'],
|
|
1898
|
+
...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
|
|
1887
1899
|
},
|
|
1888
1900
|
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1889
1901
|
const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
|
|
@@ -1895,15 +1907,20 @@ class CatalogService {
|
|
|
1895
1907
|
.concat(mostRelevantWithouyStock);
|
|
1896
1908
|
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
1897
1909
|
const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
|
|
1910
|
+
await this.setBrandsList(options, totalResult.distinct?.brand);
|
|
1898
1911
|
return {
|
|
1899
1912
|
data: resultFinal,
|
|
1900
1913
|
count: totalResult.count,
|
|
1901
1914
|
maximum: totalResult.maximum,
|
|
1902
1915
|
minimal: totalResult.minimal,
|
|
1903
|
-
distinct:
|
|
1916
|
+
distinct: {
|
|
1917
|
+
...totalResult.distinct,
|
|
1918
|
+
brand: this.brandsList[this.buildIndexBrands(options)],
|
|
1919
|
+
},
|
|
1904
1920
|
};
|
|
1905
1921
|
}
|
|
1906
1922
|
async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
|
|
1923
|
+
const brandsList = this.brandsList[this.buildIndexBrands(options)];
|
|
1907
1924
|
const totalResult = await this.productRepository.findCatalog({
|
|
1908
1925
|
fields: ['id', 'stock', 'gender'],
|
|
1909
1926
|
filters: {
|
|
@@ -1914,7 +1931,7 @@ class CatalogService {
|
|
|
1914
1931
|
options: {
|
|
1915
1932
|
minimal: ['price'],
|
|
1916
1933
|
maximum: ['price'],
|
|
1917
|
-
distinct: ['brand'],
|
|
1934
|
+
...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
|
|
1918
1935
|
},
|
|
1919
1936
|
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1920
1937
|
const defaultGender = options?.filters?.gender
|
|
@@ -1937,12 +1954,16 @@ class CatalogService {
|
|
|
1937
1954
|
id: { operator: Where.IN, value: orderedId },
|
|
1938
1955
|
},
|
|
1939
1956
|
});
|
|
1957
|
+
await this.setBrandsList(options, totalResult.distinct?.brand);
|
|
1940
1958
|
return {
|
|
1941
1959
|
data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
|
|
1942
1960
|
count: totalResult.count,
|
|
1943
1961
|
maximum: totalResult.maximum,
|
|
1944
1962
|
minimal: totalResult.minimal,
|
|
1945
|
-
distinct:
|
|
1963
|
+
distinct: {
|
|
1964
|
+
...totalResult.distinct,
|
|
1965
|
+
brand: this.brandsList[this.buildIndexBrands(options)],
|
|
1966
|
+
},
|
|
1946
1967
|
};
|
|
1947
1968
|
}
|
|
1948
1969
|
async findCatalogIdsBySearch(term, preview = false) {
|
|
@@ -1952,6 +1973,35 @@ class CatalogService {
|
|
|
1952
1973
|
.search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
|
|
1953
1974
|
.then((products) => [...new Set(products.map((product) => product.id))]));
|
|
1954
1975
|
}
|
|
1976
|
+
async fetchBrandsOnly(options, productIds = []) {
|
|
1977
|
+
return this.productRepository
|
|
1978
|
+
.findCatalog({
|
|
1979
|
+
fields: ['id'],
|
|
1980
|
+
filters: {
|
|
1981
|
+
...(!isEmpty(productIds) ? { id: { operator: Where.IN, value: productIds } } : {}),
|
|
1982
|
+
published: { operator: Where.EQUALS, value: true },
|
|
1983
|
+
...this.buildFilterQuery(options?.filters || {}),
|
|
1984
|
+
},
|
|
1985
|
+
options: {
|
|
1986
|
+
distinct: ['brand'],
|
|
1987
|
+
},
|
|
1988
|
+
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
|
|
1989
|
+
.then((result) => {
|
|
1990
|
+
return result.distinct.brand;
|
|
1991
|
+
});
|
|
1992
|
+
}
|
|
1993
|
+
async setBrandsList(options, brands) {
|
|
1994
|
+
const filterBrands = options.filters?.brands;
|
|
1995
|
+
if (isEmpty(brands))
|
|
1996
|
+
delete options.filters?.brands;
|
|
1997
|
+
this.brandsList[this.buildIndexBrands(options)] =
|
|
1998
|
+
this.brandsList[this.buildIndexBrands(options)] || brands || (await this.fetchBrandsOnly(options));
|
|
1999
|
+
this.brandsList[this.buildIndexBrands(options)] = this.brandsList[this.buildIndexBrands(options)].filter(Boolean);
|
|
2000
|
+
options.filters = {
|
|
2001
|
+
...options.filters,
|
|
2002
|
+
brands: filterBrands,
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
1955
2005
|
}
|
|
1956
2006
|
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 });
|
|
1957
2007
|
CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
|