@infrab4a/connect-angular 4.3.0-beta.1 → 4.3.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/angular-hasura-graphql.module.mjs +24 -2
- package/esm2020/services/catalog/catalog.service.mjs +41 -2
- package/fesm2015/infrab4a-connect-angular.mjs +66 -1
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +62 -1
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/catalog/catalog.service.d.ts +3 -0
|
@@ -3,7 +3,7 @@ import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angu
|
|
|
3
3
|
import * as i1$4 from '@angular/fire/app';
|
|
4
4
|
import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
|
|
5
5
|
import * as i1$2 from '@infrab4a/connect';
|
|
6
|
-
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, 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, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
|
|
6
|
+
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, 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, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
|
|
7
7
|
import * as i1 from '@angular/fire/auth';
|
|
8
8
|
import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
9
9
|
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
|
|
@@ -703,6 +703,17 @@ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.
|
|
|
703
703
|
},
|
|
704
704
|
deps: ['HasuraConfig'],
|
|
705
705
|
},
|
|
706
|
+
{
|
|
707
|
+
provide: 'ProductReviewsRepository',
|
|
708
|
+
useExisting: ProductReviewsHasuraGraphQLRepository,
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
provide: ProductReviewsHasuraGraphQLRepository,
|
|
712
|
+
useFactory: (hasuraConfig) => {
|
|
713
|
+
return new ProductReviewsHasuraGraphQLRepository(hasuraConfig);
|
|
714
|
+
},
|
|
715
|
+
deps: ['HasuraConfig'],
|
|
716
|
+
},
|
|
706
717
|
{
|
|
707
718
|
provide: 'VariantRepository',
|
|
708
719
|
useExisting: VariantHasuraGraphQLRepository,
|
|
@@ -817,6 +828,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
817
828
|
},
|
|
818
829
|
deps: ['HasuraConfig'],
|
|
819
830
|
},
|
|
831
|
+
{
|
|
832
|
+
provide: 'ProductReviewsRepository',
|
|
833
|
+
useExisting: ProductReviewsHasuraGraphQLRepository,
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
provide: ProductReviewsHasuraGraphQLRepository,
|
|
837
|
+
useFactory: (hasuraConfig) => {
|
|
838
|
+
return new ProductReviewsHasuraGraphQLRepository(hasuraConfig);
|
|
839
|
+
},
|
|
840
|
+
deps: ['HasuraConfig'],
|
|
841
|
+
},
|
|
820
842
|
{
|
|
821
843
|
provide: 'VariantRepository',
|
|
822
844
|
useExisting: VariantHasuraGraphQLRepository,
|
|
@@ -1464,6 +1486,7 @@ class CatalogService {
|
|
|
1464
1486
|
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
1465
1487
|
this.shop = shop;
|
|
1466
1488
|
this.productIndex = productIndex;
|
|
1489
|
+
this.productsByTerm = {};
|
|
1467
1490
|
this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
|
|
1468
1491
|
const filters = {};
|
|
1469
1492
|
if (clubDiscount?.length)
|
|
@@ -1534,6 +1557,8 @@ class CatalogService {
|
|
|
1534
1557
|
}));
|
|
1535
1558
|
}
|
|
1536
1559
|
async findCatalog(options, limits) {
|
|
1560
|
+
if (this.hasTerm(options) && options.sort === 'most-relevant')
|
|
1561
|
+
return this.findCatalogByTermAndSortByMostRevelant(options, limits);
|
|
1537
1562
|
const repoParams = {
|
|
1538
1563
|
filters: {
|
|
1539
1564
|
...(await this.buildMainFilter(options)),
|
|
@@ -1561,6 +1586,42 @@ class CatalogService {
|
|
|
1561
1586
|
.search(term, 999, this.shop)
|
|
1562
1587
|
.then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
|
|
1563
1588
|
}
|
|
1589
|
+
async findCatalogByTermAndSortByMostRevelant(options, limits) {
|
|
1590
|
+
const productIds = await this.findCatalogIdsByElasticSearch(options.term);
|
|
1591
|
+
const limitedProductId = productIds.slice(limits.offset, limits.offset + limits.limit);
|
|
1592
|
+
const productResult = await this.productRepository.findCatalog({
|
|
1593
|
+
filters: { id: { operator: Where.IN, value: limitedProductId } },
|
|
1594
|
+
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1595
|
+
const totalResult = await this.productRepository.findCatalog({
|
|
1596
|
+
fields: ['id'],
|
|
1597
|
+
filters: { id: { operator: Where.IN, value: productIds } },
|
|
1598
|
+
limits: { limit: 1, offset: 0 },
|
|
1599
|
+
options: {
|
|
1600
|
+
minimal: ['price'],
|
|
1601
|
+
maximum: ['price'],
|
|
1602
|
+
distinct: ['brand'],
|
|
1603
|
+
},
|
|
1604
|
+
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1605
|
+
return {
|
|
1606
|
+
data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
|
|
1607
|
+
count: totalResult.count,
|
|
1608
|
+
maximum: totalResult.maximum,
|
|
1609
|
+
minimal: totalResult.minimal,
|
|
1610
|
+
distinct: totalResult.distinct,
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
async findCatalogIdsByElasticSearch(term) {
|
|
1614
|
+
if (this.productsByTerm[term])
|
|
1615
|
+
return this.productsByTerm[term];
|
|
1616
|
+
return (this.productsByTerm[term] = await this.productIndex
|
|
1617
|
+
.search(term, 999, this.shop)
|
|
1618
|
+
.then(({ hits: products }) => {
|
|
1619
|
+
const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
|
|
1620
|
+
const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
|
|
1621
|
+
const sorted = [...withStock, ...withOutStock];
|
|
1622
|
+
return [...new Set(sorted.map(({ _source }) => _source.id))];
|
|
1623
|
+
}));
|
|
1624
|
+
}
|
|
1564
1625
|
}
|
|
1565
1626
|
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 }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1566
1627
|
CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
|