@infrab4a/connect-angular 2.0.6-beta.2 → 2.0.6-beta.4
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.
|
@@ -450,56 +450,44 @@
|
|
|
450
450
|
nickname: { operator: i2.Where.EQUALS, value: nickname },
|
|
451
451
|
active: { operator: i2.Where.EQUALS, value: true },
|
|
452
452
|
},
|
|
453
|
-
})).pipe(operators.concatMap(function (coupons) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_d) {
|
|
453
|
+
})).pipe(operators.concatMap(function (coupons) { return _this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription); }), operators.concatMap(function (coupon) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_d) {
|
|
454
454
|
switch (_d.label) {
|
|
455
|
-
case 0: return [4 /*yield*/, this.
|
|
455
|
+
case 0: return [4 /*yield*/, this.checkCouponUseAndLimit(coupon, userEmail, checkout)];
|
|
456
456
|
case 1: return [2 /*return*/, _d.sent()];
|
|
457
457
|
}
|
|
458
|
-
}); }); }), operators.
|
|
458
|
+
}); }); }), operators.map(function (coupon) { return _this.isValidCoupon(coupon, userEmail); }), operators.map(function (coupon) { return coupon; }));
|
|
459
459
|
};
|
|
460
460
|
CouponService.prototype.checkCouponRules = function (coupons, checkoutType, plan, checkout, isSubscription) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
return
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
|
|
492
|
-
case 1:
|
|
493
|
-
hasProductCategories = _d.sent();
|
|
494
|
-
console.log('hasProductCategories', hasProductCategories);
|
|
495
|
-
// Se não tem produtos elegíveis, retorna erro
|
|
496
|
-
if (!hasProductCategories)
|
|
497
|
-
return [2 /*return*/, rxjs.throwError('Seu carrinho não possui produtos elegíveis para desconto.')];
|
|
498
|
-
// return of(coupon)
|
|
499
|
-
return [2 /*return*/, coupon];
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
});
|
|
461
|
+
// Caso não ache nenhum cupom, retorna erro
|
|
462
|
+
if (coupons.count < 1) {
|
|
463
|
+
return rxjs.throwError('Cupom inválido.');
|
|
464
|
+
}
|
|
465
|
+
// Get Primeiro Cupom (o find do repository retorna um array)
|
|
466
|
+
var coupon = coupons.data.shift();
|
|
467
|
+
// Verifica se o cupom é aplicavel na loja
|
|
468
|
+
var isInShop = coupon.shopAvailability === i2.Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
469
|
+
// Cupon não aplicavel a loja retorna erro
|
|
470
|
+
if (!isInShop)
|
|
471
|
+
return rxjs.throwError('Cupom inválido para loja.');
|
|
472
|
+
// Verifica se o coupon é aplicado no checkout que está sendo realizado
|
|
473
|
+
var isCheckoutType = coupon.checkoutType === i2.CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
474
|
+
// Cupon não aplicavel ao checkout retorna erro
|
|
475
|
+
if (!isCheckoutType)
|
|
476
|
+
return rxjs.throwError('Cupom inválido. Erro de checkout.');
|
|
477
|
+
// Verifica se o cupom é ou pode ser aplicado para subscription
|
|
478
|
+
if (checkoutType === i2.CheckoutTypes.ALL || checkoutType === i2.CheckoutTypes.SUBSCRIPTION) {
|
|
479
|
+
// Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
|
|
480
|
+
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
481
|
+
return rxjs.throwError('Cupom inválido para sua assinatura.');
|
|
482
|
+
}
|
|
483
|
+
if (isSubscription)
|
|
484
|
+
return rxjs.of(coupon);
|
|
485
|
+
// Verifica se possui o valor minimo de compra para utilização do cupom
|
|
486
|
+
var hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
|
|
487
|
+
// Se não tem valor mínimo atingido, retorna erro
|
|
488
|
+
if (!hasMinSubTotal)
|
|
489
|
+
return rxjs.throwError('Valor mínimo não atingido');
|
|
490
|
+
return rxjs.of(coupon);
|
|
503
491
|
};
|
|
504
492
|
CouponService.prototype.isValidCoupon = function (coupon, userEmail) {
|
|
505
493
|
// Verifica a data de inicio de validade do cupom
|
|
@@ -510,9 +498,9 @@
|
|
|
510
498
|
throw new InvalidCouponError('Cupom expirado.');
|
|
511
499
|
return coupon;
|
|
512
500
|
};
|
|
513
|
-
CouponService.prototype.checkCouponUseAndLimit = function (coupon, userEmail) {
|
|
501
|
+
CouponService.prototype.checkCouponUseAndLimit = function (coupon, userEmail, checkout) {
|
|
514
502
|
return __awaiter(this, void 0, void 0, function () {
|
|
515
|
-
var orders, ordersUserCoupon, validUser;
|
|
503
|
+
var orders, ordersUserCoupon, validUser, hasProductCategories;
|
|
516
504
|
return __generator(this, function (_d) {
|
|
517
505
|
switch (_d.label) {
|
|
518
506
|
case 0: return [4 /*yield*/, this.orderRepository.find({
|
|
@@ -535,6 +523,13 @@
|
|
|
535
523
|
validUser = _d.sent();
|
|
536
524
|
if (!validUser)
|
|
537
525
|
throw new InvalidCouponError('Usuário não elegível.');
|
|
526
|
+
return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
|
|
527
|
+
case 3:
|
|
528
|
+
hasProductCategories = _d.sent();
|
|
529
|
+
console.log('hasProductCategories', hasProductCategories);
|
|
530
|
+
// Se não tem produtos elegíveis, retorna erro
|
|
531
|
+
if (!hasProductCategories)
|
|
532
|
+
return [2 /*return*/, rxjs.throwError('Seu carrinho não possui produtos elegíveis para desconto.')];
|
|
538
533
|
return [2 /*return*/, coupon];
|
|
539
534
|
}
|
|
540
535
|
});
|
|
@@ -610,35 +605,32 @@
|
|
|
610
605
|
var hasCategories;
|
|
611
606
|
var _this = this;
|
|
612
607
|
return __generator(this, function (_d) {
|
|
613
|
-
if (coupon.productsCategories && coupon.productsCategories.length) {
|
|
614
|
-
|
|
615
|
-
var _a;
|
|
616
|
-
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
617
|
-
// buscar categoria por id
|
|
618
|
-
// filtrar por id ou firestore id
|
|
619
|
-
return i.categories.some(function (c) { return __awaiter(_this, void 0, void 0, function () {
|
|
620
|
-
var categoria;
|
|
621
|
-
return __generator(this, function (_d) {
|
|
622
|
-
switch (_d.label) {
|
|
623
|
-
case 0: return [4 /*yield*/, this.categoryRepository.get({ id: c })];
|
|
624
|
-
case 1:
|
|
625
|
-
categoria = _d.sent();
|
|
626
|
-
console.log(categoria);
|
|
627
|
-
console.log(coupon.productsCategories.includes(categoria.id), coupon.productsCategories.includes(categoria.firestoreId), i.isGift);
|
|
628
|
-
console.log('validation', (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift);
|
|
629
|
-
return [2 /*return*/, (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift];
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
}); });
|
|
633
|
-
}
|
|
634
|
-
return true;
|
|
635
|
-
});
|
|
636
|
-
return [2 /*return*/, hasCategories.length ? true : false];
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
608
|
+
if (!coupon.productsCategories && !coupon.productsCategories.length) {
|
|
609
|
+
console.log('não possui categories');
|
|
639
610
|
return [2 /*return*/, true];
|
|
640
611
|
}
|
|
641
|
-
|
|
612
|
+
hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
|
|
613
|
+
var _a;
|
|
614
|
+
if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
615
|
+
console.log('produto não tem categorias');
|
|
616
|
+
return true;
|
|
617
|
+
}
|
|
618
|
+
return i.categories.some(function (c) { return __awaiter(_this, void 0, void 0, function () {
|
|
619
|
+
var categoria;
|
|
620
|
+
return __generator(this, function (_d) {
|
|
621
|
+
switch (_d.label) {
|
|
622
|
+
case 0: return [4 /*yield*/, this.categoryRepository.get({ id: c })];
|
|
623
|
+
case 1:
|
|
624
|
+
categoria = _d.sent();
|
|
625
|
+
console.log(categoria);
|
|
626
|
+
console.log(coupon.productsCategories.includes(categoria.id), coupon.productsCategories.includes(categoria.firestoreId), i.isGift);
|
|
627
|
+
console.log('validation', (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift);
|
|
628
|
+
return [2 /*return*/, (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift];
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}); });
|
|
632
|
+
});
|
|
633
|
+
return [2 /*return*/, hasCategories.length ? true : false];
|
|
642
634
|
});
|
|
643
635
|
});
|
|
644
636
|
};
|