@infrab4a/connect-angular 4.0.0-beta.10 → 4.0.0-beta.12
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/esm2020/angular-connect.module.mjs +1 -1
- package/esm2020/angular-firestore.module.mjs +44 -2
- package/esm2020/angular-hasura-graphql.module.mjs +74 -8
- package/esm2020/services/cart.service.mjs +130 -22
- package/esm2020/services/checkout-subscription.service.mjs +5 -3
- package/esm2020/services/checkout.service.mjs +2 -2
- package/esm2020/services/coupon.service.mjs +20 -37
- package/esm2020/services/shipping.service.mjs +3 -4
- package/fesm2015/infrab4a-connect-angular.mjs +281 -85
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +279 -79
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +7 -2
- package/services/coupon.service.d.ts +2 -3
|
@@ -5,14 +5,14 @@ import { getIdToken, authState, Auth, provideAuth, getAuth } from '@angular/fire
|
|
|
5
5
|
import { combineLatest, of, from, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
6
6
|
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
7
7
|
import { __awaiter } from 'tslib';
|
|
8
|
-
import * as
|
|
9
|
-
import { Where, Shops, CheckoutTypes, CouponTypes, Exclusivities,
|
|
8
|
+
import * as i3 from '@infrab4a/connect';
|
|
9
|
+
import { 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, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository } 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$1 from '@angular/fire/firestore';
|
|
13
13
|
import { docSnapshots, doc, Firestore, provideFirestore, getFirestore } from '@angular/fire/firestore';
|
|
14
|
-
import * as i1$
|
|
15
|
-
import * as i1$
|
|
14
|
+
import * as i1$2 from '@angular/common/http';
|
|
15
|
+
import * as i1$3 from '@angular/fire/app';
|
|
16
16
|
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
17
17
|
import { isPlatformBrowser } from '@angular/common';
|
|
18
18
|
|
|
@@ -74,11 +74,10 @@ class GroupInvalidCouponError extends CustomError {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
class CouponService {
|
|
77
|
-
constructor(couponRepository, defaultShop, orderRepository,
|
|
77
|
+
constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
|
|
78
78
|
this.couponRepository = couponRepository;
|
|
79
79
|
this.defaultShop = defaultShop;
|
|
80
80
|
this.orderRepository = orderRepository;
|
|
81
|
-
this.subscriptionRepository = subscriptionRepository;
|
|
82
81
|
this.categoryRepository = categoryRepository;
|
|
83
82
|
this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
|
|
84
83
|
}
|
|
@@ -119,7 +118,7 @@ class CouponService {
|
|
|
119
118
|
const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
|
|
120
119
|
// Se não tem valor mínimo atingido, retorna erro
|
|
121
120
|
if (!hasMinSubTotal)
|
|
122
|
-
return throwError(
|
|
121
|
+
return throwError(`Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`);
|
|
123
122
|
return of(coupon);
|
|
124
123
|
}
|
|
125
124
|
isValidCoupon(coupon, userEmail) {
|
|
@@ -147,7 +146,7 @@ class CouponService {
|
|
|
147
146
|
// Verifica o limite de uso geral por usuario
|
|
148
147
|
if (coupon.useLimit && orders.data.length >= coupon.useLimit)
|
|
149
148
|
throw new InvalidCouponError('Limite de uso atingido.');
|
|
150
|
-
const validUser =
|
|
149
|
+
const validUser = this.userValidationAndSubscriptionStatus(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
151
150
|
if (!validUser)
|
|
152
151
|
throw new InvalidCouponError('Usuário não elegível.');
|
|
153
152
|
const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
|
|
@@ -241,41 +240,26 @@ class CouponService {
|
|
|
241
240
|
return hasCategories.length ? true : false;
|
|
242
241
|
});
|
|
243
242
|
}
|
|
244
|
-
userValidationAndSubscriptionStatus(coupon,
|
|
245
|
-
|
|
246
|
-
// Verifica se o email do usuário é coorporativo
|
|
247
|
-
if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
|
|
248
|
-
throw new InvalidCouponError('Você não é colaborador.');
|
|
249
|
-
// Verifica se o email do usuário é associado ao cupom de uso por usuario
|
|
250
|
-
if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== userEmail)
|
|
251
|
-
throw new InvalidCouponError('Cupom não é válido para este usuário.');
|
|
252
|
-
const couponRuleSubscription = coupon.exclusivityType === Exclusivities.ACTIVE_SUBSCRIBER ||
|
|
253
|
-
coupon.exclusivityType === Exclusivities.INACTIVE_SUBSCRIBER ||
|
|
254
|
-
coupon.exclusivityType === Exclusivities.NON_SUBSCRIBER;
|
|
255
|
-
if (couponRuleSubscription && userEmail) {
|
|
256
|
-
const sub = yield this.subscriptionRepository
|
|
257
|
-
.find({
|
|
258
|
-
filters: {
|
|
259
|
-
user: {
|
|
260
|
-
email: { operator: Where.EQUALS, value: userEmail },
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
})
|
|
264
|
-
.then((sub) => sub.data);
|
|
265
|
-
const activeSubs = sub === null || sub === void 0 ? void 0 : sub.filter((s) => s.status === Status.ACTIVE);
|
|
266
|
-
switch (coupon.exclusivityType) {
|
|
267
|
-
case Exclusivities.ACTIVE_SUBSCRIBER:
|
|
268
|
-
return activeSubs.length > 0;
|
|
269
|
-
case Exclusivities.INACTIVE_SUBSCRIBER:
|
|
270
|
-
return activeSubs.length === 0;
|
|
271
|
-
case Exclusivities.NON_SUBSCRIBER:
|
|
272
|
-
return sub.length === 0;
|
|
273
|
-
default:
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
243
|
+
userValidationAndSubscriptionStatus(coupon, user) {
|
|
244
|
+
if (coupon.exclusivityType === Exclusivities.ALL_USERS)
|
|
277
245
|
return true;
|
|
278
|
-
|
|
246
|
+
if (!user)
|
|
247
|
+
return true;
|
|
248
|
+
// Verifica se o email do usuário é coorporativo
|
|
249
|
+
if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
|
|
250
|
+
throw new InvalidCouponError('Você não é colaborador.');
|
|
251
|
+
// Verifica se o email do usuário é associado ao cupom de uso por usuario
|
|
252
|
+
if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== user.email)
|
|
253
|
+
throw new InvalidCouponError('Cupom não é válido para este usuário.');
|
|
254
|
+
switch (coupon.exclusivityType) {
|
|
255
|
+
case Exclusivities.ACTIVE_SUBSCRIBER:
|
|
256
|
+
return user.isSubscriber ? true : false;
|
|
257
|
+
case Exclusivities.INACTIVE_SUBSCRIBER:
|
|
258
|
+
return user.isSubscriber ? false : true;
|
|
259
|
+
case Exclusivities.NON_SUBSCRIBER:
|
|
260
|
+
return user.isSubscriber ? false : true;
|
|
261
|
+
}
|
|
262
|
+
return true;
|
|
279
263
|
}
|
|
280
264
|
getCouponCategoriesId(coupon) {
|
|
281
265
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -290,7 +274,7 @@ class CouponService {
|
|
|
290
274
|
});
|
|
291
275
|
}
|
|
292
276
|
}
|
|
293
|
-
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: '
|
|
277
|
+
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
294
278
|
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
295
279
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
296
280
|
type: Injectable,
|
|
@@ -301,15 +285,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
301
285
|
return [{ type: undefined, decorators: [{
|
|
302
286
|
type: Inject,
|
|
303
287
|
args: ['CouponRepository']
|
|
304
|
-
}] }, { type:
|
|
288
|
+
}] }, { type: i3.Shops, decorators: [{
|
|
305
289
|
type: Inject,
|
|
306
290
|
args: [DEFAULT_SHOP]
|
|
307
291
|
}] }, { type: undefined, decorators: [{
|
|
308
292
|
type: Inject,
|
|
309
293
|
args: ['OrderRepository']
|
|
310
|
-
}] }, { type: undefined, decorators: [{
|
|
311
|
-
type: Inject,
|
|
312
|
-
args: ['SubscriptionRepository']
|
|
313
294
|
}] }, { type: undefined, decorators: [{
|
|
314
295
|
type: Inject,
|
|
315
296
|
args: ['CategoryRepository']
|
|
@@ -376,23 +357,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
376
357
|
}] }, { type: undefined, decorators: [{
|
|
377
358
|
type: Inject,
|
|
378
359
|
args: ['UserRepository']
|
|
379
|
-
}] }, { type:
|
|
360
|
+
}] }, { type: i3.Shops, decorators: [{
|
|
380
361
|
type: Inject,
|
|
381
362
|
args: [DEFAULT_SHOP]
|
|
382
363
|
}] }];
|
|
383
364
|
} });
|
|
384
365
|
|
|
385
366
|
class CartService {
|
|
386
|
-
constructor(authService, checkoutService, defaultShop, productRepository) {
|
|
367
|
+
constructor(authService, checkoutService, defaultShop, productRepository, variantRepository, buy2WinRepository) {
|
|
387
368
|
this.authService = authService;
|
|
388
369
|
this.checkoutService = checkoutService;
|
|
389
370
|
this.defaultShop = defaultShop;
|
|
390
371
|
this.productRepository = productRepository;
|
|
372
|
+
this.variantRepository = variantRepository;
|
|
373
|
+
this.buy2WinRepository = buy2WinRepository;
|
|
391
374
|
this.cartSubject = new Subject();
|
|
392
375
|
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
393
376
|
var _a;
|
|
394
377
|
const items = [];
|
|
395
|
-
const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.
|
|
378
|
+
const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
396
379
|
if (index > -1) {
|
|
397
380
|
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
398
381
|
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
@@ -403,22 +386,18 @@ class CartService {
|
|
|
403
386
|
.updateCheckoutLineItems(checkoutLoaded)
|
|
404
387
|
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
405
388
|
}));
|
|
406
|
-
this.generateCartObject = (items) => {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
return (cart[item.sku] = LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.sku] || item)), { quantity: (((_a = cart[item.sku]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })));
|
|
411
|
-
});
|
|
412
|
-
return cart;
|
|
413
|
-
};
|
|
389
|
+
this.generateCartObject = (items) => items.reduce((cart, item) => {
|
|
390
|
+
var _a;
|
|
391
|
+
return (Object.assign(Object.assign({}, cart), { [item.id]: LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })) }));
|
|
392
|
+
}, {});
|
|
414
393
|
this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
|
|
415
394
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
416
|
-
const product = yield this.
|
|
417
|
-
item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.
|
|
395
|
+
const product = yield this.getProductData(item.id);
|
|
396
|
+
item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
|
|
418
397
|
if (this.checkMaxStock(item, quantity || 0))
|
|
419
398
|
throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
|
|
420
399
|
const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
|
|
421
|
-
const { id, name, EAN,
|
|
400
|
+
const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
|
|
422
401
|
const isGift = item.isGift || null;
|
|
423
402
|
const pricePaid = this.getProductPrice({
|
|
424
403
|
product: item,
|
|
@@ -466,7 +445,7 @@ class CartService {
|
|
|
466
445
|
decreaseItem(item) {
|
|
467
446
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
468
447
|
var _a;
|
|
469
|
-
const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.
|
|
448
|
+
const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
|
|
470
449
|
if (!isNil(checkoutItem))
|
|
471
450
|
checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
|
|
472
451
|
return checkout;
|
|
@@ -484,7 +463,7 @@ class CartService {
|
|
|
484
463
|
}
|
|
485
464
|
removeItem(item) {
|
|
486
465
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
487
|
-
const index = checkout.lineItems.findIndex((lineItem) => lineItem.
|
|
466
|
+
const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
|
|
488
467
|
if (index >= 0)
|
|
489
468
|
checkout.lineItems.splice(index, 1);
|
|
490
469
|
return checkout;
|
|
@@ -493,8 +472,12 @@ class CartService {
|
|
|
493
472
|
updateUserCart(user) {
|
|
494
473
|
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* () {
|
|
495
474
|
var _a, _b;
|
|
496
|
-
return this.checkoutService
|
|
497
|
-
|
|
475
|
+
return this.checkoutService
|
|
476
|
+
.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
|
|
477
|
+
? 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; })))
|
|
478
|
+
: [] })))
|
|
479
|
+
.toPromise();
|
|
480
|
+
})), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
498
481
|
}
|
|
499
482
|
clearCart() {
|
|
500
483
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
@@ -505,18 +488,122 @@ class CartService {
|
|
|
505
488
|
buildCartFromCheckout(checkoutData) {
|
|
506
489
|
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
507
490
|
}
|
|
491
|
+
getProductData(productId) {
|
|
492
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
493
|
+
let product;
|
|
494
|
+
let variant;
|
|
495
|
+
try {
|
|
496
|
+
product = yield this.productRepository.get({ id: productId });
|
|
497
|
+
}
|
|
498
|
+
catch (error) {
|
|
499
|
+
if (!(error instanceof NotFoundError))
|
|
500
|
+
throw error;
|
|
501
|
+
variant = yield this.variantRepository.get({ id: productId });
|
|
502
|
+
product = yield this.productRepository.get({ id: variant.productId });
|
|
503
|
+
}
|
|
504
|
+
return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
getGifts() {
|
|
508
|
+
return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
|
|
509
|
+
const campaigns = yield this.buy2WinRepository
|
|
510
|
+
.find({
|
|
511
|
+
filters: {
|
|
512
|
+
active: { operator: Where.EQUALS, value: true },
|
|
513
|
+
shop: { operator: Where.EQUALS, value: this.defaultShop },
|
|
514
|
+
},
|
|
515
|
+
})
|
|
516
|
+
.then((data) => data.data);
|
|
517
|
+
const notGiftItems = checkout.lineItems.filter((item) => !item.isGift);
|
|
518
|
+
if (!campaigns.length)
|
|
519
|
+
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
520
|
+
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
521
|
+
const elegibleCampaigns = [];
|
|
522
|
+
for (const campaign of campaigns) {
|
|
523
|
+
const today = new Date();
|
|
524
|
+
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
525
|
+
continue;
|
|
526
|
+
if (campaign.activeCategory) {
|
|
527
|
+
const categoriesCampaing = campaign.categories.map((c) => c.id);
|
|
528
|
+
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
529
|
+
var _a;
|
|
530
|
+
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
531
|
+
return true;
|
|
532
|
+
return l.categories.some((c) => categoriesCampaing.some((cat) => cat == c));
|
|
533
|
+
});
|
|
534
|
+
if (filterProductsCategories.length) {
|
|
535
|
+
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
536
|
+
if (cartTotalCategories >= campaign.cartValueMin)
|
|
537
|
+
elegibleCampaigns.push(campaign);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
542
|
+
if (campaign.cartValue <= cartTotal)
|
|
543
|
+
elegibleCampaigns.push(campaign);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (!elegibleCampaigns.length)
|
|
548
|
+
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
549
|
+
const campaingnProducts = [];
|
|
550
|
+
for (const campaign of elegibleCampaigns) {
|
|
551
|
+
let elegibleProducts = [];
|
|
552
|
+
for (const product of campaign.products) {
|
|
553
|
+
const productData = yield this.productRepository.get({ sku: product });
|
|
554
|
+
if (!productData)
|
|
555
|
+
continue;
|
|
556
|
+
elegibleProducts.push(productData);
|
|
557
|
+
}
|
|
558
|
+
campaingnProducts.push(elegibleProducts);
|
|
559
|
+
}
|
|
560
|
+
if (!campaingnProducts.length)
|
|
561
|
+
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
562
|
+
const gifts = this.giftToLineItems([].concat(...campaingnProducts));
|
|
563
|
+
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
|
|
564
|
+
})), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
565
|
+
}
|
|
566
|
+
giftToLineItems(items) {
|
|
567
|
+
return items.map((item) => {
|
|
568
|
+
var _a;
|
|
569
|
+
const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
570
|
+
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];
|
|
571
|
+
return LineItem.toInstance({
|
|
572
|
+
brand,
|
|
573
|
+
categories,
|
|
574
|
+
id: id.toString(),
|
|
575
|
+
name,
|
|
576
|
+
price,
|
|
577
|
+
sku,
|
|
578
|
+
slug,
|
|
579
|
+
stock,
|
|
580
|
+
weight,
|
|
581
|
+
EAN,
|
|
582
|
+
image,
|
|
583
|
+
pricePaid: 0,
|
|
584
|
+
quantity: 1,
|
|
585
|
+
isGift: true,
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
}
|
|
508
589
|
}
|
|
509
|
-
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
590
|
+
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
510
591
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
511
592
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
512
593
|
type: Injectable
|
|
513
594
|
}], ctorParameters: function () {
|
|
514
|
-
return [{ type: AuthService }, { type: CheckoutService }, { type:
|
|
595
|
+
return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
|
|
515
596
|
type: Inject,
|
|
516
597
|
args: [DEFAULT_SHOP]
|
|
517
598
|
}] }, { type: undefined, decorators: [{
|
|
518
599
|
type: Inject,
|
|
519
600
|
args: ['ProductRepository']
|
|
601
|
+
}] }, { type: undefined, decorators: [{
|
|
602
|
+
type: Inject,
|
|
603
|
+
args: ['VariantRepository']
|
|
604
|
+
}] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
|
|
605
|
+
type: Inject,
|
|
606
|
+
args: ['Buy2WinRepository']
|
|
520
607
|
}] }];
|
|
521
608
|
} });
|
|
522
609
|
|
|
@@ -544,7 +631,9 @@ class CheckoutSubscriptionService {
|
|
|
544
631
|
return of();
|
|
545
632
|
}
|
|
546
633
|
checkCoupon(nickname, userEmail) {
|
|
547
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
634
|
+
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
635
|
+
.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
|
|
636
|
+
.pipe()));
|
|
548
637
|
}
|
|
549
638
|
calcDiscountSubscription(coupon) {
|
|
550
639
|
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
@@ -670,7 +759,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
670
759
|
}] }, { type: undefined, decorators: [{
|
|
671
760
|
type: Inject,
|
|
672
761
|
args: ['ProductRepository']
|
|
673
|
-
}] }, { type:
|
|
762
|
+
}] }, { type: i3.Shops, decorators: [{
|
|
674
763
|
type: Inject,
|
|
675
764
|
args: [DEFAULT_SHOP]
|
|
676
765
|
}] }];
|
|
@@ -689,12 +778,12 @@ class OrderService {
|
|
|
689
778
|
return this.orderSubject;
|
|
690
779
|
}
|
|
691
780
|
}
|
|
692
|
-
OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, deps: [{ token: i1$
|
|
781
|
+
OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, deps: [{ token: i1$1.Firestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
693
782
|
OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
|
|
694
783
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
695
784
|
type: Injectable
|
|
696
785
|
}], ctorParameters: function () {
|
|
697
|
-
return [{ type: i1$
|
|
786
|
+
return [{ type: i1$1.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
|
|
698
787
|
type: Inject,
|
|
699
788
|
args: ['OrderRepository']
|
|
700
789
|
}] }];
|
|
@@ -721,7 +810,7 @@ class ShippingService {
|
|
|
721
810
|
});
|
|
722
811
|
const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
|
|
723
812
|
if (this.isHolidays(datasSameDayNotAvaliable)) {
|
|
724
|
-
shippingMethods = shippingMethods.filter((method) => method.
|
|
813
|
+
shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
|
|
725
814
|
}
|
|
726
815
|
if (totalPrice >= 200) {
|
|
727
816
|
shippingMethods = shippingMethods.map((s) => {
|
|
@@ -752,9 +841,8 @@ class ShippingService {
|
|
|
752
841
|
isFreeShippingBySubscription(shop, subscriptionPlan) {
|
|
753
842
|
if (!subscriptionPlan)
|
|
754
843
|
return false;
|
|
755
|
-
if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
|
|
844
|
+
if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
|
|
756
845
|
return true;
|
|
757
|
-
}
|
|
758
846
|
return false;
|
|
759
847
|
}
|
|
760
848
|
isHalfShippingBySubscription(shop, subscriptionPlan) {
|
|
@@ -778,12 +866,12 @@ class ShippingService {
|
|
|
778
866
|
return false;
|
|
779
867
|
}
|
|
780
868
|
}
|
|
781
|
-
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i1$
|
|
869
|
+
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i1$2.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
782
870
|
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
|
|
783
871
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
|
|
784
872
|
type: Injectable
|
|
785
873
|
}], ctorParameters: function () {
|
|
786
|
-
return [{ type: i1$
|
|
874
|
+
return [{ type: i1$2.HttpClient }, { type: undefined, decorators: [{
|
|
787
875
|
type: Inject,
|
|
788
876
|
args: [BACKEND_URL]
|
|
789
877
|
}] }, { type: HomeShopService }];
|
|
@@ -801,7 +889,7 @@ class AngularFirebaseAuthModule {
|
|
|
801
889
|
}
|
|
802
890
|
}
|
|
803
891
|
AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
804
|
-
AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1$
|
|
892
|
+
AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1$3.FirebaseAppModule, i1.AuthModule] });
|
|
805
893
|
AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
|
|
806
894
|
{
|
|
807
895
|
provide: 'Authentication',
|
|
@@ -958,7 +1046,7 @@ class AngularFirestoreModule {
|
|
|
958
1046
|
}
|
|
959
1047
|
}
|
|
960
1048
|
AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
961
|
-
AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$
|
|
1049
|
+
AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$3.FirebaseAppModule, i1$1.FirestoreModule] });
|
|
962
1050
|
AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, providers: [
|
|
963
1051
|
{
|
|
964
1052
|
provide: 'FirestoreOptions',
|
|
@@ -1024,6 +1112,20 @@ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0",
|
|
|
1024
1112
|
},
|
|
1025
1113
|
deps: ['FirestoreOptions'],
|
|
1026
1114
|
},
|
|
1115
|
+
{
|
|
1116
|
+
provide: 'CampaignHashtagRepository',
|
|
1117
|
+
useFactory: (options) => {
|
|
1118
|
+
return new CampaignHashtagFirestoreRepository(options);
|
|
1119
|
+
},
|
|
1120
|
+
deps: [Firestore],
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
provide: 'CampaignDashboardRepository',
|
|
1124
|
+
useFactory: (options) => {
|
|
1125
|
+
return new CampaignDashboardFirestoreRepository(options);
|
|
1126
|
+
},
|
|
1127
|
+
deps: [Firestore],
|
|
1128
|
+
},
|
|
1027
1129
|
{
|
|
1028
1130
|
provide: 'EditionRepository',
|
|
1029
1131
|
useFactory: (options, subscriptionRepository) => {
|
|
@@ -1080,6 +1182,13 @@ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0",
|
|
|
1080
1182
|
},
|
|
1081
1183
|
deps: ['FirestoreOptions'],
|
|
1082
1184
|
},
|
|
1185
|
+
{
|
|
1186
|
+
provide: 'ShopSettingsRepository',
|
|
1187
|
+
useFactory: (options) => {
|
|
1188
|
+
return new ShopSettingsFirestoreRepository(options);
|
|
1189
|
+
},
|
|
1190
|
+
deps: [Firestore],
|
|
1191
|
+
},
|
|
1083
1192
|
{
|
|
1084
1193
|
provide: 'SubscriptionPaymentRepository',
|
|
1085
1194
|
useFactory: (options, subscriptionRepository) => {
|
|
@@ -1222,6 +1331,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1222
1331
|
},
|
|
1223
1332
|
deps: ['FirestoreOptions'],
|
|
1224
1333
|
},
|
|
1334
|
+
{
|
|
1335
|
+
provide: 'CampaignHashtagRepository',
|
|
1336
|
+
useFactory: (options) => {
|
|
1337
|
+
return new CampaignHashtagFirestoreRepository(options);
|
|
1338
|
+
},
|
|
1339
|
+
deps: [Firestore],
|
|
1340
|
+
},
|
|
1341
|
+
{
|
|
1342
|
+
provide: 'CampaignDashboardRepository',
|
|
1343
|
+
useFactory: (options) => {
|
|
1344
|
+
return new CampaignDashboardFirestoreRepository(options);
|
|
1345
|
+
},
|
|
1346
|
+
deps: [Firestore],
|
|
1347
|
+
},
|
|
1225
1348
|
{
|
|
1226
1349
|
provide: 'EditionRepository',
|
|
1227
1350
|
useFactory: (options, subscriptionRepository) => {
|
|
@@ -1278,6 +1401,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1278
1401
|
},
|
|
1279
1402
|
deps: ['FirestoreOptions'],
|
|
1280
1403
|
},
|
|
1404
|
+
{
|
|
1405
|
+
provide: 'ShopSettingsRepository',
|
|
1406
|
+
useFactory: (options) => {
|
|
1407
|
+
return new ShopSettingsFirestoreRepository(options);
|
|
1408
|
+
},
|
|
1409
|
+
deps: [Firestore],
|
|
1410
|
+
},
|
|
1281
1411
|
{
|
|
1282
1412
|
provide: 'SubscriptionPaymentRepository',
|
|
1283
1413
|
useFactory: (options, subscriptionRepository) => {
|
|
@@ -1378,10 +1508,10 @@ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.
|
|
|
1378
1508
|
},
|
|
1379
1509
|
{
|
|
1380
1510
|
provide: CategoryHasuraGraphQLRepository,
|
|
1381
|
-
useFactory: (
|
|
1382
|
-
return new CategoryHasuraGraphQLRepository(
|
|
1511
|
+
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
1512
|
+
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
1383
1513
|
},
|
|
1384
|
-
deps: [
|
|
1514
|
+
deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1385
1515
|
},
|
|
1386
1516
|
{
|
|
1387
1517
|
provide: 'ProductRepository',
|
|
@@ -1405,6 +1535,39 @@ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.
|
|
|
1405
1535
|
},
|
|
1406
1536
|
deps: ['HasuraConfig'],
|
|
1407
1537
|
},
|
|
1538
|
+
{
|
|
1539
|
+
provide: 'CategoryFilterRepository',
|
|
1540
|
+
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1541
|
+
},
|
|
1542
|
+
{
|
|
1543
|
+
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1544
|
+
useFactory: (options) => {
|
|
1545
|
+
return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1546
|
+
},
|
|
1547
|
+
deps: [HASURA_OPTIONS],
|
|
1548
|
+
},
|
|
1549
|
+
{
|
|
1550
|
+
provide: 'FilterOptionRepository',
|
|
1551
|
+
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1552
|
+
},
|
|
1553
|
+
{
|
|
1554
|
+
provide: FilterOptionHasuraGraphQLRepository,
|
|
1555
|
+
useFactory: (options) => {
|
|
1556
|
+
return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1557
|
+
},
|
|
1558
|
+
deps: [HASURA_OPTIONS],
|
|
1559
|
+
},
|
|
1560
|
+
{
|
|
1561
|
+
provide: 'FilterRepository',
|
|
1562
|
+
useExisting: FilterHasuraGraphQLRepository,
|
|
1563
|
+
},
|
|
1564
|
+
{
|
|
1565
|
+
provide: FilterHasuraGraphQLRepository,
|
|
1566
|
+
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
1567
|
+
return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
|
|
1568
|
+
},
|
|
1569
|
+
deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1570
|
+
},
|
|
1408
1571
|
] });
|
|
1409
1572
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
|
|
1410
1573
|
type: NgModule,
|
|
@@ -1439,10 +1602,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1439
1602
|
},
|
|
1440
1603
|
{
|
|
1441
1604
|
provide: CategoryHasuraGraphQLRepository,
|
|
1442
|
-
useFactory: (
|
|
1443
|
-
return new CategoryHasuraGraphQLRepository(
|
|
1605
|
+
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
1606
|
+
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
1444
1607
|
},
|
|
1445
|
-
deps: [
|
|
1608
|
+
deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1446
1609
|
},
|
|
1447
1610
|
{
|
|
1448
1611
|
provide: 'ProductRepository',
|
|
@@ -1466,6 +1629,39 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1466
1629
|
},
|
|
1467
1630
|
deps: ['HasuraConfig'],
|
|
1468
1631
|
},
|
|
1632
|
+
{
|
|
1633
|
+
provide: 'CategoryFilterRepository',
|
|
1634
|
+
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1638
|
+
useFactory: (options) => {
|
|
1639
|
+
return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1640
|
+
},
|
|
1641
|
+
deps: [HASURA_OPTIONS],
|
|
1642
|
+
},
|
|
1643
|
+
{
|
|
1644
|
+
provide: 'FilterOptionRepository',
|
|
1645
|
+
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1646
|
+
},
|
|
1647
|
+
{
|
|
1648
|
+
provide: FilterOptionHasuraGraphQLRepository,
|
|
1649
|
+
useFactory: (options) => {
|
|
1650
|
+
return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1651
|
+
},
|
|
1652
|
+
deps: [HASURA_OPTIONS],
|
|
1653
|
+
},
|
|
1654
|
+
{
|
|
1655
|
+
provide: 'FilterRepository',
|
|
1656
|
+
useExisting: FilterHasuraGraphQLRepository,
|
|
1657
|
+
},
|
|
1658
|
+
{
|
|
1659
|
+
provide: FilterHasuraGraphQLRepository,
|
|
1660
|
+
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
1661
|
+
return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
|
|
1662
|
+
},
|
|
1663
|
+
deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1664
|
+
},
|
|
1469
1665
|
],
|
|
1470
1666
|
}]
|
|
1471
1667
|
}] });
|