@infrab4a/connect-angular 5.8.13 → 5.8.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/angular-connect.module.mjs +4 -8
- package/esm2020/services/index.mjs +1 -3
- package/fesm2015/infrab4a-connect-angular.mjs +28 -352
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +26 -317
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/index.d.ts +0 -2
- package/esm2020/services/checkout-subscription.service.mjs +0 -55
- package/esm2020/services/coupon/types/coupon-params.type.mjs +0 -2
- package/esm2020/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, 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';
|
|
@@ -2737,315 +2737,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2737
2737
|
args: [DEFAULT_SHOP]
|
|
2738
2738
|
}] }]; } });
|
|
2739
2739
|
|
|
2740
|
-
class CouponRepositoriesFacade {
|
|
2741
|
-
constructor(couponRepository, orderRepository, categoryRepository) {
|
|
2742
|
-
this.couponRepository = couponRepository;
|
|
2743
|
-
this.orderRepository = orderRepository;
|
|
2744
|
-
this.categoryRepository = categoryRepository;
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
|
-
CouponRepositoriesFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade, deps: [{ token: 'CouponRepository' }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2748
|
-
CouponRepositoriesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade });
|
|
2749
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
|
|
2750
|
-
type: Injectable
|
|
2751
|
-
}], ctorParameters: function () { return [{ 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
|
-
}
|
|
2992
|
-
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: CouponRepositoriesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2993
|
-
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
2994
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
2995
|
-
type: Injectable,
|
|
2996
|
-
args: [{
|
|
2997
|
-
providedIn: 'root',
|
|
2998
|
-
}]
|
|
2999
|
-
}], ctorParameters: function () { return [{ 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
|
-
}
|
|
3037
|
-
CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: PERSISTENCE_PROVIDER }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3038
|
-
CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
|
|
3039
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
3040
|
-
type: Injectable
|
|
3041
|
-
}], ctorParameters: function () { return [{ 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
2740
|
class UtilHelper {
|
|
3050
2741
|
static createSlug(name) {
|
|
3051
2742
|
return name
|
|
@@ -3416,6 +3107,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
3416
3107
|
args: ['OrderRepository']
|
|
3417
3108
|
}] }]; } });
|
|
3418
3109
|
|
|
3110
|
+
class CouponRepositoriesFacade {
|
|
3111
|
+
constructor(couponRepository, orderRepository, categoryRepository) {
|
|
3112
|
+
this.couponRepository = couponRepository;
|
|
3113
|
+
this.orderRepository = orderRepository;
|
|
3114
|
+
this.categoryRepository = categoryRepository;
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
CouponRepositoriesFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade, deps: [{ token: 'CouponRepository' }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3118
|
+
CouponRepositoriesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade });
|
|
3119
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
|
|
3120
|
+
type: Injectable
|
|
3121
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
3122
|
+
type: Inject,
|
|
3123
|
+
args: ['CouponRepository']
|
|
3124
|
+
}] }, { type: undefined, decorators: [{
|
|
3125
|
+
type: Inject,
|
|
3126
|
+
args: ['OrderRepository']
|
|
3127
|
+
}] }, { type: undefined, decorators: [{
|
|
3128
|
+
type: Inject,
|
|
3129
|
+
args: ['CategoryRepository']
|
|
3130
|
+
}] }]; } });
|
|
3131
|
+
|
|
3419
3132
|
class AngularConnectModule {
|
|
3420
3133
|
static initializeApp(defaultShop, options, nameOrConfig) {
|
|
3421
3134
|
return {
|
|
@@ -3469,8 +3182,6 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
|
|
|
3469
3182
|
CatalogService,
|
|
3470
3183
|
CategoryService,
|
|
3471
3184
|
CheckoutService,
|
|
3472
|
-
CheckoutSubscriptionService,
|
|
3473
|
-
CouponService,
|
|
3474
3185
|
HomeShopService,
|
|
3475
3186
|
OrderService,
|
|
3476
3187
|
WishlistService,
|
|
@@ -3531,7 +3242,7 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
|
|
|
3531
3242
|
CouponRepositoriesFacade,
|
|
3532
3243
|
HomeShopRepositoriesFacade,
|
|
3533
3244
|
OrderProductReviewService,
|
|
3534
|
-
OrderRecurrenceService
|
|
3245
|
+
OrderRecurrenceService,
|
|
3535
3246
|
], imports: [provideFirebaseApp((injector) => {
|
|
3536
3247
|
const appName = injector.get(FIREBASE_APP_NAME);
|
|
3537
3248
|
try {
|
|
@@ -3613,8 +3324,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
3613
3324
|
CatalogService,
|
|
3614
3325
|
CategoryService,
|
|
3615
3326
|
CheckoutService,
|
|
3616
|
-
CheckoutSubscriptionService,
|
|
3617
|
-
CouponService,
|
|
3618
3327
|
HomeShopService,
|
|
3619
3328
|
OrderService,
|
|
3620
3329
|
WishlistService,
|
|
@@ -3675,7 +3384,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
3675
3384
|
CouponRepositoriesFacade,
|
|
3676
3385
|
HomeShopRepositoriesFacade,
|
|
3677
3386
|
OrderProductReviewService,
|
|
3678
|
-
OrderRecurrenceService
|
|
3387
|
+
OrderRecurrenceService,
|
|
3679
3388
|
],
|
|
3680
3389
|
}]
|
|
3681
3390
|
}] });
|
|
@@ -3684,5 +3393,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
3684
3393
|
* Generated bundle index. Do not edit.
|
|
3685
3394
|
*/
|
|
3686
3395
|
|
|
3687
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService,
|
|
3396
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CookieDataPersistence, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderProductReviewService, OrderRecurrenceService, OrderService, ProductSorts, UtilHelper, WishlistService };
|
|
3688
3397
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|