@infrab4a/connect-angular 4.0.0-beta.19 → 4.0.0-beta.20
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-elastic-search.module.mjs +3 -7
- package/esm2020/services/auth.service.mjs +3 -3
- package/esm2020/services/cart.service.mjs +13 -8
- package/fesm2015/infrab4a-connect-angular.mjs +16 -15
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +16 -15
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { Injectable, Inject, InjectionToken, NgModule, PLATFORM_ID } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/fire/auth';
|
|
4
4
|
import { getIdToken, authState, Auth, provideAuth, getAuth } from '@angular/fire/auth';
|
|
5
|
-
import { combineLatest,
|
|
5
|
+
import { combineLatest, from, of, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
6
6
|
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
7
7
|
import * as i3 from '@infrab4a/connect';
|
|
8
8
|
import { Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, 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 } from '@infrab4a/connect';
|
|
@@ -30,7 +30,7 @@ class AuthService {
|
|
|
30
30
|
})));
|
|
31
31
|
}
|
|
32
32
|
getUser() {
|
|
33
|
-
return this.getFireUser().pipe(map((user) => user?.uid), mergeMap((id) => (id ? this.userRepository.get({ id })
|
|
33
|
+
return this.getFireUser().pipe(map((user) => user?.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
|
|
34
34
|
}
|
|
35
35
|
getTokenId() {
|
|
36
36
|
return from(getIdToken(this.angularFireAuth.currentUser));
|
|
@@ -358,13 +358,13 @@ class CartService {
|
|
|
358
358
|
.updateCheckoutLineItems(checkoutLoaded)
|
|
359
359
|
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
360
360
|
}));
|
|
361
|
-
this.generateCartObject = (items) => items
|
|
361
|
+
this.generateCartObject = (items) => items?.reduce((cart, item) => ({
|
|
362
362
|
...cart,
|
|
363
363
|
[item.id]: LineItem.toInstance({
|
|
364
364
|
...(cart[item.id] || item),
|
|
365
365
|
quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
|
|
366
366
|
}),
|
|
367
|
-
}), {});
|
|
367
|
+
}), {}) || {};
|
|
368
368
|
this.buildLineItem = async ({ checkout, item, quantity, }) => {
|
|
369
369
|
const product = await this.getProductData(item.id);
|
|
370
370
|
item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
|
|
@@ -479,6 +479,10 @@ class CartService {
|
|
|
479
479
|
}
|
|
480
480
|
getGifts() {
|
|
481
481
|
return this.checkoutService.getCheckout().pipe(mergeMap(async (checkout) => {
|
|
482
|
+
const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
|
|
483
|
+
if (!notGiftItems.length)
|
|
484
|
+
return { ...checkout, lineItems: [] };
|
|
485
|
+
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
482
486
|
const campaigns = await this.buy2WinRepository
|
|
483
487
|
.find({
|
|
484
488
|
filters: {
|
|
@@ -487,10 +491,8 @@ class CartService {
|
|
|
487
491
|
},
|
|
488
492
|
})
|
|
489
493
|
.then((data) => data.data);
|
|
490
|
-
const notGiftItems = checkout.lineItems.filter((item) => !item.isGift);
|
|
491
494
|
if (!campaigns.length)
|
|
492
495
|
return { ...checkout, lineItems: notGiftItems };
|
|
493
|
-
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
494
496
|
const elegibleCampaigns = [];
|
|
495
497
|
for (const campaign of campaigns) {
|
|
496
498
|
const today = new Date();
|
|
@@ -522,10 +524,13 @@ class CartService {
|
|
|
522
524
|
for (const campaign of elegibleCampaigns) {
|
|
523
525
|
let elegibleProducts = [];
|
|
524
526
|
for (const product of campaign.products) {
|
|
525
|
-
const productData = await this.productRepository.
|
|
526
|
-
if (!productData)
|
|
527
|
+
const { data: productData } = await this.productRepository.find({ filters: { sku: product } });
|
|
528
|
+
if (!productData.length)
|
|
529
|
+
continue;
|
|
530
|
+
const gift = productData.shift();
|
|
531
|
+
if (gift.stock.quantity < 1)
|
|
527
532
|
continue;
|
|
528
|
-
elegibleProducts.push(
|
|
533
|
+
elegibleProducts.push(gift);
|
|
529
534
|
}
|
|
530
535
|
campaingnProducts.push(elegibleProducts);
|
|
531
536
|
}
|
|
@@ -971,9 +976,7 @@ AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0
|
|
|
971
976
|
AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
|
|
972
977
|
{
|
|
973
978
|
provide: ProductsIndex,
|
|
974
|
-
useFactory: (configuration) =>
|
|
975
|
-
return new ProductsIndex(new AxiosAdapter(configuration));
|
|
976
|
-
},
|
|
979
|
+
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
977
980
|
deps: [ES_CONFIG],
|
|
978
981
|
},
|
|
979
982
|
] });
|
|
@@ -983,9 +986,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
983
986
|
providers: [
|
|
984
987
|
{
|
|
985
988
|
provide: ProductsIndex,
|
|
986
|
-
useFactory: (configuration) =>
|
|
987
|
-
return new ProductsIndex(new AxiosAdapter(configuration));
|
|
988
|
-
},
|
|
989
|
+
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
989
990
|
deps: [ES_CONFIG],
|
|
990
991
|
},
|
|
991
992
|
],
|