@infrab4a/connect-angular 3.6.0 → 3.7.0-beta.1

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.
@@ -31,7 +31,7 @@
31
31
  var i1__namespace$2 = /*#__PURE__*/_interopNamespace(i1$2);
32
32
  var i1__namespace$3 = /*#__PURE__*/_interopNamespace(i1$3);
33
33
 
34
- /*! *****************************************************************************
34
+ /******************************************************************************
35
35
  Copyright (c) Microsoft Corporation.
36
36
 
37
37
  Permission to use, copy, modify, and/or distribute this software for any
@@ -98,6 +98,64 @@
98
98
  function __param(paramIndex, decorator) {
99
99
  return function (target, key) { decorator(target, key, paramIndex); };
100
100
  }
101
+ function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
102
+ function accept(f) { if (f !== void 0 && typeof f !== "function")
103
+ throw new TypeError("Function expected"); return f; }
104
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
105
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
106
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
107
+ var _, done = false;
108
+ for (var i = decorators.length - 1; i >= 0; i--) {
109
+ var context = {};
110
+ for (var p in contextIn)
111
+ context[p] = p === "access" ? {} : contextIn[p];
112
+ for (var p in contextIn.access)
113
+ context.access[p] = contextIn.access[p];
114
+ context.addInitializer = function (f) { if (done)
115
+ throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
116
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
117
+ if (kind === "accessor") {
118
+ if (result === void 0)
119
+ continue;
120
+ if (result === null || typeof result !== "object")
121
+ throw new TypeError("Object expected");
122
+ if (_ = accept(result.get))
123
+ descriptor.get = _;
124
+ if (_ = accept(result.set))
125
+ descriptor.set = _;
126
+ if (_ = accept(result.init))
127
+ initializers.push(_);
128
+ }
129
+ else if (_ = accept(result)) {
130
+ if (kind === "field")
131
+ initializers.push(_);
132
+ else
133
+ descriptor[key] = _;
134
+ }
135
+ }
136
+ if (target)
137
+ Object.defineProperty(target, contextIn.name, descriptor);
138
+ done = true;
139
+ }
140
+ ;
141
+ function __runInitializers(thisArg, initializers, value) {
142
+ var useValue = arguments.length > 2;
143
+ for (var i = 0; i < initializers.length; i++) {
144
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
145
+ }
146
+ return useValue ? value : void 0;
147
+ }
148
+ ;
149
+ function __propKey(x) {
150
+ return typeof x === "symbol" ? x : "".concat(x);
151
+ }
152
+ ;
153
+ function __setFunctionName(f, name, prefix) {
154
+ if (typeof name === "symbol")
155
+ name = name.description ? "[".concat(name.description, "]") : "";
156
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
157
+ }
158
+ ;
101
159
  function __metadata(metadataKey, metadataValue) {
102
160
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
103
161
  return Reflect.metadata(metadataKey, metadataValue);
@@ -129,7 +187,7 @@
129
187
  function step(op) {
130
188
  if (f)
131
189
  throw new TypeError("Generator is already executing.");
132
- while (_)
190
+ while (g && (g = 0, op[0] && (_ = 0)), _)
133
191
  try {
134
192
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
135
193
  return t;
@@ -193,7 +251,11 @@
193
251
  var __createBinding = Object.create ? (function (o, m, k, k2) {
194
252
  if (k2 === undefined)
195
253
  k2 = k;
196
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
254
+ var desc = Object.getOwnPropertyDescriptor(m, k);
255
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
256
+ desc = { enumerable: true, get: function () { return m[k]; } };
257
+ }
258
+ Object.defineProperty(o, k2, desc);
197
259
  }) : (function (o, m, k, k2) {
198
260
  if (k2 === undefined)
199
261
  k2 = k;
@@ -293,7 +355,7 @@
293
355
  function __asyncDelegator(o) {
294
356
  var i, p;
295
357
  return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
296
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
358
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
297
359
  }
298
360
  function __asyncValues(o) {
299
361
  if (!Symbol.asyncIterator)
@@ -347,6 +409,11 @@
347
409
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
348
410
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
349
411
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
412
+ }
413
+ function __classPrivateFieldIn(state, receiver) {
414
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
415
+ throw new TypeError("Cannot use 'in' operator on non-object");
416
+ return typeof state === "function" ? receiver === state : state.has(receiver);
350
417
  }
351
418
 
352
419
  var AuthService = /** @class */ (function () {
@@ -516,11 +583,13 @@
516
583
  // Verifica o limite de uso geral por usuario
517
584
  if (coupon.useLimit && orders.data.length >= coupon.useLimit)
518
585
  throw new InvalidCouponError('Limite de uso atingido.');
519
- validUser = this.userValidationAndSubscriptionStatus(coupon, checkout.user);
586
+ return [4 /*yield*/, this.userValidationAndSubscriptionStatus(coupon, userEmail)];
587
+ case 2:
588
+ validUser = _d.sent();
520
589
  if (!validUser)
521
590
  throw new InvalidCouponError('Usuário não elegível.');
522
591
  return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
523
- case 2:
592
+ case 3:
524
593
  hasProductCategories = _d.sent();
525
594
  if (!hasProductCategories)
526
595
  throw 'Seu carrinho não possui produtos elegíveis para desconto.';
@@ -583,7 +652,7 @@
583
652
  lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
584
653
  var _a;
585
654
  if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
586
- return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat.id == c || cat.firestoreId == c; }); });
655
+ return i.categories.some(function (c) { return couponCategories.some(function (cat) { return (cat.id == c || cat.firestoreId == c); }); });
587
656
  }
