@infrab4a/connect-angular 3.6.0-beta.14 → 3.6.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 +258 -600
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/angular-connect.module.js +5 -5
- package/esm2015/angular-firestore.module.js +16 -2
- package/esm2015/angular-hasura-graphql.module.js +8 -74
- package/esm2015/services/cart.service.js +8 -194
- package/esm2015/services/coupon.service.js +41 -26
- package/esm2015/services/shipping.service.js +8 -7
- package/fesm2015/infrab4a-connect-angular.js +86 -308
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +3 -3
- package/services/cart.service.d.ts +2 -7
|
@@ -5,13 +5,13 @@ import { AngularFireAuth } from '@angular/fire/auth';
|
|
|
5
5
|
import { of, combineLatest, from, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
6
6
|
import { catchError, map, mergeMap, concatMap, tap } from 'rxjs/operators';
|
|
7
7
|
import { __awaiter } from 'tslib';
|
|
8
|
-
import * as
|
|
9
|
-
import { Coupon, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository,
|
|
8
|
+
import * as i1$1 from '@infrab4a/connect';
|
|
9
|
+
import { Coupon, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, Status, isNil, NotFoundError, Checkout, pick, LineItem, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, VariantHasuraGraphQLRepository } from '@infrab4a/connect';
|
|
10
10
|
import cookie from 'js-cookie';
|
|
11
11
|
import { CustomError } from 'ts-custom-error';
|
|
12
|
-
import * as i1$
|
|
12
|
+
import * as i1$2 from '@angular/fire/firestore';
|
|
13
13
|
import { AngularFirestore } from '@angular/fire/firestore';
|
|
14
|
-
import * as i1$
|
|
14
|
+
import * as i1$3 from '@angular/common/http';
|
|
15
15
|
import { FIREBASE_OPTIONS, FIREBASE_APP_NAME, AngularFireModule } from '@angular/fire';
|
|
16
16
|
|
|
17
17
|
class AuthService {
|
|
@@ -164,7 +164,7 @@ class CouponService {
|
|
|
164
164
|
// Verifica o limite de uso geral por usuario
|
|
165
165
|
if (coupon.useLimit && orders.data.length >= coupon.useLimit)
|
|
166
166
|
throw new InvalidCouponError('Limite de uso atingido.');
|
|
167
|
-
const validUser = this.userValidationAndSubscriptionStatus(coupon,
|
|
167
|
+
const validUser = yield this.userValidationAndSubscriptionStatus(coupon, userEmail);
|
|
168
168
|
if (!validUser)
|
|
169
169
|
throw new InvalidCouponError('Usuário não elegível.');
|
|
170
170
|
const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
|
|
@@ -209,7 +209,7 @@ class CouponService {
|
|
|
209
209
|
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
|
|
210
210
|
var _a;
|
|
211
211
|
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
212
|
-
return i.categories.some((c) => couponCategories.some(
|
|
212
|
+
return i.categories.some((c) => couponCategories.some(cat => (cat.id == c || cat.firestoreId == c)));
|
|
213
213
|
}
|
|
214
214
|
return true;
|
|
215
215
|
});
|
|
@@ -249,41 +249,56 @@ class CouponService {
|
|
|
249
249
|
return true;
|
|
250
250
|
}
|
|
251
251
|
const couponCategories = yield this.getCouponCategoriesId(coupon);
|
|
252
|
-
const hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(
|
|
252
|
+
const hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(i => {
|
|
253
253
|
var _a;
|
|
254
254
|
if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
255
255
|
return true;
|
|
256
|
-
return i.categories.some((c) => couponCategories.some(
|
|
256
|
+
return i.categories.some((c) => couponCategories.some(cat => (cat.id == c || cat.firestoreId == c)));
|
|
257
257
|
});
|
|
258
258
|
return hasCategories.length ? true : false;
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
|
-
userValidationAndSubscriptionStatus(coupon,
|
|
262
|
-
|
|
261
|
+
userValidationAndSubscriptionStatus(coupon, userEmail) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
// Verifica se o email do usuário é coorporativo
|
|
264
|
+
if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
|
|
265
|
+
throw new InvalidCouponError('Você não é colaborador.');
|
|
266
|
+
// Verifica se o email do usuário é associado ao cupom de uso por usuario
|
|
267
|
+
if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== userEmail)
|
|
268
|
+
throw new InvalidCouponError('Cupom não é válido para este usuário.');
|
|
269
|
+
const couponRuleSubscription = coupon.exclusivityType === Exclusivities.ACTIVE_SUBSCRIBER ||
|
|
270
|
+
coupon.exclusivityType === Exclusivities.INACTIVE_SUBSCRIBER ||
|
|
271
|
+
coupon.exclusivityType === Exclusivities.NON_SUBSCRIBER;
|
|
272
|
+
if (couponRuleSubscription && userEmail) {
|
|
273
|
+
const sub = yield this.subscriptionRepository
|
|
274
|
+
.find({
|
|
275
|
+
filters: {
|
|
276
|
+
user: {
|
|
277
|
+
email: { operator: Where.EQUALS, value: userEmail },
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
.then((sub) => sub.data);
|
|
282
|
+
const activeSubs = sub === null || sub === void 0 ? void 0 : sub.filter((s) => s.status === Status.ACTIVE);
|
|
283
|
+
switch (coupon.exclusivityType) {
|
|
284
|
+
case Exclusivities.ACTIVE_SUBSCRIBER:
|
|
285
|
+
return activeSubs.length > 0;
|
|
286
|
+
case Exclusivities.INACTIVE_SUBSCRIBER:
|
|
287
|
+
return activeSubs.length === 0;
|
|
288
|
+
case Exclusivities.NON_SUBSCRIBER:
|
|
289
|
+
return sub.length === 0;
|
|
290
|
+
default:
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
263
294
|
return true;
|
|
264
|
-
|
|
265
|
-
if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
|
|
266
|
-
throw new InvalidCouponError('Você não é colaborador.');
|
|
267
|
-
// Verifica se o email do usuário é associado ao cupom de uso por usuario
|
|
268
|
-
if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== user.email)
|
|
269
|
-
throw new InvalidCouponError('Cupom não é válido para este usuário.');
|
|
270
|
-
switch (coupon.exclusivityType) {
|
|
271
|
-
case Exclusivities.ACTIVE_SUBSCRIBER:
|
|
272
|
-
return user.isSubscriber ? true : false;
|
|
273
|
-
case Exclusivities.INACTIVE_SUBSCRIBER:
|
|
274
|
-
return user.isSubscriber ? false : true;
|
|
275
|
-
case Exclusivities.NON_SUBSCRIBER:
|
|
276
|
-
return user.isSubscriber ? false : true;
|
|
277
|
-
}
|
|
278
|
-
return true;
|
|
295
|
+
});
|
|
279
296
|
}
|
|
280
297
|
getCouponCategoriesId(coupon) {
|
|
281
298
|
return __awaiter(this, void 0, void 0, function* () {
|
|
282
299
|
let couponCategories = [];
|
|
283
300
|
for (let index = 0; index < coupon.productsCategories.length; index++) {
|
|
284
|
-
let c = yield this.categoryRepository.get({
|
|
285
|
-
id: coupon.productsCategories[index],
|
|
286
|
-
});
|
|
301
|
+
let c = yield this.categoryRepository.get({ id: coupon.productsCategories[index] });
|
|
287
302
|
couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
|
|
288
303
|
}
|
|
289
304
|
return couponCategories;
|
|
@@ -300,7 +315,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
300
315
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
301
316
|
type: Inject,
|
|
302
317
|
args: ['CouponRepository']
|
|
303
|
-
}] }, { type:
|
|
318
|
+
}] }, { type: i1$1.Shops, decorators: [{
|
|
304
319
|
type: Inject,
|
|
305
320
|
args: [DEFAULT_SHOP]
|
|
306
321
|
}] }, { type: undefined, decorators: [{
|
|
@@ -373,18 +388,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
373
388
|
}] }, { type: undefined, decorators: [{
|
|
374
389
|
type: Inject,
|
|
375
390
|
args: ['UserRepository']
|
|
376
|
-
}] }, { type:
|
|
391
|
+
}] }, { type: i1$1.Shops, decorators: [{
|
|
377
392
|
type: Inject,
|
|
378
393
|
args: [DEFAULT_SHOP]
|
|
379
394
|
}] }]; } });
|
|
380
395
|
|
|
381
396
|
class CartService {
|
|
382
|
-
constructor(authService, checkoutService, defaultShop, productRepository
|
|
397
|
+
constructor(authService, checkoutService, defaultShop, productRepository) {
|
|
383
398
|
this.authService = authService;
|
|
384
399
|
this.checkoutService = checkoutService;
|
|
385
400
|
this.defaultShop = defaultShop;
|
|
386
401
|
this.productRepository = productRepository;
|
|
387
|
-
this.buy2WinRepository = buy2WinRepository;
|
|
388
402
|
this.cartSubject = new Subject();
|
|
389
403
|
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
390
404
|
var _a;
|
|
@@ -400,21 +414,6 @@ class CartService {
|
|
|
400
414
|
.updateCheckoutLineItems(checkoutLoaded)
|
|
401
415
|
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
402
416
|
}));
|
|
403
|
-
this.updateLineItemInCartNew = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
404
|
-
var _a;
|
|
405
|
-
const items = [];
|
|
406
|
-
const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
|
|
407
|
-
if (index > -1) {
|
|
408
|
-
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
409
|
-
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
410
|
-
}
|
|
411
|
-
else
|
|
412
|
-
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
413
|
-
return of(checkoutLoaded);
|
|
414
|
-
// return this.checkoutService
|
|
415
|
-
// .updateCheckoutLineItems(checkoutLoaded)
|
|
416
|
-
// .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)))
|
|
417
|
-
}));
|
|
418
417
|
this.generateCartObject = (items) => {
|
|
419
418
|
const cart = {};
|
|
420
419
|
items === null || items === void 0 ? void 0 : items.forEach((item) => {
|
|
@@ -473,11 +472,7 @@ class CartService {
|
|
|
473
472
|
};
|
|
474
473
|
}
|
|
475
474
|
addItem(item, quantity = 1) {
|
|
476
|
-
return from(this.checkoutService.getCheckout()).pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item, quantity: quantity || 1 }); })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)),
|
|
477
|
-
// concatMap(async (updatedCheckout) => await this.checkGifts(updatedCheckout)),
|
|
478
|
-
// concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)),
|
|
479
|
-
// map((checkout) => this.generateCartObject(checkout.lineItems)),
|
|
480
|
-
tap((cart) => this.cartSubject.next(cart)));
|
|
475
|
+
return from(this.checkoutService.getCheckout()).pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item, quantity: quantity || 1 }); })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
|
|
481
476
|
}
|
|
482
477
|
decreaseItem(item) {
|
|
483
478
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
@@ -486,9 +481,7 @@ class CartService {
|
|
|
486
481
|
if (!isNil(checkoutItem))
|
|
487
482
|
checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
|
|
488
483
|
return checkout;
|
|
489
|
-
}),
|
|
490
|
-
// concatMap(async (updatedCheckout) => await this.checkGifts(updatedCheckout)),
|
|
491
|
-
concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
484
|
+
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
492
485
|
}
|
|
493
486
|
getCart(checkout) {
|
|
494
487
|
this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
|
|
@@ -511,12 +504,8 @@ class CartService {
|
|
|
511
504
|
updateUserCart(user) {
|
|
512
505
|
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => __awaiter(this, void 0, void 0, function* () {
|
|
513
506
|
var _a, _b;
|
|
514
|
-
return this.checkoutService
|
|
515
|
-
|
|
516
|
-
? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; })))
|
|
517
|
-
: [] })))
|
|
518
|
-
.toPromise();
|
|
519
|
-
})), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
507
|
+
return this.checkoutService.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length) ? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; }))) : [] }))).toPromise();
|
|
508
|
+
})), map(checkout => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
520
509
|
}
|
|
521
510
|
clearCart() {
|
|
522
511
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
@@ -527,177 +516,17 @@ class CartService {
|
|
|
527
516
|
buildCartFromCheckout(checkoutData) {
|
|
528
517
|
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
529
518
|
}
|
|
530
|
-
checkGifts(checkout) {
|
|
531
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
532
|
-
const campaigns = yield this.buy2WinRepository
|
|
533
|
-
.find({
|
|
534
|
-
filters: {
|
|
535
|
-
active: { operator: Where.EQUALS, value: true },
|
|
536
|
-
shop: { operator: Where.EQUALS, value: this.defaultShop },
|
|
537
|
-
},
|
|
538
|
-
})
|
|
539
|
-
.then((data) => data.data);
|
|
540
|
-
const notGiftItems = checkout.lineItems.filter((item) => !item.isGift);
|
|
541
|
-
if (!campaigns.length)
|
|
542
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
543
|
-
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
544
|
-
const elegibleCampaigns = [];
|
|
545
|
-
for (const campaign of campaigns) {
|
|
546
|
-
// problemas: datas, valorcart e valor cartMin, filtros no código
|
|
547
|
-
const today = new Date();
|
|
548
|
-
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
549
|
-
continue;
|
|
550
|
-
// Passo 2: Verificar se a campanha é por categorias
|
|
551
|
-
if (campaign.activeCategory) {
|
|
552
|
-
const categoriesCampaing = campaign.categories.map((c) => c.id);
|
|
553
|
-
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
554
|
-
var _a;
|
|
555
|
-
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
556
|
-
return true;
|
|
557
|
-
return l.categories.some((c) => categoriesCampaing.some((cat) => cat == c));
|
|
558
|
-
});
|
|
559
|
-
if (filterProductsCategories.length) {
|
|
560
|
-
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
561
|
-
if (cartTotalCategories >= campaign.cartValueMin)
|
|
562
|
-
elegibleCampaigns.push(campaign);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
567
|
-
if (campaign.cartValue <= cartTotal)
|
|
568
|
-
elegibleCampaigns.push(campaign);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
// Passo 2.1: Se não for, apenas valida o preço do carrinho
|
|
572
|
-
// Passo 2.2: Se for, filta lineItens pelas categorias da campanha, valida valor minimo da categoria
|
|
573
|
-
// Passo 3: Se tiver campanha elegiveis, adiciona os produtos ao carrinho
|
|
574
|
-
}
|
|
575
|
-
if (!elegibleCampaigns.length)
|
|
576
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
577
|
-
const campaingnProducts = [];
|
|
578
|
-
for (const campaign of elegibleCampaigns) {
|
|
579
|
-
let elegibleProducts = [];
|
|
580
|
-
for (const product of campaign.products) {
|
|
581
|
-
const productData = yield this.productRepository.get({ sku: product });
|
|
582
|
-
if (!productData)
|
|
583
|
-
continue;
|
|
584
|
-
elegibleProducts.push(productData);
|
|
585
|
-
}
|
|
586
|
-
campaingnProducts.push(elegibleProducts);
|
|
587
|
-
}
|
|
588
|
-
if (!campaingnProducts.length)
|
|
589
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
590
|
-
const productArray = campaingnProducts.reduce((acc, curr) => acc.reduce((aAcc, aCurr) => aAcc + aCurr.price.price, 0) >
|
|
591
|
-
curr.reduce((cAcc, cCurr) => cAcc + cCurr.price.price, 0)
|
|
592
|
-
? acc
|
|
593
|
-
: curr);
|
|
594
|
-
const gifts = this.giftToLineItems(productArray);
|
|
595
|
-
checkout.lineItems = notGiftItems.concat(gifts);
|
|
596
|
-
return checkout;
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
getGifts() {
|
|
600
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => __awaiter(this, void 0, void 0, function* () {
|
|
601
|
-
const campaigns = yield this.buy2WinRepository
|
|
602
|
-
.find({
|
|
603
|
-
filters: {
|
|
604
|
-
active: { operator: Where.EQUALS, value: true },
|
|
605
|
-
shop: { operator: Where.EQUALS, value: this.defaultShop },
|
|
606
|
-
},
|
|
607
|
-
})
|
|
608
|
-
.then((data) => data.data);
|
|
609
|
-
const notGiftItems = checkout.lineItems.filter((item) => !item.isGift);
|
|
610
|
-
if (!campaigns.length)
|
|
611
|
-
return notGiftItems;
|
|
612
|
-
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
613
|
-
const elegibleCampaigns = [];
|
|
614
|
-
for (const campaign of campaigns) {
|
|
615
|
-
// problemas: datas, valorcart e valor cartMin, filtros no código
|
|
616
|
-
const today = new Date();
|
|
617
|
-
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
618
|
-
continue;
|
|
619
|
-
// Passo 2: Verificar se a campanha é por categorias
|
|
620
|
-
if (campaign.activeCategory) {
|
|
621
|
-
const categoriesCampaing = campaign.categories.map((c) => c.id);
|
|
622
|
-
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
623
|
-
var _a;
|
|
624
|
-
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
625
|
-
return true;
|
|
626
|
-
return l.categories.some((c) => categoriesCampaing.some((cat) => cat == c));
|
|
627
|
-
});
|
|
628
|
-
if (filterProductsCategories.length) {
|
|
629
|
-
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
630
|
-
if (cartTotalCategories >= campaign.cartValueMin)
|
|
631
|
-
elegibleCampaigns.push(campaign);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
else {
|
|
635
|
-
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
636
|
-
if (campaign.cartValue <= cartTotal)
|
|
637
|
-
elegibleCampaigns.push(campaign);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
if (!elegibleCampaigns.length)
|
|
642
|
-
return notGiftItems;
|
|
643
|
-
const campaingnProducts = [];
|
|
644
|
-
for (const campaign of elegibleCampaigns) {
|
|
645
|
-
let elegibleProducts = [];
|
|
646
|
-
for (const product of campaign.products) {
|
|
647
|
-
const productData = yield this.productRepository.get({ sku: product });
|
|
648
|
-
if (!productData)
|
|
649
|
-
continue;
|
|
650
|
-
elegibleProducts.push(productData);
|
|
651
|
-
}
|
|
652
|
-
campaingnProducts.push(elegibleProducts);
|
|
653
|
-
}
|
|
654
|
-
if (!campaingnProducts.length)
|
|
655
|
-
return notGiftItems;
|
|
656
|
-
const productArray = campaingnProducts.reduce((acc, curr) => acc.reduce((aAcc, aCurr) => aAcc + aCurr.price.price, 0) >
|
|
657
|
-
curr.reduce((cAcc, cCurr) => cAcc + cCurr.price.price, 0)
|
|
658
|
-
? acc
|
|
659
|
-
: curr);
|
|
660
|
-
const gifts = this.giftToLineItems(productArray);
|
|
661
|
-
return notGiftItems.concat(gifts);
|
|
662
|
-
})));
|
|
663
|
-
}
|
|
664
|
-
giftToLineItems(items) {
|
|
665
|
-
return items.map((item) => {
|
|
666
|
-
var _a;
|
|
667
|
-
const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
668
|
-
const image = ((_a = item === null || item === void 0 ? void 0 : item.miniatures) === null || _a === void 0 ? void 0 : _a.length) ? item.miniatures[0] : item.images[0];
|
|
669
|
-
return LineItem.toInstance({
|
|
670
|
-
brand,
|
|
671
|
-
categories,
|
|
672
|
-
id: id.toString(),
|
|
673
|
-
name,
|
|
674
|
-
price,
|
|
675
|
-
sku,
|
|
676
|
-
slug,
|
|
677
|
-
stock,
|
|
678
|
-
weight,
|
|
679
|
-
EAN,
|
|
680
|
-
image,
|
|
681
|
-
pricePaid: 0,
|
|
682
|
-
quantity: 1,
|
|
683
|
-
isGift: true,
|
|
684
|
-
});
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
519
|
}
|
|
688
|
-
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' }
|
|
520
|
+
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' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
689
521
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
|
|
690
522
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
|
|
691
523
|
type: Injectable
|
|
692
|
-
}], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type:
|
|
524
|
+
}], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$1.Shops, decorators: [{
|
|
693
525
|
type: Inject,
|
|
694
526
|
args: [DEFAULT_SHOP]
|
|
695
527
|
}] }, { type: undefined, decorators: [{
|
|
696
528
|
type: Inject,
|
|
697
529
|
args: ['ProductRepository']
|
|
698
|
-
}] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
|
|
699
|
-
type: Inject,
|
|
700
|
-
args: ['Buy2WinRepository']
|
|
701
530
|
}] }]; } });
|
|
702
531
|
|
|
703
532
|
class CheckoutSubscriptionService {
|
|
@@ -846,7 +675,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
846
675
|
}] }, { type: undefined, decorators: [{
|
|
847
676
|
type: Inject,
|
|
848
677
|
args: ['ProductRepository']
|
|
849
|
-
}] }, { type:
|
|
678
|
+
}] }, { type: i1$1.Shops, decorators: [{
|
|
850
679
|
type: Inject,
|
|
851
680
|
args: [DEFAULT_SHOP]
|
|
852
681
|
}] }]; } });
|
|
@@ -866,11 +695,11 @@ class OrderService {
|
|
|
866
695
|
return this.orderSubject;
|
|
867
696
|
}
|
|
868
697
|
}
|
|
869
|
-
OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$
|
|
698
|
+
OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$2.AngularFirestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
870
699
|
OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
|
|
871
700
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
|
|
872
701
|
type: Injectable
|
|
873
|
-
}], ctorParameters: function () { return [{ type: i1$
|
|
702
|
+
}], ctorParameters: function () { return [{ type: i1$2.AngularFirestore }, { type: i1$1.OrderFirestoreRepository, decorators: [{
|
|
874
703
|
type: Inject,
|
|
875
704
|
args: ['OrderRepository']
|
|
876
705
|
}] }]; } });
|
|
@@ -884,12 +713,13 @@ class ShippingService {
|
|
|
884
713
|
getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
|
|
885
714
|
return combineLatest([
|
|
886
715
|
this.homeService.getHomeData(),
|
|
887
|
-
this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`)
|
|
888
|
-
])
|
|
716
|
+
this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`)
|
|
717
|
+
])
|
|
718
|
+
.pipe(map(([datas, shippingMethodsResponse]) => {
|
|
889
719
|
let shippingMethods = shippingMethodsResponse.result;
|
|
890
720
|
if (!shippingMethods.length)
|
|
891
721
|
return [];
|
|
892
|
-
shippingMethods = shippingMethods.map(
|
|
722
|
+
shippingMethods = shippingMethods.map(s => {
|
|
893
723
|
if (s.ShippingCompanyName == 'Same Day EG')
|
|
894
724
|
s.ShippingCompanyName = 'Same Day';
|
|
895
725
|
else
|
|
@@ -900,7 +730,7 @@ class ShippingService {
|
|
|
900
730
|
shippingMethods = shippingMethods.filter((method) => method.ShippingCompanyName !== 'Same Day');
|
|
901
731
|
}
|
|
902
732
|
if (totalPrice >= 200) {
|
|
903
|
-
shippingMethods = shippingMethods.map(
|
|
733
|
+
shippingMethods = shippingMethods.map(s => {
|
|
904
734
|
if (s.serviceName !== 'Same Day')
|
|
905
735
|
return Object.assign(Object.assign({}, s), { totalPrice: 0 });
|
|
906
736
|
else
|
|
@@ -910,7 +740,7 @@ class ShippingService {
|
|
|
910
740
|
if (shop == Shops.GLAMSHOP)
|
|
911
741
|
return shippingMethods;
|
|
912
742
|
if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
|
|
913
|
-
shippingMethods = shippingMethods.map(
|
|
743
|
+
shippingMethods = shippingMethods.map(s => {
|
|
914
744
|
if (s.serviceName == 'Same Day')
|
|
915
745
|
return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
|
|
916
746
|
else
|
|
@@ -918,7 +748,7 @@ class ShippingService {
|
|
|
918
748
|
});
|
|
919
749
|
}
|
|
920
750
|
if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
|
|
921
|
-
shippingMethods = shippingMethods.map(
|
|
751
|
+
shippingMethods = shippingMethods.map(s => {
|
|
922
752
|
return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
|
|
923
753
|
});
|
|
924
754
|
}
|
|
@@ -954,11 +784,11 @@ class ShippingService {
|
|
|
954
784
|
return false;
|
|
955
785
|
}
|
|
956
786
|
}
|
|
957
|
-
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, deps: [{ token: i1$
|
|
787
|
+
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, deps: [{ token: i1$3.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
958
788
|
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService });
|
|
959
789
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, decorators: [{
|
|
960
790
|
type: Injectable
|
|
961
|
-
}], ctorParameters: function () { return [{ type: i1$
|
|
791
|
+
}], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
|
|
962
792
|
type: Inject,
|
|
963
793
|
args: [BACKEND_URL]
|
|
964
794
|
}] }, { type: HomeShopService }]; } });
|
|
@@ -1218,6 +1048,13 @@ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0",
|
|
|
1218
1048
|
},
|
|
1219
1049
|
deps: [AngularFirestore],
|
|
1220
1050
|
},
|
|
1051
|
+
{
|
|
1052
|
+
provide: 'ShopSettingsRepository',
|
|
1053
|
+
useFactory: (firestore) => {
|
|
1054
|
+
return new ShopSettingsFirestoreRepository(firestore.firestore);
|
|
1055
|
+
},
|
|
1056
|
+
deps: [AngularFirestore],
|
|
1057
|
+
},
|
|
1221
1058
|
{
|
|
1222
1059
|
provide: 'SubscriptionPaymentRepository',
|
|
1223
1060
|
useFactory: (firestore, subscriptionRepository) => {
|
|
@@ -1384,6 +1221,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
1384
1221
|
},
|
|
1385
1222
|
deps: [AngularFirestore],
|
|
1386
1223
|
},
|
|
1224
|
+
{
|
|
1225
|
+
provide: 'ShopSettingsRepository',
|
|
1226
|
+
useFactory: (firestore) => {
|
|
1227
|
+
return new ShopSettingsFirestoreRepository(firestore.firestore);
|
|
1228
|
+
},
|
|
1229
|
+
deps: [AngularFirestore],
|
|
1230
|
+
},
|
|
1387
1231
|
{
|
|
1388
1232
|
provide: 'SubscriptionPaymentRepository',
|
|
1389
1233
|
useFactory: (firestore, subscriptionRepository) => {
|
|
@@ -1467,10 +1311,10 @@ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.
|
|
|
1467
1311
|
},
|
|
1468
1312
|
{
|
|
1469
1313
|
provide: CategoryHasuraGraphQLRepository,
|
|
1470
|
-
useFactory: (options, productRepository
|
|
1471
|
-
return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository
|
|
1314
|
+
useFactory: (options, productRepository) => {
|
|
1315
|
+
return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
|
|
1472
1316
|
},
|
|
1473
|
-
deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository
|
|
1317
|
+
deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
|
|
1474
1318
|
},
|
|
1475
1319
|
{
|
|
1476
1320
|
provide: 'ProductRepository',
|
|
@@ -1494,39 +1338,6 @@ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.
|
|
|
1494
1338
|
},
|
|
1495
1339
|
deps: [HASURA_OPTIONS],
|
|
1496
1340
|
},
|
|
1497
|
-
{
|
|
1498
|
-
provide: 'CategoryFilterRepository',
|
|
1499
|
-
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1500
|
-
},
|
|
1501
|
-
{
|
|
1502
|
-
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1503
|
-
useFactory: (options) => {
|
|
1504
|
-
return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1505
|
-
},
|
|
1506
|
-
deps: [HASURA_OPTIONS],
|
|
1507
|
-
},
|
|
1508
|
-
{
|
|
1509
|
-
provide: 'FilterOptionRepository',
|
|
1510
|
-
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1511
|
-
},
|
|
1512
|
-
{
|
|
1513
|
-
provide: FilterOptionHasuraGraphQLRepository,
|
|
1514
|
-
useFactory: (options) => {
|
|
1515
|
-
return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1516
|
-
},
|
|
1517
|
-
deps: [HASURA_OPTIONS],
|
|
1518
|
-
},
|
|
1519
|
-
{
|
|
1520
|
-
provide: 'FilterRepository',
|
|
1521
|
-
useExisting: FilterHasuraGraphQLRepository,
|
|
1522
|
-
},
|
|
1523
|
-
{
|
|
1524
|
-
provide: FilterHasuraGraphQLRepository,
|
|
1525
|
-
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
1526
|
-
return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
|
|
1527
|
-
},
|
|
1528
|
-
deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1529
|
-
},
|
|
1530
1341
|
] });
|
|
1531
1342
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
|
|
1532
1343
|
type: NgModule,
|
|
@@ -1538,10 +1349,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
1538
1349
|
},
|
|
1539
1350
|
{
|
|
1540
1351
|
provide: CategoryHasuraGraphQLRepository,
|
|
1541
|
-
useFactory: (options, productRepository
|
|
1542
|
-
return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository
|
|
1352
|
+
useFactory: (options, productRepository) => {
|
|
1353
|
+
return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
|
|
1543
1354
|
},
|
|
1544
|
-
deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository
|
|
1355
|
+
deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
|
|
1545
1356
|
},
|
|
1546
1357
|
{
|
|
1547
1358
|
provide: 'ProductRepository',
|
|
@@ -1565,39 +1376,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
1565
1376
|
},
|
|
1566
1377
|
deps: [HASURA_OPTIONS],
|
|
1567
1378
|
},
|
|
1568
|
-
{
|
|
1569
|
-
provide: 'CategoryFilterRepository',
|
|
1570
|
-
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1571
|
-
},
|
|
1572
|
-
{
|
|
1573
|
-
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1574
|
-
useFactory: (options) => {
|
|
1575
|
-
return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1576
|
-
},
|
|
1577
|
-
deps: [HASURA_OPTIONS],
|
|
1578
|
-
},
|
|
1579
|
-
{
|
|
1580
|
-
provide: 'FilterOptionRepository',
|
|
1581
|
-
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1582
|
-
},
|
|
1583
|
-
{
|
|
1584
|
-
provide: FilterOptionHasuraGraphQLRepository,
|
|
1585
|
-
useFactory: (options) => {
|
|
1586
|
-
return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1587
|
-
},
|
|
1588
|
-
deps: [HASURA_OPTIONS],
|
|
1589
|
-
},
|
|
1590
|
-
{
|
|
1591
|
-
provide: 'FilterRepository',
|
|
1592
|
-
useExisting: FilterHasuraGraphQLRepository,
|
|
1593
|
-
},
|
|
1594
|
-
{
|
|
1595
|
-
provide: FilterHasuraGraphQLRepository,
|
|
1596
|
-
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
1597
|
-
return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
|
|
1598
|
-
},
|
|
1599
|
-
deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1600
|
-
},
|
|
1601
1379
|
],
|
|
1602
1380
|
}]
|
|
1603
1381
|
}] });
|
|
@@ -1627,7 +1405,7 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
|
|
|
1627
1405
|
CouponService,
|
|
1628
1406
|
HomeShopService,
|
|
1629
1407
|
OrderService,
|
|
1630
|
-
ShippingService
|
|
1408
|
+
ShippingService
|
|
1631
1409
|
], imports: [[AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
|
|
1632
1410
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
|
|
1633
1411
|
type: NgModule,
|
|
@@ -1641,7 +1419,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
1641
1419
|
CouponService,
|
|
1642
1420
|
HomeShopService,
|
|
1643
1421
|
OrderService,
|
|
1644
|
-
ShippingService
|
|
1422
|
+
ShippingService
|
|
1645
1423
|
],
|
|
1646
1424
|
}]
|
|
1647
1425
|
}] });
|