@infrab4a/connect-angular 3.10.0-beta.1 → 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 +169 -94
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +23 -10
- package/esm2015/services/coupon.service.js +28 -14
- package/fesm2015/infrab4a-connect-angular.js +47 -20
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +3 -2
- package/services/coupon.service.d.ts +1 -0
|
@@ -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
|
});
|
|
@@ -200,14 +201,17 @@ class CouponService {
|
|
|
200
201
|
}
|
|
201
202
|
getCouponCategoriesId(productsCategories) {
|
|
202
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
|
|
204
|
+
const couponCategories = [];
|
|
204
205
|
for (let index = 0; index < productsCategories.length; index++) {
|
|
205
|
-
|
|
206
|
+
const category = yield this.categoryRepository.get({
|
|
206
207
|
id: productsCategories[index],
|
|
207
208
|
});
|
|
208
|
-
|
|
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
|
+
}
|
|
209
213
|
}
|
|
210
|
-
return couponCategories;
|
|
214
|
+
return [...new Set(couponCategories)];
|
|
211
215
|
});
|
|
212
216
|
}
|
|
213
217
|
getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
@@ -219,7 +223,7 @@ class CouponService {
|
|
|
219
223
|
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
|
|
220
224
|
var _a;
|
|
221
225
|
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
222
|
-
return i.categories.some((c) => couponCategories.some((cat) => cat
|
|
226
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
223
227
|
}
|
|
224
228
|
return true;
|
|
225
229
|
});
|
|
@@ -253,6 +257,16 @@ class CouponService {
|
|
|
253
257
|
countOrdersWithUser(orders, email) {
|
|
254
258
|
return orders.filter((o) => o.user.email == email).length;
|
|
255
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
|
+
}
|
|
256
270
|
}
|
|
257
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 });
|
|
258
272
|
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
@@ -335,11 +349,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
335
349
|
}] }]; } });
|
|
336
350
|
|
|
337
351
|
class CartService {
|
|
338
|
-
constructor(authService, checkoutService, defaultShop, productRepository, variantRepository, buy2WinRepository) {
|
|
352
|
+
constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
|
|
339
353
|
this.authService = authService;
|
|
340
354
|
this.checkoutService = checkoutService;
|
|
341
355
|
this.defaultShop = defaultShop;
|
|
342
356
|
this.productRepository = productRepository;
|
|
357
|
+
this.categoryRepository = categoryRepository;
|
|
343
358
|
this.variantRepository = variantRepository;
|
|
344
359
|
this.buy2WinRepository = buy2WinRepository;
|
|
345
360
|
this.cartSubject = new Subject();
|
|
@@ -478,7 +493,10 @@ class CartService {
|
|
|
478
493
|
catch (error) {
|
|
479
494
|
if (!(error instanceof NotFoundError))
|
|
480
495
|
throw error;
|
|
481
|
-
|
|
496
|
+
const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
|
|
497
|
+
variant = variants.shift();
|
|
498
|
+
if (!variant)
|
|
499
|
+
throw error;
|
|
482
500
|
product = yield this.productRepository.get({ id: variant.productId });
|
|
483
501
|
}
|
|
484
502
|
return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
|
|
@@ -502,16 +520,22 @@ class CartService {
|
|
|
502
520
|
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
503
521
|
const elegibleCampaigns = [];
|
|
504
522
|
for (const campaign of campaigns) {
|
|
505
|
-
const today = new Date();
|
|
506
|
-
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
523
|
+
const today = new Date().getDate();
|
|
524
|
+
if (!(campaign.startDate.getDate() <= today) && !(campaign.endDate.getDate() >= today))
|
|
507
525
|
continue;
|
|
508
526
|
if (campaign.activeCategory) {
|
|
509
|
-
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)];
|
|
510
534
|
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
511
535
|
var _a;
|
|
512
536
|
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
513
537
|
return true;
|
|
514
|
-
return l.categories.some((c) =>
|
|
538
|
+
return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
|
|
515
539
|
});
|
|
516
540
|
if (filterProductsCategories.length) {
|
|
517
541
|
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
@@ -572,7 +596,7 @@ class CartService {
|
|
|
572
596
|
});
|
|
573
597
|
}
|
|
574
598
|
}
|
|
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 });
|
|
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 });
|
|
576
600
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
|
|
577
601
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
|
|
578
602
|
type: Injectable
|
|
@@ -582,6 +606,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
582
606
|
}] }, { type: undefined, decorators: [{
|
|
583
607
|
type: Inject,
|
|
584
608
|
args: ['ProductRepository']
|
|
609
|
+
}] }, { type: undefined, decorators: [{
|
|
610
|
+
type: Inject,
|
|
611
|
+
args: ['CategoryRepository']
|
|
585
612
|
}] }, { type: undefined, decorators: [{
|
|
586
613
|
type: Inject,
|
|
587
614
|
args: ['VariantRepository']
|