@infrab4a/connect-angular 3.10.0-beta.0 → 3.10.0-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.
- package/bundles/infrab4a-connect-angular.umd.js +187 -101
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +32 -12
- package/esm2015/services/coupon.service.js +37 -19
- package/fesm2015/infrab4a-connect-angular.js +66 -28
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +4 -2
- package/services/coupon.service.d.ts +1 -0
|
@@ -6,7 +6,7 @@ import { of, combineLatest, from, throwError, Subject, iif, forkJoin } from 'rxj
|
|
|
6
6
|
import { catchError, map, mergeMap, concatMap, tap } from 'rxjs/operators';
|
|
7
7
|
import { __awaiter } from 'tslib';
|
|
8
8
|
import * as i3 from '@infrab4a/connect';
|
|
9
|
-
import { Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository } from '@infrab4a/connect';
|
|
9
|
+
import { Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository } from '@infrab4a/connect';
|
|
10
10
|
import cookie from 'js-cookie';
|
|
11
11
|
import * as i1$1 from '@angular/fire/firestore';
|
|
12
12
|
import { AngularFirestore } from '@angular/fire/firestore';
|
|
@@ -79,9 +79,9 @@ class CouponService {
|
|
|
79
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
80
|
if (!coupon)
|
|
81
81
|
throw 'Cupom inválido.';
|
|
82
|
-
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) > new Date())
|
|
82
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt.getTime()) > new Date().getTime())
|
|
83
83
|
throw 'Cupom inválido.';
|
|
84
|
-
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
|
|
84
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn.getTime()) < new Date().getTime())
|
|
85
85
|
throw 'Cupom expirado.';
|
|
86
86
|
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
87
87
|
if (!isInShop)
|
|
@@ -99,15 +99,16 @@ class CouponService {
|
|
|
99
99
|
throw 'Cupom inválido para sua assinatura.';
|
|
100
100
|
return coupon;
|
|
101
101
|
}
|
|
102
|
+
const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
103
|
+
if (!validUser)
|
|
104
|
+
throw 'Usuário não elegível.';
|
|
102
105
|
const orders = yield this.getOrdersWithCoupon(coupon);
|
|
103
106
|
const ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
|
|
104
|
-
|
|
107
|
+
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
108
|
+
if (couponUseLimits.limitedPerUser && ordersWithUser > 0)
|
|
105
109
|
throw 'Limite de uso por usuário atingido.';
|
|
106
|
-
if (!
|
|
110
|
+
if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
|
|
107
111
|
throw 'Limite de uso atingido.';
|
|
108
|
-
const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
109
|
-
if (!validUser)
|
|
110
|
-
throw 'Usuário não elegível.';
|
|
111
112
|
const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
|
|
112
113
|
if (!hasProductCategories)
|
|
113
114
|
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
@@ -173,7 +174,7 @@ class CouponService {
|
|
|
173
174
|
var _a;
|
|
174
175
|
if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
175
176
|
return true;
|
|
176
|
-
return i.categories.some((c) => couponCategories.some((cat) => cat
|
|
177
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
177
178
|
});
|
|
178
179
|
return hasCategories.length ? true : false;
|
|
179
180
|
});
|
|
@@ -186,24 +187,31 @@ class CouponService {
|
|
|
186
187
|
userTypes.push(Exclusivities.COLLABORATORS);
|
|
187
188
|
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) && coupon.userExclusiveEmail.includes(user.email))
|
|
188
189
|
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
189
|
-
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER)) &&
|
|
193
|
-
!user.isSubscriber)
|
|
190
|
+
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
191
|
+
user.isSubscriber &&
|
|
192
|
+
user.subscriptionPlan != '')
|
|
194
193
|
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
194
|
+
if (user.isSubscriber &&
|
|
195
|
+
user.subscriptionPlan == '' &&
|
|
196
|
+
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
197
|
+
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
198
|
+
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
199
|
+
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
195
200
|
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
196
201
|
}
|
|
197
202
|
getCouponCategoriesId(productsCategories) {
|
|
198
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
|
|
204
|
+
const couponCategories = [];
|
|
200
205
|
for (let index = 0; index < productsCategories.length; index++) {
|
|
201
|
-
|
|
206
|
+
const category = yield this.categoryRepository.get({
|
|
202
207
|
id: productsCategories[index],
|
|
203
208
|
});
|
|
204
|
-
|
|
209
|
+
if (category) {
|
|
210
|
+
const children = yield this.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
211
|
+
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
212
|
+
}
|
|
205
213
|
}
|
|
206
|
-
return couponCategories;
|
|
214
|
+
return [...new Set(couponCategories)];
|
|
207
215
|
});
|
|
208
216
|
}
|
|
209
217
|
getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
@@ -215,7 +223,7 @@ class CouponService {
|
|
|
215
223
|
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
|
|
216
224
|
var _a;
|
|
217
225
|
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
218
|
-
return i.categories.some((c) => couponCategories.some((cat) => cat
|
|
226
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
219
227
|
}
|
|
220
228
|
return true;
|
|
221
229
|
});
|
|
@@ -249,6 +257,16 @@ class CouponService {
|
|
|
249
257
|
countOrdersWithUser(orders, email) {
|
|
250
258
|
return orders.filter((o) => o.user.email == email).length;
|
|
251
259
|
}
|
|
260
|
+
getCouponUseLimits(coupon, checkoutType, user) {
|
|
261
|
+
let couponUseLimits;
|
|
262
|
+
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
263
|
+
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
couponUseLimits = coupon.useLimits.subscription;
|
|
267
|
+
}
|
|
268
|
+
return couponUseLimits;
|
|
269
|
+
}
|
|
252
270
|
}
|
|
253
271
|
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
254
272
|
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
@@ -331,11 +349,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
331
349
|
}] }]; } });
|
|
332
350
|
|
|
333
351
|
class CartService {
|
|
334
|
-
constructor(authService, checkoutService, defaultShop, productRepository, variantRepository, buy2WinRepository) {
|
|
352
|
+
constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
|
|
335
353
|
this.authService = authService;
|
|
336
354
|
this.checkoutService = checkoutService;
|
|
337
355
|
this.defaultShop = defaultShop;
|
|
338
356
|
this.productRepository = productRepository;
|
|
357
|
+
this.categoryRepository = categoryRepository;
|
|
339
358
|
this.variantRepository = variantRepository;
|
|
340
359
|
this.buy2WinRepository = buy2WinRepository;
|
|
341
360
|
this.cartSubject = new Subject();
|
|
@@ -373,6 +392,7 @@ class CartService {
|
|
|
373
392
|
shop: checkout.shop || this.defaultShop,
|
|
374
393
|
isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
|
|
375
394
|
});
|
|
395
|
+
RoundProductPricesHelper.roundProductPrices(item);
|
|
376
396
|
return {
|
|
377
397
|
checkout,
|
|
378
398
|
lineItem: LineItem.toInstance({
|
|
@@ -383,7 +403,7 @@ class CartService {
|
|
|
383
403
|
slug: slug !== null && slug !== void 0 ? slug : product.slug,
|
|
384
404
|
sku: sku !== null && sku !== void 0 ? sku : product.sku,
|
|
385
405
|
stock,
|
|
386
|
-
price,
|
|
406
|
+
price: this.roundPrice(price),
|
|
387
407
|
image,
|
|
388
408
|
weight: weight !== null && weight !== void 0 ? weight : product.weight,
|
|
389
409
|
quantity: (item.quantity || 0) + (quantity || 0),
|
|
@@ -399,7 +419,9 @@ class CartService {
|
|
|
399
419
|
const info = product.price;
|
|
400
420
|
if (product.isGift)
|
|
401
421
|
return 0;
|
|
402
|
-
return isSubscriber && info.subscriberPrice > 0
|
|
422
|
+
return isSubscriber && info.subscriberPrice > 0
|
|
423
|
+
? Number(info.subscriberPrice.toFixed(2))
|
|
424
|
+
: Number(info.price.toFixed(2));
|
|
403
425
|
};
|
|
404
426
|
this.checkMaxStock = (item, quantity) => {
|
|
405
427
|
var _a;
|
|
@@ -457,6 +479,10 @@ class CartService {
|
|
|
457
479
|
buildCartFromCheckout(checkoutData) {
|
|
458
480
|
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
459
481
|
}
|
|
482
|
+
roundPrice(productPrice) {
|
|
483
|
+
const { price, fullPrice, subscriberPrice } = productPrice;
|
|
484
|
+
return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
|
|
485
|
+
}
|
|
460
486
|
getProductData(productId) {
|
|
461
487
|
return __awaiter(this, void 0, void 0, function* () {
|
|
462
488
|
let product;
|
|
@@ -467,7 +493,10 @@ class CartService {
|
|
|
467
493
|
catch (error) {
|
|
468
494
|
if (!(error instanceof NotFoundError))
|
|
469
495
|
throw error;
|
|
470
|
-
|
|
496
|
+
const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
|
|
497
|
+
variant = variants.shift();
|
|
498
|
+
if (!variant)
|
|
499
|
+
throw error;
|
|
471
500
|
product = yield this.productRepository.get({ id: variant.productId });
|
|
472
501
|
}
|
|
473
502
|
return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
|
|
@@ -491,16 +520,22 @@ class CartService {
|
|
|
491
520
|
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
492
521
|
const elegibleCampaigns = [];
|
|
493
522
|
for (const campaign of campaigns) {
|
|
494
|
-
const today = new Date();
|
|
495
|
-
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
523
|
+
const today = new Date().getDate();
|
|
524
|
+
if (!(campaign.startDate.getDate() <= today) && !(campaign.endDate.getDate() >= today))
|
|
496
525
|
continue;
|
|
497
526
|
if (campaign.activeCategory) {
|
|
498
|
-
const categoriesCampaing = campaign.categories.map((c) => c.id);
|
|
527
|
+
const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
|
|
528
|
+
const categoriesCampaingFullTree = [];
|
|
529
|
+
for (const id of categoriesCampaing) {
|
|
530
|
+
const children = yield this.categoryRepository.getChildren(parseInt(id));
|
|
531
|
+
categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
|
|
532
|
+
}
|
|
533
|
+
const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
|
|
499
534
|
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
500
535
|
var _a;
|
|
501
536
|
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
502
537
|
return true;
|
|
503
|
-
return l.categories.some((c) =>
|
|
538
|
+
return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
|
|
504
539
|
});
|
|
505
540
|
if (filterProductsCategories.length) {
|
|
506
541
|
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
@@ -561,7 +596,7 @@ class CartService {
|
|
|
561
596
|
});
|
|
562
597
|
}
|
|
563
598
|
}
|
|
564
|
-
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
599
|
+
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
565
600
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
|
|
566
601
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
|
|
567
602
|
type: Injectable
|
|
@@ -571,6 +606,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
571
606
|
}] }, { type: undefined, decorators: [{
|
|
572
607
|
type: Inject,
|
|
573
608
|
args: ['ProductRepository']
|
|
609
|
+
}] }, { type: undefined, decorators: [{
|
|
610
|
+
type: Inject,
|
|
611
|
+
args: ['CategoryRepository']
|
|
574
612
|
}] }, { type: undefined, decorators: [{
|
|
575
613
|
type: Inject,
|
|
576
614
|
args: ['VariantRepository']
|