588
657
  return true;
589
658
  });
@@ -635,31 +704,56 @@
635
704
  var _a;
636
705
  if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
637
706
  return true;
638
- return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat.id == c || cat.firestoreId == c; }); });
707
+ return i.categories.some(function (c) { return couponCategories.some(function (cat) { return (cat.id == c || cat.firestoreId == c); }); });
639
708
  });
640
709
  return [2 /*return*/, hasCategories.length ? true : false];
641
710
  }
642
711
  });
643
712
  });
644
713
  };
645
- CouponService.prototype.userValidationAndSubscriptionStatus = function (coupon, user) {
646
- if (coupon.exclusivityType === i1$1.Exclusivities.ALL_USERS)
647
- return true;
648
- // Verifica se o email do usuário é coorporativo
649
- if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === i1$1.Exclusivities.COLLABORATORS)
650
- throw new InvalidCouponError('Você não é colaborador.');
651
- // Verifica se o email do usuário é associado ao cupom de uso por usuario
652
- if (coupon.exclusivityType === i1$1.Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== user.email)
653
- throw new InvalidCouponError('Cupom não é válido para este usuário.');
654
- switch (coupon.exclusivityType) {
655
- case i1$1.Exclusivities.ACTIVE_SUBSCRIBER:
656
- return user.isSubscriber ? true : false;
657
- case i1$1.Exclusivities.INACTIVE_SUBSCRIBER:
658
- return user.isSubscriber ? false : true;
659
- case i1$1.Exclusivities.NON_SUBSCRIBER:
660
- return user.isSubscriber ? false : true;
661
- }
662
- return true;
714
+ CouponService.prototype.userValidationAndSubscriptionStatus = function (coupon, userEmail) {
715
+ return __awaiter(this, void 0, void 0, function () {
716
+ var couponRuleSubscription, sub, activeSubs;
717
+ return __generator(this, function (_d) {
718
+ switch (_d.label) {
719
+ case 0:
720
+ // Verifica se o email do usuário é coorporativo
721
+ if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === i1$1.Exclusivities.COLLABORATORS)
722
+ throw new InvalidCouponError('Você não é colaborador.');
723
+ // Verifica se o email do usuário é associado ao cupom de uso por usuario
724
+ if (coupon.exclusivityType === i1$1.Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== userEmail)
725
+ throw new InvalidCouponError('Cupom não é válido para este usuário.');
726
+ couponRuleSubscription = coupon.exclusivityType === i1$1.Exclusivities.ACTIVE_SUBSCRIBER ||
727
+ coupon.exclusivityType === i1$1.Exclusivities.INACTIVE_SUBSCRIBER ||
728
+ coupon.exclusivityType === i1$1.Exclusivities.NON_SUBSCRIBER;
729
+ if (!(couponRuleSubscription && userEmail)) return [3 /*break*/, 2];
730
+ return [4 /*yield*/, this.subscriptionRepository
731
+ .find({
732
+ filters: {
733
+ user: {
734
+ email: { operator: i1$1.Where.EQUALS, value: userEmail },
735
+ },
736
+ },
737
+ })
738
+ .then(function (sub) { return sub.data; })];
739
+ case 1:
740
+ sub = _d.sent();
741
+ activeSubs = sub === null || sub === void 0 ? void 0 : sub.filter(function (s) { return s.status === i1$1.Status.ACTIVE; });
742
+ switch (coupon.exclusivityType) {
743
+ case i1$1.Exclusivities.ACTIVE_SUBSCRIBER:
744
+ return [2 /*return*/, activeSubs.length > 0];
745
+ case i1$1.Exclusivities.INACTIVE_SUBSCRIBER:
746
+ return [2 /*return*/, activeSubs.length === 0];
747
+ case i1$1.Exclusivities.NON_SUBSCRIBER:
748
+ return [2 /*return*/, sub.length === 0];
749
+ default:
750
+ return [2 /*return*/, false];
751
+ }
752
+ _d.label = 2;
753
+ case 2: return [2 /*return*/, true];
754
+ }
755
+ });
756
+ });
663
757
  };
664
758
  CouponService.prototype.getCouponCategoriesId = function (coupon) {
665
759
  return __awaiter(this, void 0, void 0, function () {
@@ -672,9 +766,7 @@
672
766
  _d.label = 1;
673
767
  case 1:
674
768
  if (!(index < coupon.productsCategories.length)) return [3 /*break*/, 4];
675
- return [4 /*yield*/, this.categoryRepository.get({
676
- id: coupon.productsCategories[index],
677
- })];
769
+ return [4 /*yield*/, this.categoryRepository.get({ id: coupon.productsCategories[index] })];
678
770
  case 2:
679
771
  c = _d.sent();
680
772
  couponCategories.push({ id: c.id, firestoreId: c.firestoreId });