@infrab4a/connect-angular 6.0.0-beta.37 → 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/services/index.mjs +1 -3
- package/fesm2022/infrab4a-connect-angular.mjs +40 -317
- package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/index.d.ts +0 -2
- 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, 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,
|
|
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) => {
|
|
@@ -2737,315 +2751,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2737
2751
|
args: [DEFAULT_SHOP]
|
|
2738
2752
|
}] }] });
|
|
2739
2753
|
|
|
2740
|
-
class CouponRepositoriesFacade {
|
|
2741
|
-
constructor(couponRepository, orderRepository, categoryRepository) {
|
|
2742
|
-
this.couponRepository = couponRepository;
|
|
2743
|
-
this.orderRepository = orderRepository;
|
|
2744
|
-
this.categoryRepository = categoryRepository;
|
|
2745
|
-
}
|
|
2746
|
-
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 }); }
|
|
2747
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponRepositoriesFacade }); }
|
|
2748
|
-
}
|
|
2749
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
|
|
2750
|
-
type: Injectable
|
|
2751
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
2752
|
-
type: Inject,
|
|
2753
|
-
args: ['CouponRepository']
|
|
2754
|
-
}] }, { type: undefined, decorators: [{
|
|
2755
|
-
type: Inject,
|
|
2756
|
-
args: ['OrderRepository']
|
|
2757
|
-
}] }, { type: undefined, decorators: [{
|
|
2758
|
-
type: Inject,
|
|
2759
|
-
args: ['CategoryRepository']
|
|
2760
|
-
}] }] });
|
|
2761
|
-
|
|
2762
|
-
class CouponService {
|
|
2763
|
-
constructor(repositoriesFacade, configurationFacade) {
|
|
2764
|
-
this.repositoriesFacade = repositoriesFacade;
|
|
2765
|
-
this.configurationFacade = configurationFacade;
|
|
2766
|
-
this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
|
|
2767
|
-
}
|
|
2768
|
-
checkCoupon(params) {
|
|
2769
|
-
const { nickname, checkoutType, checkout, plan } = params;
|
|
2770
|
-
return from(this.repositoriesFacade.couponRepository
|
|
2771
|
-
.find({
|
|
2772
|
-
filters: {
|
|
2773
|
-
nickname: { operator: Where.EQUALS, value: nickname },
|
|
2774
|
-
active: { operator: Where.EQUALS, value: true },
|
|
2775
|
-
},
|
|
2776
|
-
})
|
|
2777
|
-
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation({ coupon: couponValid, checkoutType, checkout, plan })), map((couponValidated) => couponValidated));
|
|
2778
|
-
}
|
|
2779
|
-
async couponValidation(coupon, checkoutType) {
|
|
2780
|
-
if (!coupon)
|
|
2781
|
-
throw 'Cupom inválido.';
|
|
2782
|
-
if (coupon?.beginAt && coupon?.beginAt.getTime() > new Date().getTime())
|
|
2783
|
-
throw 'Cupom inválido.';
|
|
2784
|
-
if (coupon?.expiresIn && (coupon?.expiresIn).getTime() < new Date().getTime())
|
|
2785
|
-
throw 'Cupom expirado.';
|
|
2786
|
-
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.configurationFacade.defaultShop;
|
|
2787
|
-
if (!isInShop)
|
|
2788
|
-
throw 'Cupom inválido para loja.';
|
|
2789
|
-
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
2790
|
-
if (!isCheckoutType)
|
|
2791
|
-
throw 'Cupom inválido. Erro de checkout.';
|
|
2792
|
-
return coupon;
|
|
2793
|
-
}
|
|
2794
|
-
async couponRulesValidation(params) {
|
|
2795
|
-
const { coupon, checkoutType, checkout, plan } = params;
|
|
2796
|
-
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
2797
|
-
return this.validateSubscriptionCoupon(coupon, plan);
|
|
2798
|
-
}
|
|
2799
|
-
return this.validateEcommerceCoupon(coupon, checkoutType, checkout);
|
|
2800
|
-
}
|
|
2801
|
-
validateSubscriptionCoupon(coupon, plan) {
|
|
2802
|
-
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase()) {
|
|
2803
|
-
throw 'Cupom inválido para sua assinatura.';
|
|
2804
|
-
}
|
|
2805
|
-
return coupon;
|
|
2806
|
-
}
|
|
2807
|
-
async validateEcommerceCoupon(coupon, checkoutType, checkout) {
|
|
2808
|
-
this.validateUserEligibility(coupon, checkout?.user);
|
|
2809
|
-
await this.validateUsageLimits(coupon, checkoutType, checkout);
|
|
2810
|
-
await this.validateProductEligibility(coupon, checkout);
|
|
2811
|
-
return coupon;
|
|
2812
|
-
}
|
|
2813
|
-
validateUserEligibility(coupon, user) {
|
|
2814
|
-
const validUser = this.coupomUserValidation(coupon, user);
|
|
2815
|
-
if (!validUser)
|
|
2816
|
-
throw 'Usuário não elegível.';
|
|
2817
|
-
}
|
|
2818
|
-
async validateUsageLimits(coupon, checkoutType, checkout) {
|
|
2819
|
-
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
2820
|
-
if (couponUseLimits.firstOrder) {
|
|
2821
|
-
await this.validateFirstOrderLimit(checkout.user.email);
|
|
2822
|
-
}
|
|
2823
|
-
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
2824
|
-
await this.validateCouponUsageLimits(coupon, couponUseLimits, checkout.user.email);
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
async validateFirstOrderLimit(userEmail) {
|
|
2828
|
-
const ordersUser = await this.getOrdersFromUser(userEmail.toLocaleLowerCase());
|
|
2829
|
-
if (ordersUser.length >= 1)
|
|
2830
|
-
throw 'Limite de uso atingido';
|
|
2831
|
-
}
|
|
2832
|
-
async validateCouponUsageLimits(coupon, couponUseLimits, userEmail) {
|
|
2833
|
-
const ordersCoupon = await this.getOrdersWithCoupon(coupon);
|
|
2834
|
-
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total) {
|
|
2835
|
-
throw 'Limite de uso atingido.';
|
|
2836
|
-
}
|
|
2837
|
-
if (couponUseLimits.limitedPerUser) {
|
|
2838
|
-
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, userEmail);
|
|
2839
|
-
if (ordersWithUser > 0)
|
|
2840
|
-
throw 'Limite de uso por usuário atingido.';
|
|
2841
|
-
}
|
|
2842
|
-
}
|
|
2843
|
-
async validateProductEligibility(coupon, checkout) {
|
|
2844
|
-
const hasProductCategories = await this.hasProductCategories(coupon, checkout);
|
|
2845
|
-
if (!hasProductCategories)
|
|
2846
|
-
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
2847
|
-
const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
|
|
2848
|
-
if (!hasMinSubTotal) {
|
|
2849
|
-
this.throwMinSubTotalError(coupon);
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
throwMinSubTotalError(coupon) {
|
|
2853
|
-
const formattedValue = Intl.NumberFormat('pt-BR', {
|
|
2854
|
-
style: 'currency',
|
|
2855
|
-
currency: 'BRL',
|
|
2856
|
-
}).format(coupon.minSubTotalValue);
|
|
2857
|
-
if (coupon.productsCategories?.length) {
|
|
2858
|
-
throw `Valor mínimo de ${formattedValue} não atingido na(s) categoria(s) elegíveis para o desconto.`;
|
|
2859
|
-
}
|
|
2860
|
-
throw `Valor mínimo de ${formattedValue} não atingido.`;
|
|
2861
|
-
}
|
|
2862
|
-
calcDiscountSubscription(coupon, checkout) {
|
|
2863
|
-
let discount = 0;
|
|
2864
|
-
if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
|
|
2865
|
-
discount = coupon.discount.subscription.value;
|
|
2866
|
-
else
|
|
2867
|
-
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
|
|
2868
|
-
return of(discount);
|
|
2869
|
-
}
|
|
2870
|
-
async hasMinSubTotal(coupon, checkout) {
|
|
2871
|
-
if (!coupon.minSubTotalValue)
|
|
2872
|
-
return true;
|
|
2873
|
-
const lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
2874
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
2875
|
-
if (coupon.minSubTotalValue <= subTotal)
|
|
2876
|
-
return true;
|
|
2877
|
-
return false;
|
|
2878
|
-
}
|
|
2879
|
-
async hasProductCategories(coupon, checkout) {
|
|
2880
|
-
if (!coupon.productsCategories?.length) {
|
|
2881
|
-
return true;
|
|
2882
|
-
}
|
|
2883
|
-
const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
|
|
2884
|
-
const hasCategories = checkout.lineItems?.filter((item) => {
|
|
2885
|
-
if (item.isGift)
|
|
2886
|
-
return false;
|
|
2887
|
-
if (!item.categories?.length)
|
|
2888
|
-
return true;
|
|
2889
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2890
|
-
});
|
|
2891
|
-
return hasCategories?.length ? true : false;
|
|
2892
|
-
}
|
|
2893
|
-
coupomUserValidation(coupon, user) {
|
|
2894
|
-
if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
|
|
2895
|
-
return true;
|
|
2896
|
-
const userTypes = [];
|
|
2897
|
-
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
|
|
2898
|
-
this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
|
|
2899
|
-
userTypes.push(Exclusivities.COLLABORATORS);
|
|
2900
|
-
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
|
|
2901
|
-
coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
|
|
2902
|
-
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
2903
|
-
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
2904
|
-
user.isSubscriber &&
|
|
2905
|
-
user.subscriptionPlan != '')
|
|
2906
|
-
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
2907
|
-
if (user.isSubscriber &&
|
|
2908
|
-
user.subscriptionPlan == '' &&
|
|
2909
|
-
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
2910
|
-
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
2911
|
-
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
2912
|
-
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
2913
|
-
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
2914
|
-
}
|
|
2915
|
-
async getCouponCategoriesId(productsCategories) {
|
|
2916
|
-
const couponCategories = [];
|
|
2917
|
-
for (let index = 0; index < productsCategories.length; index++) {
|
|
2918
|
-
const category = await this.repositoriesFacade.categoryRepository.get({
|
|
2919
|
-
id: productsCategories[index],
|
|
2920
|
-
});
|
|
2921
|
-
if (category) {
|
|
2922
|
-
const children = await this.repositoriesFacade.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
2923
|
-
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
2924
|
-
}
|
|
2925
|
-
}
|
|
2926
|
-
return [...new Set(couponCategories)];
|
|
2927
|
-
}
|
|
2928
|
-
async getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
2929
|
-
let lineItensDiscount = [];
|
|
2930
|
-
const couponCategories = await this.getCouponCategoriesId(productsCategories);
|
|
2931
|
-
if (productsCategories?.length) {
|
|
2932
|
-
lineItensDiscount = checkout.lineItems?.filter((item) => {
|
|
2933
|
-
if (item.isGift)
|
|
2934
|
-
return false;
|
|
2935
|
-
if (item.categories?.length) {
|
|
2936
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2937
|
-
}
|
|
2938
|
-
return true;
|
|
2939
|
-
});
|
|
2940
|
-
}
|
|
2941
|
-
else {
|
|
2942
|
-
lineItensDiscount = checkout.lineItems.filter((item) => !item.isGift);
|
|
2943
|
-
}
|
|
2944
|
-
return lineItensDiscount;
|
|
2945
|
-
}
|
|
2946
|
-
calcCheckoutSubtotal(lineItens, user) {
|
|
2947
|
-
return (lineItens
|
|
2948
|
-
?.filter((item) => !item.isGift)
|
|
2949
|
-
.reduce((acc, curr) => user?.isSubscriber && curr.price?.subscriberPrice
|
|
2950
|
-
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
2951
|
-
: acc + curr.pricePaid * curr.quantity, 0) || 0);
|
|
2952
|
-
}
|
|
2953
|
-
async getOrdersWithCoupon(coupon) {
|
|
2954
|
-
return await this.repositoriesFacade.orderRepository
|
|
2955
|
-
.find({
|
|
2956
|
-
filters: {
|
|
2957
|
-
coupon: { id: coupon.id },
|
|
2958
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2959
|
-
},
|
|
2960
|
-
})
|
|
2961
|
-
.then((result) => result.data);
|
|
2962
|
-
}
|
|
2963
|
-
async getOrdersFromUser(email) {
|
|
2964
|
-
return await this.repositoriesFacade.orderRepository
|
|
2965
|
-
.find({
|
|
2966
|
-
filters: {
|
|
2967
|
-
user: { email: { operator: Where.EQUALS, value: email } },
|
|
2968
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2969
|
-
},
|
|
2970
|
-
})
|
|
2971
|
-
.then((result) => result.data);
|
|
2972
|
-
}
|
|
2973
|
-
countOrdersWithUser(orders, email) {
|
|
2974
|
-
return orders.filter((o) => o.user.email == email).length;
|
|
2975
|
-
}
|
|
2976
|
-
getCouponUseLimits(coupon, checkoutType, user) {
|
|
2977
|
-
let couponUseLimits;
|
|
2978
|
-
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
2979
|
-
if (coupon.exclusivityType.length === 1 &&
|
|
2980
|
-
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
2981
|
-
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
2982
|
-
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
2983
|
-
else
|
|
2984
|
-
couponUseLimits = user?.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
2985
|
-
}
|
|
2986
|
-
else {
|
|
2987
|
-
couponUseLimits = coupon.useLimits.subscription;
|
|
2988
|
-
}
|
|
2989
|
-
return couponUseLimits;
|
|
2990
|
-
}
|
|
2991
|
-
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 }); }
|
|
2992
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, providedIn: 'root' }); }
|
|
2993
|
-
}
|
|
2994
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, decorators: [{
|
|
2995
|
-
type: Injectable,
|
|
2996
|
-
args: [{
|
|
2997
|
-
providedIn: 'root',
|
|
2998
|
-
}]
|
|
2999
|
-
}], ctorParameters: () => [{ type: CouponRepositoriesFacade }, { type: ConfigurationFacade }] });
|
|
3000
|
-
|
|
3001
|
-
class CheckoutSubscriptionService {
|
|
3002
|
-
constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
|
|
3003
|
-
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
3004
|
-
this.dataPersistence = dataPersistence;
|
|
3005
|
-
this.couponService = couponService;
|
|
3006
|
-
}
|
|
3007
|
-
getCheckoutSubscription(checkoutData) {
|
|
3008
|
-
return this.dataPersistence
|
|
3009
|
-
.get('checkoutSubscriptionId')
|
|
3010
|
-
.pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
|
|
3011
|
-
}
|
|
3012
|
-
clearCheckoutSubscriptionFromSession() {
|
|
3013
|
-
return this.dataPersistence.remove('checkoutSubscriptionId');
|
|
3014
|
-
}
|
|
3015
|
-
checkCoupon(nickname, _userEmail) {
|
|
3016
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
3017
|
-
.checkCoupon({
|
|
3018
|
-
nickname,
|
|
3019
|
-
checkoutType: CheckoutTypes.SUBSCRIPTION,
|
|
3020
|
-
checkout,
|
|
3021
|
-
plan: checkout.subscriptionPlan.name,
|
|
3022
|
-
})
|
|
3023
|
-
.pipe()));
|
|
3024
|
-
}
|
|
3025
|
-
calcDiscountSubscription(coupon) {
|
|
3026
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
3027
|
-
}
|
|
3028
|
-
async createCheckoutSubscription(checkoutData) {
|
|
3029
|
-
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
3030
|
-
createdAt: new Date(),
|
|
3031
|
-
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
3032
|
-
});
|
|
3033
|
-
await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
|
|
3034
|
-
return checkout;
|
|
3035
|
-
}
|
|
3036
|
-
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 }); }
|
|
3037
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService }); }
|
|
3038
|
-
}
|
|
3039
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
3040
|
-
type: Injectable
|
|
3041
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
3042
|
-
type: Inject,
|
|
3043
|
-
args: ['CheckoutSubscriptionRepository']
|
|
3044
|
-
}] }, { type: undefined, decorators: [{
|
|
3045
|
-
type: Inject,
|
|
3046
|
-
args: [PERSISTENCE_PROVIDER]
|
|
3047
|
-
}] }, { type: CouponService }] });
|
|
3048
|
-
|
|
3049
2754
|
class UtilHelper {
|
|
3050
2755
|
static createSlug(name) {
|
|
3051
2756
|
return name
|
|
@@ -3416,6 +3121,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
3416
3121
|
args: ['OrderRepository']
|
|
3417
3122
|
}] }] });
|
|
3418
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
|
+
|
|
3419
3146
|
class AngularConnectModule {
|
|
3420
3147
|
static initializeApp(defaultShop, options, nameOrConfig) {
|
|
3421
3148
|
return {
|
|
@@ -3468,8 +3195,6 @@ class AngularConnectModule {
|
|
|
3468
3195
|
CatalogService,
|
|
3469
3196
|
CategoryService,
|
|
3470
3197
|
CheckoutService,
|
|
3471
|
-
CheckoutSubscriptionService,
|
|
3472
|
-
CouponService,
|
|
3473
3198
|
HomeShopService,
|
|
3474
3199
|
OrderService,
|
|
3475
3200
|
WishlistService,
|
|
@@ -3530,7 +3255,7 @@ class AngularConnectModule {
|
|
|
3530
3255
|
CouponRepositoriesFacade,
|
|
3531
3256
|
HomeShopRepositoriesFacade,
|
|
3532
3257
|
OrderProductReviewService,
|
|
3533
|
-
OrderRecurrenceService
|
|
3258
|
+
OrderRecurrenceService,
|
|
3534
3259
|
], imports: [provideFirebaseApp((injector) => {
|
|
3535
3260
|
const appName = injector.get(FIREBASE_APP_NAME);
|
|
3536
3261
|
try {
|
|
@@ -3613,8 +3338,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
3613
3338
|
CatalogService,
|
|
3614
3339
|
CategoryService,
|
|
3615
3340
|
CheckoutService,
|
|
3616
|
-
CheckoutSubscriptionService,
|
|
3617
|
-
CouponService,
|
|
3618
3341
|
HomeShopService,
|
|
3619
3342
|
OrderService,
|
|
3620
3343
|
WishlistService,
|
|
@@ -3675,7 +3398,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
3675
3398
|
CouponRepositoriesFacade,
|
|
3676
3399
|
HomeShopRepositoriesFacade,
|
|
3677
3400
|
OrderProductReviewService,
|
|
3678
|
-
OrderRecurrenceService
|
|
3401
|
+
OrderRecurrenceService,
|
|
3679
3402
|
],
|
|
3680
3403
|
}]
|
|
3681
3404
|
}] });
|
|
@@ -3684,5 +3407,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
3684
3407
|
* Generated bundle index. Do not edit.
|
|
3685
3408
|
*/
|
|
3686
3409
|
|
|
3687
|
-
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 };
|
|
3688
3411
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|