@infrab4a/connect-angular 6.0.0-beta.36 → 6.0.0-beta.38
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/esm2022/angular-connect.module.mjs +4 -8
- package/esm2022/angular-firestore.module.mjs +16 -2
- package/esm2022/angular-hasura-graphql.module.mjs +4 -4
- package/esm2022/services/cart.service.mjs +13 -2
- package/esm2022/services/checkout.service.mjs +12 -1
- package/esm2022/services/index.mjs +1 -3
- package/esm2022/services/order-recurrence.service.mjs +9 -16
- package/fesm2022/infrab4a-connect-angular.mjs +73 -335
- package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +2 -1
- package/services/checkout.service.d.ts +2 -0
- package/services/index.d.ts +0 -2
- package/services/order-recurrence.service.d.ts +7 -19
- package/esm2022/services/checkout-subscription.service.mjs +0 -55
- package/esm2022/services/coupon/types/coupon-params.type.mjs +0 -2
- package/esm2022/services/coupon.service.mjs +0 -248
- package/services/checkout-subscription.service.d.ts +0 -19
- package/services/coupon/types/coupon-params.type.d.ts +0 -13
- package/services/coupon.service.d.ts +0 -36
|
@@ -7,7 +7,7 @@ import { provideAppCheck, initializeAppCheck } from '@angular/fire/app-check';
|
|
|
7
7
|
import * as i3$1 from '@angular/fire/storage';
|
|
8
8
|
import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
|
|
9
9
|
import * as i3 from '@infrab4a/connect';
|
|
10
|
-
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, GroupFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ShoppingRecurrenceFirestoreRepository, ShoppingRecurrenceEditionFirestoreRepository, ShoppingRecurrenceErrorLogFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, BrandCategoryFirestoreRepository, ShopConfigsFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductErrorsHasuraGraphQLRepository, ProductCatalogHasuraGraphQLRepository, ProductStockEntryHasuraGraphQLRepository, ProductGroupHasuraGraphQLRepository, ProductPriceLogHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, isNil, NotFoundError, Checkout, pick, LineItem, Where, isEmpty, Shops, set, InvalidArgumentError, RoundProductPricesHelper, Category, WishlistLogType, PersonTypes, Wishlist,
|
|
10
|
+
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignHashtagPostsFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, GroupFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ShoppingRecurrenceFirestoreRepository, ShoppingRecurrenceEditionFirestoreRepository, ShoppingRecurrenceErrorLogFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, BrandCategoryFirestoreRepository, ShopConfigsFirestoreRepository, resolveCacheConfig, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductErrorsHasuraGraphQLRepository, ProductCatalogHasuraGraphQLRepository, ProductStockEntryHasuraGraphQLRepository, ProductGroupHasuraGraphQLRepository, ProductPriceLogHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, isNil, NotFoundError, Checkout, pick, LineItem, Where, isEmpty, Shops, set, InvalidArgumentError, RoundProductPricesHelper, Category, WishlistLogType, PersonTypes, Wishlist, Product, RequiredArgumentError, add, OrderStatus, ProductReview, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
|
|
11
11
|
import * as i1 from '@angular/fire/auth';
|
|
12
12
|
import { Auth, provideAuth, initializeAuth, indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
13
13
|
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
|
|
@@ -294,6 +294,13 @@ class AngularFirestoreModule {
|
|
|
294
294
|
},
|
|
295
295
|
deps: ['FirestoreOptions'],
|
|
296
296
|
},
|
|
297
|
+
{
|
|
298
|
+
provide: 'CampaignHashtagPostsRepository',
|
|
299
|
+
useFactory: (options) => {
|
|
300
|
+
return new CampaignHashtagPostsFirestoreRepository(options);
|
|
301
|
+
},
|
|
302
|
+
deps: ['FirestoreOptions'],
|
|
303
|
+
},
|
|
297
304
|
{
|
|
298
305
|
provide: 'CampaignDashboardRepository',
|
|
299
306
|
useFactory: (options) => {
|
|
@@ -603,6 +610,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
603
610
|
},
|
|
604
611
|
deps: ['FirestoreOptions'],
|
|
605
612
|
},
|
|
613
|
+
{
|
|
614
|
+
provide: 'CampaignHashtagPostsRepository',
|
|
615
|
+
useFactory: (options) => {
|
|
616
|
+
return new CampaignHashtagPostsFirestoreRepository(options);
|
|
617
|
+
},
|
|
618
|
+
deps: ['FirestoreOptions'],
|
|
619
|
+
},
|
|
606
620
|
{
|
|
607
621
|
provide: 'CampaignDashboardRepository',
|
|
608
622
|
useFactory: (options) => {
|
|
@@ -825,7 +839,7 @@ class AngularHasuraGraphQLModule {
|
|
|
825
839
|
useFactory: (options, platformId) => ({
|
|
826
840
|
endpoint: options.endpoint,
|
|
827
841
|
authOptions: options.credentials,
|
|
828
|
-
cache: options.cache,
|
|
842
|
+
cache: resolveCacheConfig(options.cache),
|
|
829
843
|
interceptors: {
|
|
830
844
|
request: (request) => {
|
|
831
845
|
if (isPlatformBrowser(platformId))
|
|
@@ -1029,7 +1043,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1029
1043
|
useFactory: (options, platformId) => ({
|
|
1030
1044
|
endpoint: options.endpoint,
|
|
1031
1045
|
authOptions: options.credentials,
|
|
1032
|
-
cache: options.cache,
|
|
1046
|
+
cache: resolveCacheConfig(options.cache),
|
|
1033
1047
|
interceptors: {
|
|
1034
1048
|
request: (request) => {
|
|
1035
1049
|
if (isPlatformBrowser(platformId))
|
|
@@ -1407,6 +1421,17 @@ class CheckoutService {
|
|
|
1407
1421
|
checkoutId: checkout.id,
|
|
1408
1422
|
})), concatMap(() => this.getCheckout()));
|
|
1409
1423
|
}
|
|
1424
|
+
applyPointsDiscount(points) {
|
|
1425
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutApplyPointsDiscount`, {
|
|
1426
|
+
checkoutId: checkout.id,
|
|
1427
|
+
points,
|
|
1428
|
+
})), concatMap(() => this.getCheckout()));
|
|
1429
|
+
}
|
|
1430
|
+
removePointsDiscount() {
|
|
1431
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutRemovePointsDiscount`, {
|
|
1432
|
+
checkoutId: checkout.id,
|
|
1433
|
+
})), concatMap(() => this.getCheckout()));
|
|
1434
|
+
}
|
|
1410
1435
|
validateStockProducts() {
|
|
1411
1436
|
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutValidateProductStock`, {
|
|
1412
1437
|
checkoutId: checkout.id,
|
|
@@ -1487,6 +1512,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1487
1512
|
type: Injectable
|
|
1488
1513
|
}], ctorParameters: () => [{ type: AuthService }, { type: CheckoutService }, { type: i1$2.HttpClient }] });
|
|
1489
1514
|
|
|
1515
|
+
/* eslint-disable max-params */
|
|
1490
1516
|
class CartService {
|
|
1491
1517
|
constructor(servicesFacade, configurationFacade) {
|
|
1492
1518
|
this.servicesFacade = servicesFacade;
|
|
@@ -1502,11 +1528,21 @@ class CartService {
|
|
|
1502
1528
|
}), {}) || {};
|
|
1503
1529
|
this.checkoutUrl = this.configurationFacade.getCheckoutUrl();
|
|
1504
1530
|
}
|
|
1505
|
-
addItem(item, quantity = 1) {
|
|
1531
|
+
addItem(item, quantity = 1, recurrence = false, recurrenceCycle = null) {
|
|
1506
1532
|
return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutAddItemToCart`, {
|
|
1507
1533
|
checkoutId: checkout.id,
|
|
1508
1534
|
productId: item.id,
|
|
1509
1535
|
quantity,
|
|
1536
|
+
recurrence,
|
|
1537
|
+
recurrenceCycle,
|
|
1538
|
+
})), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1539
|
+
}
|
|
1540
|
+
updateItemRecurrence(item, recurrence = false, recurrenceCycle = null) {
|
|
1541
|
+
return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutUpdateItemRecurrence`, {
|
|
1542
|
+
checkoutId: checkout.id,
|
|
1543
|
+
productId: item.id,
|
|
1544
|
+
recurrence,
|
|
1545
|
+
recurrenceCycle,
|
|
1510
1546
|
})), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1511
1547
|
}
|
|
1512
1548
|
decreaseItem(item) {
|
|
@@ -2715,315 +2751,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2715
2751
|
args: [DEFAULT_SHOP]
|
|
2716
2752
|
}] }] });
|
|
2717
2753
|
|
|
2718
|
-
class CouponRepositoriesFacade {
|
|
2719
|
-
constructor(couponRepository, orderRepository, categoryRepository) {
|
|
2720
|
-
this.couponRepository = couponRepository;
|
|
2721
|
-
this.orderRepository = orderRepository;
|
|
2722
|
-
this.categoryRepository = categoryRepository;
|
|
2723
|
-
}
|
|
2724
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponRepositoriesFacade, deps: [{ token: 'CouponRepository' }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2725
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponRepositoriesFacade }); }
|
|
2726
|
-
}
|
|
2727
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
|
|
2728
|
-
type: Injectable
|
|
2729
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
2730
|
-
type: Inject,
|
|
2731
|
-
args: ['CouponRepository']
|
|
2732
|
-
}] }, { type: undefined, decorators: [{
|
|
2733
|
-
type: Inject,
|
|
2734
|
-
args: ['OrderRepository']
|
|
2735
|
-
}] }, { type: undefined, decorators: [{
|
|
2736
|
-
type: Inject,
|
|
2737
|
-
args: ['CategoryRepository']
|
|
2738
|
-
}] }] });
|
|
2739
|
-
|
|
2740
|
-
class CouponService {
|
|
2741
|
-
constructor(repositoriesFacade, configurationFacade) {
|
|
2742
|
-
this.repositoriesFacade = repositoriesFacade;
|
|
2743
|
-
this.configurationFacade = configurationFacade;
|
|
2744
|
-
this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
|
|
2745
|
-
}
|
|
2746
|
-
checkCoupon(params) {
|
|
2747
|
-
const { nickname, checkoutType, checkout, plan } = params;
|
|
2748
|
-
return from(this.repositoriesFacade.couponRepository
|
|
2749
|
-
.find({
|
|
2750
|
-
filters: {
|
|
2751
|
-
nickname: { operator: Where.EQUALS, value: nickname },
|
|
2752
|
-
active: { operator: Where.EQUALS, value: true },
|
|
2753
|
-
},
|
|
2754
|
-
})
|
|
2755
|
-
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation({ coupon: couponValid, checkoutType, checkout, plan })), map((couponValidated) => couponValidated));
|
|
2756
|
-
}
|
|
2757
|
-
async couponValidation(coupon, checkoutType) {
|
|
2758
|
-
if (!coupon)
|
|
2759
|
-
throw 'Cupom inválido.';
|
|
2760
|
-
if (coupon?.beginAt && coupon?.beginAt.getTime() > new Date().getTime())
|
|
2761
|
-
throw 'Cupom inválido.';
|
|
2762
|
-
if (coupon?.expiresIn && (coupon?.expiresIn).getTime() < new Date().getTime())
|
|
2763
|
-
throw 'Cupom expirado.';
|
|
2764
|
-
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.configurationFacade.defaultShop;
|
|
2765
|
-
if (!isInShop)
|
|
2766
|
-
throw 'Cupom inválido para loja.';
|
|
2767
|
-
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
2768
|
-
if (!isCheckoutType)
|
|
2769
|
-
throw 'Cupom inválido. Erro de checkout.';
|
|
2770
|
-
return coupon;
|
|
2771
|
-
}
|
|
2772
|
-
async couponRulesValidation(params) {
|
|
2773
|
-
const { coupon, checkoutType, checkout, plan } = params;
|
|
2774
|
-
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
2775
|
-
return this.validateSubscriptionCoupon(coupon, plan);
|
|
2776
|
-
}
|
|
2777
|
-
return this.validateEcommerceCoupon(coupon, checkoutType, checkout);
|
|
2778
|
-
}
|
|
2779
|
-
validateSubscriptionCoupon(coupon, plan) {
|
|
2780
|
-
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase()) {
|
|
2781
|
-
throw 'Cupom inválido para sua assinatura.';
|
|
2782
|
-
}
|
|
2783
|
-
return coupon;
|
|
2784
|
-
}
|
|
2785
|
-
async validateEcommerceCoupon(coupon, checkoutType, checkout) {
|
|
2786
|
-
this.validateUserEligibility(coupon, checkout?.user);
|
|
2787
|
-
await this.validateUsageLimits(coupon, checkoutType, checkout);
|
|
2788
|
-
await this.validateProductEligibility(coupon, checkout);
|
|
2789
|
-
return coupon;
|
|
2790
|
-
}
|
|
2791
|
-
validateUserEligibility(coupon, user) {
|
|
2792
|
-
const validUser = this.coupomUserValidation(coupon, user);
|
|
2793
|
-
if (!validUser)
|
|
2794
|
-
throw 'Usuário não elegível.';
|
|
2795
|
-
}
|
|
2796
|
-
async validateUsageLimits(coupon, checkoutType, checkout) {
|
|
2797
|
-
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
2798
|
-
if (couponUseLimits.firstOrder) {
|
|
2799
|
-
await this.validateFirstOrderLimit(checkout.user.email);
|
|
2800
|
-
}
|
|
2801
|
-
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
2802
|
-
await this.validateCouponUsageLimits(coupon, couponUseLimits, checkout.user.email);
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
async validateFirstOrderLimit(userEmail) {
|
|
2806
|
-
const ordersUser = await this.getOrdersFromUser(userEmail.toLocaleLowerCase());
|
|
2807
|
-
if (ordersUser.length >= 1)
|
|
2808
|
-
throw 'Limite de uso atingido';
|
|
2809
|
-
}
|
|
2810
|
-
async validateCouponUsageLimits(coupon, couponUseLimits, userEmail) {
|
|
2811
|
-
const ordersCoupon = await this.getOrdersWithCoupon(coupon);
|
|
2812
|
-
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total) {
|
|
2813
|
-
throw 'Limite de uso atingido.';
|
|
2814
|
-
}
|
|
2815
|
-
if (couponUseLimits.limitedPerUser) {
|
|
2816
|
-
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, userEmail);
|
|
2817
|
-
if (ordersWithUser > 0)
|
|
2818
|
-
throw 'Limite de uso por usuário atingido.';
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
async validateProductEligibility(coupon, checkout) {
|
|
2822
|
-
const hasProductCategories = await this.hasProductCategories(coupon, checkout);
|
|
2823
|
-
if (!hasProductCategories)
|
|
2824
|
-
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
2825
|
-
const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
|
|
2826
|
-
if (!hasMinSubTotal) {
|
|
2827
|
-
this.throwMinSubTotalError(coupon);
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
throwMinSubTotalError(coupon) {
|
|
2831
|
-
const formattedValue = Intl.NumberFormat('pt-BR', {
|
|
2832
|
-
style: 'currency',
|
|
2833
|
-
currency: 'BRL',
|
|
2834
|
-
}).format(coupon.minSubTotalValue);
|
|
2835
|
-
if (coupon.productsCategories?.length) {
|
|
2836
|
-
throw `Valor mínimo de ${formattedValue} não atingido na(s) categoria(s) elegíveis para o desconto.`;
|
|
2837
|
-
}
|
|
2838
|
-
throw `Valor mínimo de ${formattedValue} não atingido.`;
|
|
2839
|
-
}
|
|
2840
|
-
calcDiscountSubscription(coupon, checkout) {
|
|
2841
|
-
let discount = 0;
|
|
2842
|
-
if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
|
|
2843
|
-
discount = coupon.discount.subscription.value;
|
|
2844
|
-
else
|
|
2845
|
-
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
|
|
2846
|
-
return of(discount);
|
|
2847
|
-
}
|
|
2848
|
-
async hasMinSubTotal(coupon, checkout) {
|
|
2849
|
-
if (!coupon.minSubTotalValue)
|
|
2850
|
-
return true;
|
|
2851
|
-
const lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
2852
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
2853
|
-
if (coupon.minSubTotalValue <= subTotal)
|
|
2854
|
-
return true;
|
|
2855
|
-
return false;
|
|
2856
|
-
}
|
|
2857
|
-
async hasProductCategories(coupon, checkout) {
|
|
2858
|
-
if (!coupon.productsCategories?.length) {
|
|
2859
|
-
return true;
|
|
2860
|
-
}
|
|
2861
|
-
const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
|
|
2862
|
-
const hasCategories = checkout.lineItems?.filter((item) => {
|
|
2863
|
-
if (item.isGift)
|
|
2864
|
-
return false;
|
|
2865
|
-
if (!item.categories?.length)
|
|
2866
|
-
return true;
|
|
2867
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2868
|
-
});
|
|
2869
|
-
return hasCategories?.length ? true : false;
|
|
2870
|
-
}
|
|
2871
|
-
coupomUserValidation(coupon, user) {
|
|
2872
|
-
if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
|
|
2873
|
-
return true;
|
|
2874
|
-
const userTypes = [];
|
|
2875
|
-
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
|
|
2876
|
-
this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
|
|
2877
|
-
userTypes.push(Exclusivities.COLLABORATORS);
|
|
2878
|
-
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
|
|
2879
|
-
coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
|
|
2880
|
-
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
2881
|
-
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
2882
|
-
user.isSubscriber &&
|
|
2883
|
-
user.subscriptionPlan != '')
|
|
2884
|
-
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
2885
|
-
if (user.isSubscriber &&
|
|
2886
|
-
user.subscriptionPlan == '' &&
|
|
2887
|
-
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
2888
|
-
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
2889
|
-
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
2890
|
-
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
2891
|
-
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
2892
|
-
}
|
|
2893
|
-
async getCouponCategoriesId(productsCategories) {
|
|
2894
|
-
const couponCategories = [];
|
|
2895
|
-
for (let index = 0; index < productsCategories.length; index++) {
|
|
2896
|
-
const category = await this.repositoriesFacade.categoryRepository.get({
|
|
2897
|
-
id: productsCategories[index],
|
|
2898
|
-
});
|
|
2899
|
-
if (category) {
|
|
2900
|
-
const children = await this.repositoriesFacade.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
2901
|
-
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
return [...new Set(couponCategories)];
|
|
2905
|
-
}
|
|
2906
|
-
async getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
2907
|
-
let lineItensDiscount = [];
|
|
2908
|
-
const couponCategories = await this.getCouponCategoriesId(productsCategories);
|
|
2909
|
-
if (productsCategories?.length) {
|
|
2910
|
-
lineItensDiscount = checkout.lineItems?.filter((item) => {
|
|
2911
|
-
if (item.isGift)
|
|
2912
|
-
return false;
|
|
2913
|
-
if (item.categories?.length) {
|
|
2914
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2915
|
-
}
|
|
2916
|
-
return true;
|
|
2917
|
-
});
|
|
2918
|
-
}
|
|
2919
|
-
else {
|
|
2920
|
-
lineItensDiscount = checkout.lineItems.filter((item) => !item.isGift);
|
|
2921
|
-
}
|
|
2922
|
-
return lineItensDiscount;
|
|
2923
|
-
}
|
|
2924
|
-
calcCheckoutSubtotal(lineItens, user) {
|
|
2925
|
-
return (lineItens
|
|
2926
|
-
?.filter((item) => !item.isGift)
|
|
2927
|
-
.reduce((acc, curr) => user?.isSubscriber && curr.price?.subscriberPrice
|
|
2928
|
-
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
2929
|
-
: acc + curr.pricePaid * curr.quantity, 0) || 0);
|
|
2930
|
-
}
|
|
2931
|
-
async getOrdersWithCoupon(coupon) {
|
|
2932
|
-
return await this.repositoriesFacade.orderRepository
|
|
2933
|
-
.find({
|
|
2934
|
-
filters: {
|
|
2935
|
-
coupon: { id: coupon.id },
|
|
2936
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2937
|
-
},
|
|
2938
|
-
})
|
|
2939
|
-
.then((result) => result.data);
|
|
2940
|
-
}
|
|
2941
|
-
async getOrdersFromUser(email) {
|
|
2942
|
-
return await this.repositoriesFacade.orderRepository
|
|
2943
|
-
.find({
|
|
2944
|
-
filters: {
|
|
2945
|
-
user: { email: { operator: Where.EQUALS, value: email } },
|
|
2946
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2947
|
-
},
|
|
2948
|
-
})
|
|
2949
|
-
.then((result) => result.data);
|
|
2950
|
-
}
|
|
2951
|
-
countOrdersWithUser(orders, email) {
|
|
2952
|
-
return orders.filter((o) => o.user.email == email).length;
|
|
2953
|
-
}
|
|
2954
|
-
getCouponUseLimits(coupon, checkoutType, user) {
|
|
2955
|
-
let couponUseLimits;
|
|
2956
|
-
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
2957
|
-
if (coupon.exclusivityType.length === 1 &&
|
|
2958
|
-
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
2959
|
-
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
2960
|
-
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
2961
|
-
else
|
|
2962
|
-
couponUseLimits = user?.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
2963
|
-
}
|
|
2964
|
-
else {
|
|
2965
|
-
couponUseLimits = coupon.useLimits.subscription;
|
|
2966
|
-
}
|
|
2967
|
-
return couponUseLimits;
|
|
2968
|
-
}
|
|
2969
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, deps: [{ token: CouponRepositoriesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2970
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, providedIn: 'root' }); }
|
|
2971
|
-
}
|
|
2972
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, decorators: [{
|
|
2973
|
-
type: Injectable,
|
|
2974
|
-
args: [{
|
|
2975
|
-
providedIn: 'root',
|
|
2976
|
-
}]
|
|
2977
|
-
}], ctorParameters: () => [{ type: CouponRepositoriesFacade }, { type: ConfigurationFacade }] });
|
|
2978
|
-
|
|
2979
|
-
class CheckoutSubscriptionService {
|
|
2980
|
-
constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
|
|
2981
|
-
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
2982
|
-
this.dataPersistence = dataPersistence;
|
|
2983
|
-
this.couponService = couponService;
|
|
2984
|
-
}
|
|
2985
|
-
getCheckoutSubscription(checkoutData) {
|
|
2986
|
-
return this.dataPersistence
|
|
2987
|
-
.get('checkoutSubscriptionId')
|
|
2988
|
-
.pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
|
|
2989
|
-
}
|
|
2990
|
-
clearCheckoutSubscriptionFromSession() {
|
|
2991
|
-
return this.dataPersistence.remove('checkoutSubscriptionId');
|
|
2992
|
-
}
|
|
2993
|
-
checkCoupon(nickname, _userEmail) {
|
|
2994
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
2995
|
-
.checkCoupon({
|
|
2996
|
-
nickname,
|
|
2997
|
-
checkoutType: CheckoutTypes.SUBSCRIPTION,
|
|
2998
|
-
checkout,
|
|
2999
|
-
plan: checkout.subscriptionPlan.name,
|
|
3000
|
-
})
|
|
3001
|
-
.pipe()));
|
|
3002
|
-
}
|
|
3003
|
-
calcDiscountSubscription(coupon) {
|
|
3004
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
3005
|
-
}
|
|
3006
|
-
async createCheckoutSubscription(checkoutData) {
|
|
3007
|
-
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
3008
|
-
createdAt: new Date(),
|
|
3009
|
-
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
3010
|
-
});
|
|
3011
|
-
await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
|
|
3012
|
-
return checkout;
|
|
3013
|
-
}
|
|
3014
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: PERSISTENCE_PROVIDER }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3015
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService }); }
|
|
3016
|
-
}
|
|
3017
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
3018
|
-
type: Injectable
|
|
3019
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
3020
|
-
type: Inject,
|
|
3021
|
-
args: ['CheckoutSubscriptionRepository']
|
|
3022
|
-
}] }, { type: undefined, decorators: [{
|
|
3023
|
-
type: Inject,
|
|
3024
|
-
args: [PERSISTENCE_PROVIDER]
|
|
3025
|
-
}] }, { type: CouponService }] });
|
|
3026
|
-
|
|
3027
2754
|
class UtilHelper {
|
|
3028
2755
|
static createSlug(name) {
|
|
3029
2756
|
return name
|
|
@@ -3344,27 +3071,20 @@ class OrderRecurrenceService {
|
|
|
3344
3071
|
});
|
|
3345
3072
|
}
|
|
3346
3073
|
enableOrDisableRecurrenceOrder(recurrenceId, active) {
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
active,
|
|
3350
|
-
});
|
|
3074
|
+
const payload = { recurrenceId, active };
|
|
3075
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/enableOrDisableShoppingRecurrence`, payload);
|
|
3351
3076
|
}
|
|
3352
3077
|
skipRecurrenceOrder(recurrenceEditionId) {
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
});
|
|
3078
|
+
const payload = { recurrenceEditionId };
|
|
3079
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/skipShoppingRecurrenceEdition`, payload);
|
|
3356
3080
|
}
|
|
3357
3081
|
updateFrequency(recurrenceId, frequency) {
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
frequency,
|
|
3361
|
-
});
|
|
3082
|
+
const payload = { recurrenceId, frequency };
|
|
3083
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/updateShoppingRecurrenceFrequency`, payload);
|
|
3362
3084
|
}
|
|
3363
3085
|
updateLineItems(recurrenceId, lineItems) {
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
lineItems,
|
|
3367
|
-
});
|
|
3086
|
+
const payload = { recurrenceId, lineItems };
|
|
3087
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/updateShoppingRecurrenceLineItems`, payload);
|
|
3368
3088
|
}
|
|
3369
3089
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: OrderRecurrenceService, deps: [{ token: 'ShoppingRecurrenceRepository' }, { token: DEFAULT_SHOP }, { token: CheckoutDependenciesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3370
3090
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: OrderRecurrenceService }); }
|
|
@@ -3401,6 +3121,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
3401
3121
|
args: ['OrderRepository']
|
|
3402
3122
|
}] }] });
|
|
3403
3123
|
|
|
3124
|
+
class CouponRepositoriesFacade {
|
|
3125
|
+
constructor(couponRepository, orderRepository, categoryRepository) {
|
|
3126
|
+
this.couponRepository = couponRepository;
|
|
3127
|
+
this.orderRepository = orderRepository;
|
|
3128
|
+
this.categoryRepository = categoryRepository;
|
|
3129
|
+
}
|
|
3130
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponRepositoriesFacade, deps: [{ token: 'CouponRepository' }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3131
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponRepositoriesFacade }); }
|
|
3132
|
+
}
|
|
3133
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
|
|
3134
|
+
type: Injectable
|
|
3135
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
3136
|
+
type: Inject,
|
|
3137
|
+
args: ['CouponRepository']
|
|
3138
|
+
}] }, { type: undefined, decorators: [{
|
|
3139
|
+
type: Inject,
|
|
3140
|
+
args: ['OrderRepository']
|
|
3141
|
+
}] }, { type: undefined, decorators: [{
|
|
3142
|
+
type: Inject,
|
|
3143
|
+
args: ['CategoryRepository']
|
|
3144
|
+
}] }] });
|
|
3145
|
+
|
|
3404
3146
|
class AngularConnectModule {
|
|
3405
3147
|
static initializeApp(defaultShop, options, nameOrConfig) {
|
|
3406
3148
|
return {
|
|
@@ -3453,8 +3195,6 @@ class AngularConnectModule {
|
|
|
3453
3195
|
CatalogService,
|
|
3454
3196
|
CategoryService,
|
|
3455
3197
|
CheckoutService,
|
|
3456
|
-
CheckoutSubscriptionService,
|
|
3457
|
-
CouponService,
|
|
3458
3198
|
HomeShopService,
|
|
3459
3199
|
OrderService,
|
|
3460
3200
|
WishlistService,
|
|
@@ -3515,7 +3255,7 @@ class AngularConnectModule {
|
|
|
3515
3255
|
CouponRepositoriesFacade,
|
|
3516
3256
|
HomeShopRepositoriesFacade,
|
|
3517
3257
|
OrderProductReviewService,
|
|
3518
|
-
OrderRecurrenceService
|
|
3258
|
+
OrderRecurrenceService,
|
|
3519
3259
|
], imports: [provideFirebaseApp((injector) => {
|
|
3520
3260
|
const appName = injector.get(FIREBASE_APP_NAME);
|
|
3521
3261
|
try {
|
|
@@ -3598,8 +3338,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
3598
3338
|
CatalogService,
|
|
3599
3339
|
CategoryService,
|
|
3600
3340
|
CheckoutService,
|
|
3601
|
-
CheckoutSubscriptionService,
|
|
3602
|
-
CouponService,
|
|
3603
3341
|
HomeShopService,
|
|
3604
3342
|
OrderService,
|
|
3605
3343
|
WishlistService,
|
|
@@ -3660,7 +3398,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
3660
3398
|
CouponRepositoriesFacade,
|
|
3661
3399
|
HomeShopRepositoriesFacade,
|
|
3662
3400
|
OrderProductReviewService,
|
|
3663
|
-
OrderRecurrenceService
|
|
3401
|
+
OrderRecurrenceService,
|
|
3664
3402
|
],
|
|
3665
3403
|
}]
|
|
3666
3404
|
}] });
|
|
@@ -3669,5 +3407,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
3669
3407
|
* Generated bundle index. Do not edit.
|
|
3670
3408
|
*/
|
|
3671
3409
|
|
|
3672
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService,
|
|
3410
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CookieDataPersistence, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderProductReviewService, OrderRecurrenceService, OrderService, ProductSorts, UtilHelper, WishlistService };
|
|
3673
3411
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|