@infrab4a/connect-angular 3.10.0-beta.10 → 3.10.0-beta.2
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 +94 -169
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +10 -23
- package/esm2015/services/coupon.service.js +14 -28
- package/fesm2015/infrab4a-connect-angular.js +20 -47
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +2 -3
- package/services/coupon.service.d.ts +0 -1
|
@@ -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
|
|
82
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) > new Date())
|
|
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
|
|
84
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
|
|
85
85
|
throw 'Cupom expirado.';
|
|
86
86
|
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
87
87
|
if (!isInShop)
|
|
@@ -99,16 +99,15 @@ 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.';
|
|
105
102
|
const orders = yield this.getOrdersWithCoupon(coupon);
|
|
106
103
|
const ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
|
|
107
|
-
|
|
108
|
-
if (couponUseLimits.limitedPerUser && ordersWithUser > 0)
|
|
104
|
+
if (coupon.useLimitPerUser && ordersWithUser > 0)
|
|
109
105
|
throw 'Limite de uso por usuário atingido.';
|
|
110
|
-
if (!
|
|
106
|
+
if (!coupon.unlimited && coupon.useLimit && orders.length >= coupon.useLimit)
|
|
111
107
|
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.';
|
|
112
111
|
const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
|
|
113
112
|
if (!hasProductCategories)
|
|
114
113
|
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
@@ -174,7 +173,7 @@ class CouponService {
|
|
|
174
173
|
var _a;
|
|
175
174
|
if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
176
175
|
return true;
|
|
177
|
-
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
176
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
|
|
178
177
|
});
|
|
179
178
|
return hasCategories.length ? true : false;
|
|
180
179
|
});
|
|
@@ -201,17 +200,14 @@ class CouponService {
|
|
|
201
200
|
}
|
|
202
201
|
getCouponCategoriesId(productsCategories) {
|
|
203
202
|
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
|
|
203
|
+
let couponCategories = [];
|
|
205
204
|
for (let index = 0; index < productsCategories.length; index++) {
|
|
206
|
-
|
|
205
|
+
let c = yield this.categoryRepository.get({
|
|
207
206
|
id: productsCategories[index],
|
|
208
207
|
});
|
|
209
|
-
|
|
210
|
-
const children = yield this.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
211
|
-
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
212
|
-
}
|
|
208
|
+
couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
|
|
213
209
|
}
|
|
214
|
-
return
|
|
210
|
+
return couponCategories;
|
|
215
211
|
});
|
|
216
212
|
}
|
|
217
213
|
getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
@@ -223,7 +219,7 @@ class CouponService {
|
|
|
223
219
|
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
|
|
224
220
|
var _a;
|
|
225
221
|
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
226
|
-
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
222
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
|
|
227
223
|
}
|
|
228
224
|
return true;
|
|
229
225
|
});
|
|
@@ -257,16 +253,6 @@ class CouponService {
|
|
|
257
253
|
countOrdersWithUser(orders, email) {
|
|
258
254
|
return orders.filter((o) => o.user.email == email).length;
|
|
259
255
|
}
|
|
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
|
-
}
|
|
270
256
|
}
|
|
271
257
|
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 });
|
|
272
258
|
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
@@ -349,12 +335,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
349
335
|
}] }]; } });
|
|
350
336
|
|
|
351
337
|
class CartService {
|
|
352
|
-
constructor(authService, checkoutService, defaultShop, productRepository,
|
|
338
|
+
constructor(authService, checkoutService, defaultShop, productRepository, variantRepository, buy2WinRepository) {
|
|
353
339
|
this.authService = authService;
|
|
354
340
|
this.checkoutService = checkoutService;
|
|
355
341
|
this.defaultShop = defaultShop;
|
|
356
342
|
this.productRepository = productRepository;
|
|
357
|
-
this.categoryRepository = categoryRepository;
|
|
358
343
|
this.variantRepository = variantRepository;
|
|
359
344
|
this.buy2WinRepository = buy2WinRepository;
|
|
360
345
|
this.cartSubject = new Subject();
|
|
@@ -493,10 +478,7 @@ class CartService {
|
|
|
493
478
|
catch (error) {
|
|
494
479
|
if (!(error instanceof NotFoundError))
|
|
495
480
|
throw error;
|
|
496
|
-
|
|
497
|
-
variant = variants.shift();
|
|
498
|
-
if (!variant)
|
|
499
|
-
throw error;
|
|
481
|
+
variant = yield this.variantRepository.get({ id: productId });
|
|
500
482
|
product = yield this.productRepository.get({ id: variant.productId });
|
|
501
483
|
}
|
|
502
484
|
return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
|
|
@@ -520,22 +502,16 @@ class CartService {
|
|
|
520
502
|
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
521
503
|
const elegibleCampaigns = [];
|
|
522
504
|
for (const campaign of campaigns) {
|
|
523
|
-
const today = new Date()
|
|
524
|
-
if (!(campaign.startDate
|
|
505
|
+
const today = new Date();
|
|
506
|
+
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
525
507
|
continue;
|
|
526
508
|
if (campaign.activeCategory) {
|
|
527
|
-
const categoriesCampaing = campaign.categories.map((c) => c.id
|
|
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)];
|
|
509
|
+
const categoriesCampaing = campaign.categories.map((c) => c.id);
|
|
534
510
|
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
535
511
|
var _a;
|
|
536
512
|
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
537
513
|
return true;
|
|
538
|
-
return l.categories.some((c) =>
|
|
514
|
+
return l.categories.some((c) => categoriesCampaing.some((cat) => cat == c));
|
|
539
515
|
});
|
|
540
516
|
if (filterProductsCategories.length) {
|
|
541
517
|
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
@@ -596,7 +572,7 @@ class CartService {
|
|
|
596
572
|
});
|
|
597
573
|
}
|
|
598
574
|
}
|
|
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: '
|
|
575
|
+
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 });
|
|
600
576
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
|
|
601
577
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
|
|
602
578
|
type: Injectable
|
|
@@ -606,9 +582,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
606
582
|
}] }, { type: undefined, decorators: [{
|
|
607
583
|
type: Inject,
|
|
608
584
|
args: ['ProductRepository']
|
|
609
|
-
}] }, { type: undefined, decorators: [{
|
|
610
|
-
type: Inject,
|
|
611
|
-
args: ['CategoryRepository']
|
|
612
585
|
}] }, { type: undefined, decorators: [{
|
|
613
586
|
type: Inject,
|
|
614
587
|
args: ['VariantRepository']
|