@infrab4a/connect-angular 2.0.6-beta.1 → 2.0.6-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.
|
@@ -450,45 +450,56 @@
|
|
|
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 _this
|
|
453
|
+
})).pipe(operators.concatMap(function (coupons) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_d) {
|
|
454
|
+
switch (_d.label) {
|
|
455
|
+
case 0: return [4 /*yield*/, this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)];
|
|
456
|
+
case 1: return [2 /*return*/, _d.sent()];
|
|
457
|
+
}
|
|
458
|
+
}); }); }), operators.concatMap(function (coupon) { return _this.checkCouponUseAndLimit(coupon, userEmail); }), operators.map(function (coupon) { return _this.isValidCoupon(coupon, userEmail); }), operators.map(function (coupon) { return coupon; }));
|
|
454
459
|
};
|
|
455
460
|
CouponService.prototype.checkCouponRules = function (coupons, checkoutType, plan, checkout, isSubscription) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
return
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
|
|
461
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
462
|
+
var coupon, isInShop, isCheckoutType, hasMinSubTotal, hasProductCategories;
|
|
463
|
+
return __generator(this, function (_d) {
|
|
464
|
+
switch (_d.label) {
|
|
465
|
+
case 0:
|
|
466
|
+
// Caso não ache nenhum cupom, retorna erro
|
|
467
|
+
if (coupons.count < 1) {
|
|
468
|
+
return [2 /*return*/, rxjs.throwError('Cupom inválido.')];
|
|
469
|
+
}
|
|
470
|
+
coupon = coupons.data.shift();
|
|
471
|
+
isInShop = coupon.shopAvailability === i2.Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
472
|
+
// Cupon não aplicavel a loja retorna erro
|
|
473
|
+
if (!isInShop)
|
|
474
|
+
return [2 /*return*/, rxjs.throwError('Cupom inválido para loja.')];
|
|
475
|
+
isCheckoutType = coupon.checkoutType === i2.CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
476
|
+
// Cupon não aplicavel ao checkout retorna erro
|
|
477
|
+
if (!isCheckoutType)
|
|
478
|
+
return [2 /*return*/, rxjs.throwError('Cupom inválido. Erro de checkout.')];
|
|
479
|
+
// Verifica se o cupom é ou pode ser aplicado para subscription
|
|
480
|
+
if (checkoutType === i2.CheckoutTypes.ALL || checkoutType === i2.CheckoutTypes.SUBSCRIPTION) {
|
|
481
|
+
// Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
|
|
482
|
+
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
483
|
+
return [2 /*return*/, rxjs.throwError('Cupom inválido para sua assinatura.')];
|
|
484
|
+
}
|
|
485
|
+
if (isSubscription)
|
|
486
|
+
return [2 /*return*/, rxjs.of(coupon)];
|
|
487
|
+
hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
|
|
488
|
+
// Se não tem valor mínimo atingido, retorna erro
|
|
489
|
+
if (!hasMinSubTotal)
|
|
490
|
+
return [2 /*return*/, rxjs.throwError('Valor mínimo não atingido')];
|
|
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
|
+
});
|
|
492
503
|
};
|
|
493
504
|
CouponService.prototype.isValidCoupon = function (coupon, userEmail) {
|
|
494
505
|
// Verifica a data de inicio de validade do cupom
|
|
@@ -594,36 +605,42 @@
|
|
|
594
605
|
return false;
|
|
595
606
|
};
|
|
596
607
|
CouponService.prototype.hasProductCategories = function (coupon, checkout) {
|
|
597
|
-
var _this = this;
|
|
598
608
|
var _a;
|
|
599
|
-
|
|
600
|
-
var hasCategories
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
609
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
610
|
+
var hasCategories;
|
|
611
|
+
var _this = this;
|
|
612
|
+
return __generator(this, function (_d) {
|
|
613
|
+
if (coupon.productsCategories && coupon.productsCategories.length) {
|
|
614
|
+
hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
|
|
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];
|
|
619
637
|
}
|
|
620
|
-
|
|
638
|
+
else {
|
|
639
|
+
return [2 /*return*/, true];
|
|
640
|
+
}
|
|
641
|
+
return [2 /*return*/];
|
|
621
642
|
});
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
else {
|
|
625
|
-
return true;
|
|
626
|
-
}
|
|
643
|
+
});
|
|
627
644
|
};
|
|
628
645
|
CouponService.prototype.userValidationAndSubscriptionStatus = function (coupon, userEmail) {
|
|
629
646
|
return __awaiter(this, void 0, void 0, function () {
|