@infrab4a/connect-angular 5.7.5-beta.1 → 5.7.5-beta.10
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.
|
@@ -4,7 +4,7 @@ import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular
|
|
|
4
4
|
import { provideAppCheck, initializeAppCheck } from '@angular/fire/app-check';
|
|
5
5
|
import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
|
|
6
6
|
import * as i3 from '@infrab4a/connect';
|
|
7
|
-
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, CategoryFirestoreRepository, ProductFirestoreRepository, ProductVariantFirestoreRepository, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, GroupFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ShoppingRecurrenceFirestoreRepository, ShoppingRecurrenceEditionFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, 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,
|
|
7
|
+
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, CategoryFirestoreRepository, ProductFirestoreRepository, ProductVariantFirestoreRepository, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignHashtagPostsFirestoreRepository, CampaignDashboardFirestoreRepository, CampaignSettingsFirestoreRepository, SubscriptionEditionFirestoreRepository, GroupFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PendingOrderFirestoreRepository, PaymentFirestoreRepository, ShoppingRecurrenceFirestoreRepository, ShoppingRecurrenceEditionFirestoreRepository, ShoppingRecurrenceErrorLogFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, BrandCategoryFirestoreRepository, ShopConfigsFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductErrorsHasuraGraphQLRepository, ProductCatalogHasuraGraphQLRepository, ProductStockEntryHasuraGraphQLRepository, ProductGroupHasuraGraphQLRepository, ProductPriceLogHasuraGraphQLRepository, resolveCacheConfig, 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';
|
|
8
8
|
import * as i1 from '@angular/fire/auth';
|
|
9
9
|
import { Auth, provideAuth, initializeAuth, indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
10
10
|
import { isPlatformServer, isPlatformBrowser } from '@angular/common';
|
|
@@ -304,6 +304,13 @@ class AngularFirestoreModule {
|
|
|
304
304
|
},
|
|
305
305
|
deps: ['FirestoreOptions'],
|
|
306
306
|
},
|
|
307
|
+
{
|
|
308
|
+
provide: 'CampaignHashtagPostsRepository',
|
|
309
|
+
useFactory: (options) => {
|
|
310
|
+
return new CampaignHashtagPostsFirestoreRepository(options);
|
|
311
|
+
},
|
|
312
|
+
deps: ['FirestoreOptions'],
|
|
313
|
+
},
|
|
307
314
|
{
|
|
308
315
|
provide: 'CampaignDashboardRepository',
|
|
309
316
|
useFactory: (options) => {
|
|
@@ -311,6 +318,13 @@ class AngularFirestoreModule {
|
|
|
311
318
|
},
|
|
312
319
|
deps: ['FirestoreOptions'],
|
|
313
320
|
},
|
|
321
|
+
{
|
|
322
|
+
provide: 'CampaignSettingsRepository',
|
|
323
|
+
useFactory: (options) => {
|
|
324
|
+
return new CampaignSettingsFirestoreRepository(options);
|
|
325
|
+
},
|
|
326
|
+
deps: ['FirestoreOptions'],
|
|
327
|
+
},
|
|
314
328
|
{
|
|
315
329
|
provide: 'EditionRepository',
|
|
316
330
|
useFactory: (options, subscriptionRepository) => {
|
|
@@ -360,6 +374,13 @@ class AngularFirestoreModule {
|
|
|
360
374
|
},
|
|
361
375
|
deps: ['FirestoreOptions'],
|
|
362
376
|
},
|
|
377
|
+
{
|
|
378
|
+
provide: 'PendingOrderRepository',
|
|
379
|
+
useFactory: (options) => {
|
|
380
|
+
return new PendingOrderFirestoreRepository(options);
|
|
381
|
+
},
|
|
382
|
+
deps: ['FirestoreOptions'],
|
|
383
|
+
},
|
|
363
384
|
{
|
|
364
385
|
provide: 'PaymentRepository',
|
|
365
386
|
useFactory: (options) => {
|
|
@@ -381,6 +402,13 @@ class AngularFirestoreModule {
|
|
|
381
402
|
},
|
|
382
403
|
deps: ['FirestoreOptions'],
|
|
383
404
|
},
|
|
405
|
+
{
|
|
406
|
+
provide: 'ShoppingRecurrenceErrorLogRepository',
|
|
407
|
+
useFactory: (options) => {
|
|
408
|
+
return new ShoppingRecurrenceErrorLogFirestoreRepository(options);
|
|
409
|
+
},
|
|
410
|
+
deps: ['FirestoreOptions'],
|
|
411
|
+
},
|
|
384
412
|
{
|
|
385
413
|
provide: ProductFirestoreRepository,
|
|
386
414
|
useFactory: (options) => {
|
|
@@ -591,6 +619,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
591
619
|
},
|
|
592
620
|
deps: ['FirestoreOptions'],
|
|
593
621
|
},
|
|
622
|
+
{
|
|
623
|
+
provide: 'CampaignHashtagPostsRepository',
|
|
624
|
+
useFactory: (options) => {
|
|
625
|
+
return new CampaignHashtagPostsFirestoreRepository(options);
|
|
626
|
+
},
|
|
627
|
+
deps: ['FirestoreOptions'],
|
|
628
|
+
},
|
|
594
629
|
{
|
|
595
630
|
provide: 'CampaignDashboardRepository',
|
|
596
631
|
useFactory: (options) => {
|
|
@@ -598,6 +633,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
598
633
|
},
|
|
599
634
|
deps: ['FirestoreOptions'],
|
|
600
635
|
},
|
|
636
|
+
{
|
|
637
|
+
provide: 'CampaignSettingsRepository',
|
|
638
|
+
useFactory: (options) => {
|
|
639
|
+
return new CampaignSettingsFirestoreRepository(options);
|
|
640
|
+
},
|
|
641
|
+
deps: ['FirestoreOptions'],
|
|
642
|
+
},
|
|
601
643
|
{
|
|
602
644
|
provide: 'EditionRepository',
|
|
603
645
|
useFactory: (options, subscriptionRepository) => {
|
|
@@ -647,6 +689,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
647
689
|
},
|
|
648
690
|
deps: ['FirestoreOptions'],
|
|
649
691
|
},
|
|
692
|
+
{
|
|
693
|
+
provide: 'PendingOrderRepository',
|
|
694
|
+
useFactory: (options) => {
|
|
695
|
+
return new PendingOrderFirestoreRepository(options);
|
|
696
|
+
},
|
|
697
|
+
deps: ['FirestoreOptions'],
|
|
698
|
+
},
|
|
650
699
|
{
|
|
651
700
|
provide: 'PaymentRepository',
|
|
652
701
|
useFactory: (options) => {
|
|
@@ -668,6 +717,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
668
717
|
},
|
|
669
718
|
deps: ['FirestoreOptions'],
|
|
670
719
|
},
|
|
720
|
+
{
|
|
721
|
+
provide: 'ShoppingRecurrenceErrorLogRepository',
|
|
722
|
+
useFactory: (options) => {
|
|
723
|
+
return new ShoppingRecurrenceErrorLogFirestoreRepository(options);
|
|
724
|
+
},
|
|
725
|
+
deps: ['FirestoreOptions'],
|
|
726
|
+
},
|
|
671
727
|
{
|
|
672
728
|
provide: ProductFirestoreRepository,
|
|
673
729
|
useFactory: (options) => {
|
|
@@ -806,7 +862,7 @@ class AngularHasuraGraphQLModule {
|
|
|
806
862
|
useFactory: (options, platformId) => ({
|
|
807
863
|
endpoint: options.endpoint,
|
|
808
864
|
authOptions: options.credentials,
|
|
809
|
-
cache: options.cache,
|
|
865
|
+
cache: resolveCacheConfig(options.cache),
|
|
810
866
|
interceptors: {
|
|
811
867
|
request: (request) => {
|
|
812
868
|
if (isPlatformBrowser(platformId))
|
|
@@ -1010,7 +1066,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
1010
1066
|
useFactory: (options, platformId) => ({
|
|
1011
1067
|
endpoint: options.endpoint,
|
|
1012
1068
|
authOptions: options.credentials,
|
|
1013
|
-
cache: options.cache,
|
|
1069
|
+
cache: resolveCacheConfig(options.cache),
|
|
1014
1070
|
interceptors: {
|
|
1015
1071
|
request: (request) => {
|
|
1016
1072
|
if (isPlatformBrowser(platformId))
|
|
@@ -1388,6 +1444,17 @@ class CheckoutService {
|
|
|
1388
1444
|
checkoutId: checkout.id,
|
|
1389
1445
|
})), concatMap(() => this.getCheckout()));
|
|
1390
1446
|
}
|
|
1447
|
+
applyPointsDiscount(points) {
|
|
1448
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutApplyPointsDiscount`, {
|
|
1449
|
+
checkoutId: checkout.id,
|
|
1450
|
+
points,
|
|
1451
|
+
})), concatMap(() => this.getCheckout()));
|
|
1452
|
+
}
|
|
1453
|
+
removePointsDiscount() {
|
|
1454
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutRemovePointsDiscount`, {
|
|
1455
|
+
checkoutId: checkout.id,
|
|
1456
|
+
})), concatMap(() => this.getCheckout()));
|
|
1457
|
+
}
|
|
1391
1458
|
validateStockProducts() {
|
|
1392
1459
|
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutValidateProductStock`, {
|
|
1393
1460
|
checkoutId: checkout.id,
|
|
@@ -1468,6 +1535,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
1468
1535
|
type: Injectable
|
|
1469
1536
|
}], ctorParameters: () => [{ type: AuthService }, { type: CheckoutService }, { type: i1$1.HttpClient }] });
|
|
1470
1537
|
|
|
1538
|
+
/* eslint-disable max-params */
|
|
1471
1539
|
class CartService {
|
|
1472
1540
|
constructor(servicesFacade, configurationFacade) {
|
|
1473
1541
|
this.servicesFacade = servicesFacade;
|
|
@@ -1483,11 +1551,21 @@ class CartService {
|
|
|
1483
1551
|
}), {}) || {};
|
|
1484
1552
|
this.checkoutUrl = this.configurationFacade.getCheckoutUrl();
|
|
1485
1553
|
}
|
|
1486
|
-
addItem(item, quantity = 1) {
|
|
1554
|
+
addItem(item, quantity = 1, recurrence = false, recurrenceCycle = null) {
|
|
1487
1555
|
return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutAddItemToCart`, {
|
|
1488
1556
|
checkoutId: checkout.id,
|
|
1489
1557
|
productId: item.id,
|
|
1490
1558
|
quantity,
|
|
1559
|
+
recurrence,
|
|
1560
|
+
recurrenceCycle,
|
|
1561
|
+
})), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1562
|
+
}
|
|
1563
|
+
updateItemRecurrence(item, recurrence = false, recurrenceCycle = null) {
|
|
1564
|
+
return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutUpdateItemRecurrence`, {
|
|
1565
|
+
checkoutId: checkout.id,
|
|
1566
|
+
productId: item.id,
|
|
1567
|
+
recurrence,
|
|
1568
|
+
recurrenceCycle,
|
|
1491
1569
|
})), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1492
1570
|
}
|
|
1493
1571
|
decreaseItem(item) {
|
|
@@ -2696,315 +2774,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
2696
2774
|
args: [DEFAULT_SHOP]
|
|
2697
2775
|
}] }] });
|
|
2698
2776
|
|
|
2699
|
-
class CouponRepositoriesFacade {
|
|
2700
|
-
constructor(couponRepository, orderRepository, categoryRepository) {
|
|
2701
|
-
this.couponRepository = couponRepository;
|
|
2702
|
-
this.orderRepository = orderRepository;
|
|
2703
|
-
this.categoryRepository = categoryRepository;
|
|
2704
|
-
}
|
|
2705
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponRepositoriesFacade, deps: [{ token: 'CouponRepository' }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2706
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponRepositoriesFacade }); }
|
|
2707
|
-
}
|
|
2708
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
|
|
2709
|
-
type: Injectable
|
|
2710
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
2711
|
-
type: Inject,
|
|
2712
|
-
args: ['CouponRepository']
|
|
2713
|
-
}] }, { type: undefined, decorators: [{
|
|
2714
|
-
type: Inject,
|
|
2715
|
-
args: ['OrderRepository']
|
|
2716
|
-
}] }, { type: undefined, decorators: [{
|
|
2717
|
-
type: Inject,
|
|
2718
|
-
args: ['CategoryRepository']
|
|
2719
|
-
}] }] });
|
|
2720
|
-
|
|
2721
|
-
class CouponService {
|
|
2722
|
-
constructor(repositoriesFacade, configurationFacade) {
|
|
2723
|
-
this.repositoriesFacade = repositoriesFacade;
|
|
2724
|
-
this.configurationFacade = configurationFacade;
|
|
2725
|
-
this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
|
|
2726
|
-
}
|
|
2727
|
-
checkCoupon(params) {
|
|
2728
|
-
const { nickname, checkoutType, checkout, plan } = params;
|
|
2729
|
-
return from(this.repositoriesFacade.couponRepository
|
|
2730
|
-
.find({
|
|
2731
|
-
filters: {
|
|
2732
|
-
nickname: { operator: Where.EQUALS, value: nickname },
|
|
2733
|
-
active: { operator: Where.EQUALS, value: true },
|
|
2734
|
-
},
|
|
2735
|
-
})
|
|
2736
|
-
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation({ coupon: couponValid, checkoutType, checkout, plan })), map((couponValidated) => couponValidated));
|
|
2737
|
-
}
|
|
2738
|
-
async couponValidation(coupon, checkoutType) {
|
|
2739
|
-
if (!coupon)
|
|
2740
|
-
throw 'Cupom inválido.';
|
|
2741
|
-
if (coupon?.beginAt && coupon?.beginAt.getTime() > new Date().getTime())
|
|
2742
|
-
throw 'Cupom inválido.';
|
|
2743
|
-
if (coupon?.expiresIn && (coupon?.expiresIn).getTime() < new Date().getTime())
|
|
2744
|
-
throw 'Cupom expirado.';
|
|
2745
|
-
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.configurationFacade.defaultShop;
|
|
2746
|
-
if (!isInShop)
|
|
2747
|
-
throw 'Cupom inválido para loja.';
|
|
2748
|
-
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
2749
|
-
if (!isCheckoutType)
|
|
2750
|
-
throw 'Cupom inválido. Erro de checkout.';
|
|
2751
|
-
return coupon;
|
|
2752
|
-
}
|
|
2753
|
-
async couponRulesValidation(params) {
|
|
2754
|
-
const { coupon, checkoutType, checkout, plan } = params;
|
|
2755
|
-
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
2756
|
-
return this.validateSubscriptionCoupon(coupon, plan);
|
|
2757
|
-
}
|
|
2758
|
-
return this.validateEcommerceCoupon(coupon, checkoutType, checkout);
|
|
2759
|
-
}
|
|
2760
|
-
validateSubscriptionCoupon(coupon, plan) {
|
|
2761
|
-
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase()) {
|
|
2762
|
-
throw 'Cupom inválido para sua assinatura.';
|
|
2763
|
-
}
|
|
2764
|
-
return coupon;
|
|
2765
|
-
}
|
|
2766
|
-
async validateEcommerceCoupon(coupon, checkoutType, checkout) {
|
|
2767
|
-
this.validateUserEligibility(coupon, checkout?.user);
|
|
2768
|
-
await this.validateUsageLimits(coupon, checkoutType, checkout);
|
|
2769
|
-
await this.validateProductEligibility(coupon, checkout);
|
|
2770
|
-
return coupon;
|
|
2771
|
-
}
|
|
2772
|
-
validateUserEligibility(coupon, user) {
|
|
2773
|
-
const validUser = this.coupomUserValidation(coupon, user);
|
|
2774
|
-
if (!validUser)
|
|
2775
|
-
throw 'Usuário não elegível.';
|
|
2776
|
-
}
|
|
2777
|
-
async validateUsageLimits(coupon, checkoutType, checkout) {
|
|
2778
|
-
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
2779
|
-
if (couponUseLimits.firstOrder) {
|
|
2780
|
-
await this.validateFirstOrderLimit(checkout.user.email);
|
|
2781
|
-
}
|
|
2782
|
-
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
2783
|
-
await this.validateCouponUsageLimits(coupon, couponUseLimits, checkout.user.email);
|
|
2784
|
-
}
|
|
2785
|
-
}
|
|
2786
|
-
async validateFirstOrderLimit(userEmail) {
|
|
2787
|
-
const ordersUser = await this.getOrdersFromUser(userEmail.toLocaleLowerCase());
|
|
2788
|
-
if (ordersUser.length >= 1)
|
|
2789
|
-
throw 'Limite de uso atingido';
|
|
2790
|
-
}
|
|
2791
|
-
async validateCouponUsageLimits(coupon, couponUseLimits, userEmail) {
|
|
2792
|
-
const ordersCoupon = await this.getOrdersWithCoupon(coupon);
|
|
2793
|
-
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total) {
|
|
2794
|
-
throw 'Limite de uso atingido.';
|
|
2795
|
-
}
|
|
2796
|
-
if (couponUseLimits.limitedPerUser) {
|
|
2797
|
-
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, userEmail);
|
|
2798
|
-
if (ordersWithUser > 0)
|
|
2799
|
-
throw 'Limite de uso por usuário atingido.';
|
|
2800
|
-
}
|
|
2801
|
-
}
|
|
2802
|
-
async validateProductEligibility(coupon, checkout) {
|
|
2803
|
-
const hasProductCategories = await this.hasProductCategories(coupon, checkout);
|
|
2804
|
-
if (!hasProductCategories)
|
|
2805
|
-
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
2806
|
-
const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
|
|
2807
|
-
if (!hasMinSubTotal) {
|
|
2808
|
-
this.throwMinSubTotalError(coupon);
|
|
2809
|
-
}
|
|
2810
|
-
}
|
|
2811
|
-
throwMinSubTotalError(coupon) {
|
|
2812
|
-
const formattedValue = Intl.NumberFormat('pt-BR', {
|
|
2813
|
-
style: 'currency',
|
|
2814
|
-
currency: 'BRL',
|
|
2815
|
-
}).format(coupon.minSubTotalValue);
|
|
2816
|
-
if (coupon.productsCategories?.length) {
|
|
2817
|
-
throw `Valor mínimo de ${formattedValue} não atingido na(s) categoria(s) elegíveis para o desconto.`;
|
|
2818
|
-
}
|
|
2819
|
-
throw `Valor mínimo de ${formattedValue} não atingido.`;
|
|
2820
|
-
}
|
|
2821
|
-
calcDiscountSubscription(coupon, checkout) {
|
|
2822
|
-
let discount = 0;
|
|
2823
|
-
if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
|
|
2824
|
-
discount = coupon.discount.subscription.value;
|
|
2825
|
-
else
|
|
2826
|
-
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
|
|
2827
|
-
return of(discount);
|
|
2828
|
-
}
|
|
2829
|
-
async hasMinSubTotal(coupon, checkout) {
|
|
2830
|
-
if (!coupon.minSubTotalValue)
|
|
2831
|
-
return true;
|
|
2832
|
-
const lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
2833
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
2834
|
-
if (coupon.minSubTotalValue <= subTotal)
|
|
2835
|
-
return true;
|
|
2836
|
-
return false;
|
|
2837
|
-
}
|
|
2838
|
-
async hasProductCategories(coupon, checkout) {
|
|
2839
|
-
if (!coupon.productsCategories?.length) {
|
|
2840
|
-
return true;
|
|
2841
|
-
}
|
|
2842
|
-
const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
|
|
2843
|
-
const hasCategories = checkout.lineItems?.filter((item) => {
|
|
2844
|
-
if (item.isGift)
|
|
2845
|
-
return false;
|
|
2846
|
-
if (!item.categories?.length)
|
|
2847
|
-
return true;
|
|
2848
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2849
|
-
});
|
|
2850
|
-
return hasCategories?.length ? true : false;
|
|
2851
|
-
}
|
|
2852
|
-
coupomUserValidation(coupon, user) {
|
|
2853
|
-
if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
|
|
2854
|
-
return true;
|
|
2855
|
-
const userTypes = [];
|
|
2856
|
-
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
|
|
2857
|
-
this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
|
|
2858
|
-
userTypes.push(Exclusivities.COLLABORATORS);
|
|
2859
|
-
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
|
|
2860
|
-
coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
|
|
2861
|
-
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
2862
|
-
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
2863
|
-
user.isSubscriber &&
|
|
2864
|
-
user.subscriptionPlan != '')
|
|
2865
|
-
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
2866
|
-
if (user.isSubscriber &&
|
|
2867
|
-
user.subscriptionPlan == '' &&
|
|
2868
|
-
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
2869
|
-
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
2870
|
-
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
2871
|
-
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
2872
|
-
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
2873
|
-
}
|
|
2874
|
-
async getCouponCategoriesId(productsCategories) {
|
|
2875
|
-
const couponCategories = [];
|
|
2876
|
-
for (let index = 0; index < productsCategories.length; index++) {
|
|
2877
|
-
const category = await this.repositoriesFacade.categoryRepository.get({
|
|
2878
|
-
id: productsCategories[index],
|
|
2879
|
-
});
|
|
2880
|
-
if (category) {
|
|
2881
|
-
const children = await this.repositoriesFacade.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
2882
|
-
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
return [...new Set(couponCategories)];
|
|
2886
|
-
}
|
|
2887
|
-
async getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
2888
|
-
let lineItensDiscount = [];
|
|
2889
|
-
const couponCategories = await this.getCouponCategoriesId(productsCategories);
|
|
2890
|
-
if (productsCategories?.length) {
|
|
2891
|
-
lineItensDiscount = checkout.lineItems?.filter((item) => {
|
|
2892
|
-
if (item.isGift)
|
|
2893
|
-
return false;
|
|
2894
|
-
if (item.categories?.length) {
|
|
2895
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2896
|
-
}
|
|
2897
|
-
return true;
|
|
2898
|
-
});
|
|
2899
|
-
}
|
|
2900
|
-
else {
|
|
2901
|
-
lineItensDiscount = checkout.lineItems.filter((item) => !item.isGift);
|
|
2902
|
-
}
|
|
2903
|
-
return lineItensDiscount;
|
|
2904
|
-
}
|
|
2905
|
-
calcCheckoutSubtotal(lineItens, user) {
|
|
2906
|
-
return (lineItens
|
|
2907
|
-
?.filter((item) => !item.isGift)
|
|
2908
|
-
.reduce((acc, curr) => user?.isSubscriber && curr.price?.subscriberPrice
|
|
2909
|
-
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
2910
|
-
: acc + curr.pricePaid * curr.quantity, 0) || 0);
|
|
2911
|
-
}
|
|
2912
|
-
async getOrdersWithCoupon(coupon) {
|
|
2913
|
-
return await this.repositoriesFacade.orderRepository
|
|
2914
|
-
.find({
|
|
2915
|
-
filters: {
|
|
2916
|
-
coupon: { id: coupon.id },
|
|
2917
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2918
|
-
},
|
|
2919
|
-
})
|
|
2920
|
-
.then((result) => result.data);
|
|
2921
|
-
}
|
|
2922
|
-
async getOrdersFromUser(email) {
|
|
2923
|
-
return await this.repositoriesFacade.orderRepository
|
|
2924
|
-
.find({
|
|
2925
|
-
filters: {
|
|
2926
|
-
user: { email: { operator: Where.EQUALS, value: email } },
|
|
2927
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2928
|
-
},
|
|
2929
|
-
})
|
|
2930
|
-
.then((result) => result.data);
|
|
2931
|
-
}
|
|
2932
|
-
countOrdersWithUser(orders, email) {
|
|
2933
|
-
return orders.filter((o) => o.user.email == email).length;
|
|
2934
|
-
}
|
|
2935
|
-
getCouponUseLimits(coupon, checkoutType, user) {
|
|
2936
|
-
let couponUseLimits;
|
|
2937
|
-
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
2938
|
-
if (coupon.exclusivityType.length === 1 &&
|
|
2939
|
-
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
2940
|
-
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
2941
|
-
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
2942
|
-
else
|
|
2943
|
-
couponUseLimits = user?.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
2944
|
-
}
|
|
2945
|
-
else {
|
|
2946
|
-
couponUseLimits = coupon.useLimits.subscription;
|
|
2947
|
-
}
|
|
2948
|
-
return couponUseLimits;
|
|
2949
|
-
}
|
|
2950
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponService, deps: [{ token: CouponRepositoriesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2951
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponService, providedIn: 'root' }); }
|
|
2952
|
-
}
|
|
2953
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponService, decorators: [{
|
|
2954
|
-
type: Injectable,
|
|
2955
|
-
args: [{
|
|
2956
|
-
providedIn: 'root',
|
|
2957
|
-
}]
|
|
2958
|
-
}], ctorParameters: () => [{ type: CouponRepositoriesFacade }, { type: ConfigurationFacade }] });
|
|
2959
|
-
|
|
2960
|
-
class CheckoutSubscriptionService {
|
|
2961
|
-
constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
|
|
2962
|
-
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
2963
|
-
this.dataPersistence = dataPersistence;
|
|
2964
|
-
this.couponService = couponService;
|
|
2965
|
-
}
|
|
2966
|
-
getCheckoutSubscription(checkoutData) {
|
|
2967
|
-
return this.dataPersistence
|
|
2968
|
-
.get('checkoutSubscriptionId')
|
|
2969
|
-
.pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
|
|
2970
|
-
}
|
|
2971
|
-
clearCheckoutSubscriptionFromSession() {
|
|
2972
|
-
return this.dataPersistence.remove('checkoutSubscriptionId');
|
|
2973
|
-
}
|
|
2974
|
-
checkCoupon(nickname, _userEmail) {
|
|
2975
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
2976
|
-
.checkCoupon({
|
|
2977
|
-
nickname,
|
|
2978
|
-
checkoutType: CheckoutTypes.SUBSCRIPTION,
|
|
2979
|
-
checkout,
|
|
2980
|
-
plan: checkout.subscriptionPlan.name,
|
|
2981
|
-
})
|
|
2982
|
-
.pipe()));
|
|
2983
|
-
}
|
|
2984
|
-
calcDiscountSubscription(coupon) {
|
|
2985
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
2986
|
-
}
|
|
2987
|
-
async createCheckoutSubscription(checkoutData) {
|
|
2988
|
-
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
2989
|
-
createdAt: new Date(),
|
|
2990
|
-
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
2991
|
-
});
|
|
2992
|
-
await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
|
|
2993
|
-
return checkout;
|
|
2994
|
-
}
|
|
2995
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: PERSISTENCE_PROVIDER }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2996
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CheckoutSubscriptionService }); }
|
|
2997
|
-
}
|
|
2998
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
2999
|
-
type: Injectable
|
|
3000
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
3001
|
-
type: Inject,
|
|
3002
|
-
args: ['CheckoutSubscriptionRepository']
|
|
3003
|
-
}] }, { type: undefined, decorators: [{
|
|
3004
|
-
type: Inject,
|
|
3005
|
-
args: [PERSISTENCE_PROVIDER]
|
|
3006
|
-
}] }, { type: CouponService }] });
|
|
3007
|
-
|
|
3008
2777
|
class UtilHelper {
|
|
3009
2778
|
static createSlug(name) {
|
|
3010
2779
|
return name
|
|
@@ -3325,27 +3094,20 @@ class OrderRecurrenceService {
|
|
|
3325
3094
|
});
|
|
3326
3095
|
}
|
|
3327
3096
|
enableOrDisableRecurrenceOrder(recurrenceId, active) {
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
active,
|
|
3331
|
-
});
|
|
3097
|
+
const payload = { recurrenceId, active };
|
|
3098
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/enableOrDisableShoppingRecurrence`, payload);
|
|
3332
3099
|
}
|
|
3333
3100
|
skipRecurrenceOrder(recurrenceEditionId) {
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
});
|
|
3101
|
+
const payload = { recurrenceEditionId };
|
|
3102
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/skipShoppingRecurrenceEdition`, payload);
|
|
3337
3103
|
}
|
|
3338
3104
|
updateFrequency(recurrenceId, frequency) {
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
frequency,
|
|
3342
|
-
});
|
|
3105
|
+
const payload = { recurrenceId, frequency };
|
|
3106
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/updateShoppingRecurrenceFrequency`, payload);
|
|
3343
3107
|
}
|
|
3344
3108
|
updateLineItems(recurrenceId, lineItems) {
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
lineItems,
|
|
3348
|
-
});
|
|
3109
|
+
const payload = { recurrenceId, lineItems };
|
|
3110
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/updateShoppingRecurrenceLineItems`, payload);
|
|
3349
3111
|
}
|
|
3350
3112
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: OrderRecurrenceService, deps: [{ token: 'ShoppingRecurrenceRepository' }, { token: DEFAULT_SHOP }, { token: CheckoutDependenciesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3351
3113
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: OrderRecurrenceService }); }
|
|
@@ -3382,6 +3144,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
3382
3144
|
args: ['OrderRepository']
|
|
3383
3145
|
}] }] });
|
|
3384
3146
|
|
|
3147
|
+
class CouponRepositoriesFacade {
|
|
3148
|
+
constructor(couponRepository, orderRepository, categoryRepository) {
|
|
3149
|
+
this.couponRepository = couponRepository;
|
|
3150
|
+
this.orderRepository = orderRepository;
|
|
3151
|
+
this.categoryRepository = categoryRepository;
|
|
3152
|
+
}
|
|
3153
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponRepositoriesFacade, deps: [{ token: 'CouponRepository' }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3154
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponRepositoriesFacade }); }
|
|
3155
|
+
}
|
|
3156
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
|
|
3157
|
+
type: Injectable
|
|
3158
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
3159
|
+
type: Inject,
|
|
3160
|
+
args: ['CouponRepository']
|
|
3161
|
+
}] }, { type: undefined, decorators: [{
|
|
3162
|
+
type: Inject,
|
|
3163
|
+
args: ['OrderRepository']
|
|
3164
|
+
}] }, { type: undefined, decorators: [{
|
|
3165
|
+
type: Inject,
|
|
3166
|
+
args: ['CategoryRepository']
|
|
3167
|
+
}] }] });
|
|
3168
|
+
|
|
3385
3169
|
class AngularConnectModule {
|
|
3386
3170
|
static initializeApp(defaultShop, options, nameOrConfig) {
|
|
3387
3171
|
return {
|
|
@@ -3464,8 +3248,6 @@ class AngularConnectModule {
|
|
|
3464
3248
|
CatalogService,
|
|
3465
3249
|
CategoryService,
|
|
3466
3250
|
CheckoutService,
|
|
3467
|
-
CheckoutSubscriptionService,
|
|
3468
|
-
CouponService,
|
|
3469
3251
|
HomeShopService,
|
|
3470
3252
|
OrderService,
|
|
3471
3253
|
WishlistService,
|
|
@@ -3526,7 +3308,7 @@ class AngularConnectModule {
|
|
|
3526
3308
|
CouponRepositoriesFacade,
|
|
3527
3309
|
HomeShopRepositoriesFacade,
|
|
3528
3310
|
OrderProductReviewService,
|
|
3529
|
-
OrderRecurrenceService
|
|
3311
|
+
OrderRecurrenceService,
|
|
3530
3312
|
], imports: [AngularElasticSeachModule,
|
|
3531
3313
|
AngularVertexSeachModule,
|
|
3532
3314
|
AngularFirebaseAuthModule,
|
|
@@ -3579,8 +3361,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
3579
3361
|
CatalogService,
|
|
3580
3362
|
CategoryService,
|
|
3581
3363
|
CheckoutService,
|
|
3582
|
-
CheckoutSubscriptionService,
|
|
3583
|
-
CouponService,
|
|
3584
3364
|
HomeShopService,
|
|
3585
3365
|
OrderService,
|
|
3586
3366
|
WishlistService,
|
|
@@ -3641,7 +3421,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
3641
3421
|
CouponRepositoriesFacade,
|
|
3642
3422
|
HomeShopRepositoriesFacade,
|
|
3643
3423
|
OrderProductReviewService,
|
|
3644
|
-
OrderRecurrenceService
|
|
3424
|
+
OrderRecurrenceService,
|
|
3645
3425
|
],
|
|
3646
3426
|
}]
|
|
3647
3427
|
}] });
|
|
@@ -3650,5 +3430,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImpo
|
|
|
3650
3430
|
* Generated bundle index. Do not edit.
|
|
3651
3431
|
*/
|
|
3652
3432
|
|
|
3653
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService,
|
|
3433
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CookieDataPersistence, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderProductReviewService, OrderRecurrenceService, OrderService, ProductSorts, UtilHelper, WishlistService };
|
|
3654
3434
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|