@infrab4a/connect-angular 4.0.0-beta.5 → 4.0.0-beta.50
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/angular-connect.module.d.ts +2 -0
- package/angular-firestore.module.d.ts +2 -1
- package/consts/backend-url.const.d.ts +1 -0
- package/consts/category-structure.d.ts +1 -0
- package/consts/index.d.ts +2 -0
- package/esm2020/angular-connect.module.mjs +19 -3
- package/esm2020/angular-elastic-search.module.mjs +3 -7
- package/esm2020/angular-firestore.module.mjs +240 -139
- package/esm2020/angular-hasura-graphql.module.mjs +122 -23
- package/esm2020/consts/backend-url.const.mjs +2 -0
- package/esm2020/consts/category-structure.mjs +2 -0
- package/esm2020/consts/index.mjs +3 -1
- package/esm2020/helpers/index.mjs +2 -0
- package/esm2020/helpers/mobile-operation-system-checker.helper.mjs +7 -0
- package/esm2020/index.mjs +3 -3
- package/esm2020/services/auth.service.mjs +3 -3
- package/esm2020/services/cart.service.mjs +161 -23
- package/esm2020/services/catalog/adapters/category-structure.adapter.mjs +2 -0
- package/esm2020/services/catalog/adapters/index.mjs +4 -0
- package/esm2020/services/catalog/adapters/new-category-structure.adapter.mjs +42 -0
- package/esm2020/services/catalog/adapters/old-category-structure.adapter.mjs +23 -0
- package/esm2020/services/catalog/catalog.service.mjs +98 -0
- package/esm2020/services/catalog/category.service.mjs +51 -0
- package/esm2020/services/catalog/enums/index.mjs +2 -0
- package/esm2020/services/catalog/enums/product-sorts.enum.mjs +11 -0
- package/esm2020/services/catalog/index.mjs +7 -0
- package/esm2020/services/catalog/models/category-with-tree.model.mjs +10 -0
- package/esm2020/services/catalog/models/index.mjs +2 -0
- package/esm2020/services/catalog/types/index.mjs +2 -0
- package/esm2020/services/catalog/types/product-sort.type.mjs +2 -0
- package/esm2020/services/catalog/wishlist.service.mjs +106 -0
- package/esm2020/services/checkout-subscription.service.mjs +5 -3
- package/esm2020/services/checkout.service.mjs +3 -5
- package/esm2020/services/coupon.service.mjs +132 -140
- package/esm2020/services/helpers/index.mjs +2 -0
- package/esm2020/services/helpers/util.service.mjs +26 -0
- package/esm2020/services/index.mjs +6 -3
- package/esm2020/services/shipping.service.mjs +96 -0
- package/esm2020/services/types/shipping-methods.type.mjs +2 -0
- package/fesm2015/infrab4a-connect-angular.mjs +1833 -1049
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +1807 -1045
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/helpers/index.d.ts +1 -0
- package/helpers/mobile-operation-system-checker.helper.d.ts +3 -0
- package/index.d.ts +2 -2
- package/package.json +2 -3
- package/services/cart.service.d.ts +9 -2
- package/services/catalog/adapters/category-structure.adapter.d.ts +4 -0
- package/services/catalog/adapters/index.d.ts +3 -0
- package/services/catalog/adapters/new-category-structure.adapter.d.ts +14 -0
- package/services/catalog/adapters/old-category-structure.adapter.d.ts +10 -0
- package/services/catalog/catalog.service.d.ts +54 -0
- package/services/catalog/category.service.d.ts +15 -0
- package/services/catalog/enums/index.d.ts +1 -0
- package/services/catalog/enums/product-sorts.enum.d.ts +9 -0
- package/services/catalog/index.d.ts +6 -0
- package/services/catalog/models/category-with-tree.model.d.ts +4 -0
- package/services/catalog/models/index.d.ts +1 -0
- package/services/catalog/types/index.d.ts +1 -0
- package/services/catalog/types/product-sort.type.d.ts +2 -0
- package/services/catalog/wishlist.service.d.ts +25 -0
- package/services/coupon.service.d.ts +13 -10
- package/services/helpers/index.d.ts +1 -0
- package/services/helpers/util.service.d.ts +7 -0
- package/services/index.d.ts +5 -2
- package/services/shipping.service.d.ts +19 -0
- package/services/types/shipping-methods.type.d.ts +12 -0
- package/esm2020/services/errors/group-invalid-coupon.error.mjs +0 -8
- package/esm2020/services/errors/index.mjs +0 -3
- package/esm2020/services/errors/invalid-coupon.error.mjs +0 -7
- package/services/errors/group-invalid-coupon.error.d.ts +0 -6
- package/services/errors/index.d.ts +0 -2
- package/services/errors/invalid-coupon.error.d.ts +0 -4
|
@@ -1,49 +1,25 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import * as i1 from '@
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import { InjectionToken, NgModule, PLATFORM_ID, Injectable, Inject } from '@angular/core';
|
|
3
|
+
import * as i1$3 from '@infrab4a/connect';
|
|
4
|
+
import { 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, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
|
|
5
|
+
import * as i1 from '@angular/fire/app';
|
|
6
|
+
import { provideFirebaseApp, initializeApp, FirebaseApp } from '@angular/fire/app';
|
|
7
|
+
import * as i1$1 from '@angular/fire/auth';
|
|
8
|
+
import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
9
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
10
|
+
import * as i1$2 from '@angular/fire/firestore';
|
|
11
|
+
import { Firestore, provideFirestore, getFirestore, initializeFirestore, enableIndexedDbPersistence, docSnapshots, doc } from '@angular/fire/firestore';
|
|
12
|
+
import { initializeApp as initializeApp$1 } from 'firebase/app';
|
|
13
|
+
import { combineLatest, from, of, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
6
14
|
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
7
|
-
import * as i2 from '@infrab4a/connect';
|
|
8
|
-
import { Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, Status, isNil, NotFoundError, Checkout, pick, LineItem, CheckoutSubscription, Order, Category, Product, RequiredArgumentError, add, 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, VariantHasuraGraphQLRepository } from '@infrab4a/connect';
|
|
9
15
|
import cookie from 'js-cookie';
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import * as i1$2 from '@angular/fire/app';
|
|
14
|
-
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
15
|
-
import { isPlatformBrowser } from '@angular/common';
|
|
16
|
+
import { __decorate, __metadata } from 'tslib';
|
|
17
|
+
import { Type } from 'class-transformer';
|
|
18
|
+
import * as i1$4 from '@angular/common/http';
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.userRepository = userRepository;
|
|
21
|
-
}
|
|
22
|
-
getAuthstate() {
|
|
23
|
-
const observables = [this.getFireUser(), this.getUser()];
|
|
24
|
-
return combineLatest(observables).pipe(map(([fireUser, user]) => ({
|
|
25
|
-
user,
|
|
26
|
-
isAnonymous: fireUser?.isAnonymous,
|
|
27
|
-
})));
|
|
28
|
-
}
|
|
29
|
-
getUser() {
|
|
30
|
-
return this.getFireUser().pipe(map((user) => user?.uid), mergeMap((id) => (id ? this.userRepository.get({ id }) : of(null))), catchError(() => of(null)));
|
|
31
|
-
}
|
|
32
|
-
getTokenId() {
|
|
33
|
-
return from(getIdToken(this.angularFireAuth.currentUser));
|
|
34
|
-
}
|
|
35
|
-
getFireUser() {
|
|
36
|
-
return authState(this.angularFireAuth).pipe(catchError(() => of(null)));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, deps: [{ token: i1.Auth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
40
|
-
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService });
|
|
41
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, decorators: [{
|
|
42
|
-
type: Injectable
|
|
43
|
-
}], ctorParameters: function () { return [{ type: i1.Auth }, { type: undefined, decorators: [{
|
|
44
|
-
type: Inject,
|
|
45
|
-
args: ['UserRepository']
|
|
46
|
-
}] }]; } });
|
|
20
|
+
const BACKEND_URL = 'BACKEND_URL';
|
|
21
|
+
|
|
22
|
+
const CATEGORY_STRUCTURE = 'CATEGORY_STRUCTURE';
|
|
47
23
|
|
|
48
24
|
const DEFAULT_SHOP = 'DEFAULT_SHOP';
|
|
49
25
|
|
|
@@ -54,152 +30,975 @@ const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
|
|
|
54
30
|
|
|
55
31
|
const HASURA_OPTIONS = 'HASURA_OPTIONS';
|
|
56
32
|
|
|
57
|
-
class
|
|
58
|
-
|
|
59
|
-
|
|
33
|
+
class AngularFirebaseAuthModule {
|
|
34
|
+
static initializeApp(options, nameOrConfig) {
|
|
35
|
+
return {
|
|
36
|
+
ngModule: AngularFirebaseAuthModule,
|
|
37
|
+
providers: [
|
|
38
|
+
{ provide: FIREBASE_OPTIONS, useValue: options },
|
|
39
|
+
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
40
|
+
],
|
|
41
|
+
};
|
|
60
42
|
}
|
|
61
43
|
}
|
|
44
|
+
AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
45
|
+
AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1.FirebaseAppModule, i1$1.AuthModule] });
|
|
46
|
+
AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
|
|
47
|
+
{
|
|
48
|
+
provide: 'Authentication',
|
|
49
|
+
useFactory: (authenticationService, userRepository) => {
|
|
50
|
+
return new Authentication(authenticationService, userRepository);
|
|
51
|
+
},
|
|
52
|
+
deps: ['AuthenticationService', 'UserRepository'],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
provide: 'AuthenticationService',
|
|
56
|
+
useFactory: (angularFireAuth) => {
|
|
57
|
+
return new AuthenticationFirebaseAuthService(angularFireAuth);
|
|
58
|
+
},
|
|
59
|
+
deps: [Auth],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
provide: 'Register',
|
|
63
|
+
useFactory: (registerService, userRepository) => {
|
|
64
|
+
return new Register(registerService, userRepository);
|
|
65
|
+
},
|
|
66
|
+
deps: ['RegisterService', 'UserRepository'],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
provide: 'RegisterService',
|
|
70
|
+
useFactory: (angularFireAuth) => {
|
|
71
|
+
return new RegisterFirebaseAuthService(angularFireAuth);
|
|
72
|
+
},
|
|
73
|
+
deps: [Auth],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
provide: 'SignOut',
|
|
77
|
+
useFactory: (authenticationService) => {
|
|
78
|
+
return new SignOut(authenticationService);
|
|
79
|
+
},
|
|
80
|
+
deps: ['AuthenticationService'],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
provide: 'RecoveryPassword',
|
|
84
|
+
useFactory: (authenticationService) => {
|
|
85
|
+
return new RecoveryPassword(authenticationService);
|
|
86
|
+
},
|
|
87
|
+
deps: ['AuthenticationService'],
|
|
88
|
+
},
|
|
89
|
+
], imports: [provideFirebaseApp((injector) => {
|
|
90
|
+
const appName = injector.get(FIREBASE_APP_NAME);
|
|
91
|
+
return appName
|
|
92
|
+
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
93
|
+
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
94
|
+
}),
|
|
95
|
+
provideAuth(() => getAuth())] });
|
|
96
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
|
|
97
|
+
type: NgModule,
|
|
98
|
+
args: [{
|
|
99
|
+
imports: [
|
|
100
|
+
provideFirebaseApp((injector) => {
|
|
101
|
+
const appName = injector.get(FIREBASE_APP_NAME);
|
|
102
|
+
return appName
|
|
103
|
+
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
104
|
+
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
105
|
+
}),
|
|
106
|
+
provideAuth(() => getAuth()),
|
|
107
|
+
],
|
|
108
|
+
providers: [
|
|
109
|
+
{
|
|
110
|
+
provide: 'Authentication',
|
|
111
|
+
useFactory: (authenticationService, userRepository) => {
|
|
112
|
+
return new Authentication(authenticationService, userRepository);
|
|
113
|
+
},
|
|
114
|
+
deps: ['AuthenticationService', 'UserRepository'],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
provide: 'AuthenticationService',
|
|
118
|
+
useFactory: (angularFireAuth) => {
|
|
119
|
+
return new AuthenticationFirebaseAuthService(angularFireAuth);
|
|
120
|
+
},
|
|
121
|
+
deps: [Auth],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
provide: 'Register',
|
|
125
|
+
useFactory: (registerService, userRepository) => {
|
|
126
|
+
return new Register(registerService, userRepository);
|
|
127
|
+
},
|
|
128
|
+
deps: ['RegisterService', 'UserRepository'],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
provide: 'RegisterService',
|
|
132
|
+
useFactory: (angularFireAuth) => {
|
|
133
|
+
return new RegisterFirebaseAuthService(angularFireAuth);
|
|
134
|
+
},
|
|
135
|
+
deps: [Auth],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
provide: 'SignOut',
|
|
139
|
+
useFactory: (authenticationService) => {
|
|
140
|
+
return new SignOut(authenticationService);
|
|
141
|
+
},
|
|
142
|
+
deps: ['AuthenticationService'],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
provide: 'RecoveryPassword',
|
|
146
|
+
useFactory: (authenticationService) => {
|
|
147
|
+
return new RecoveryPassword(authenticationService);
|
|
148
|
+
},
|
|
149
|
+
deps: ['AuthenticationService'],
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
}]
|
|
153
|
+
}] });
|
|
62
154
|
|
|
63
|
-
class
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
155
|
+
class AngularElasticSeachModule {
|
|
156
|
+
static initializeApp(options) {
|
|
157
|
+
return {
|
|
158
|
+
ngModule: AngularElasticSeachModule,
|
|
159
|
+
providers: [{ provide: ES_CONFIG, useValue: options }],
|
|
160
|
+
};
|
|
67
161
|
}
|
|
68
162
|
}
|
|
163
|
+
AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
164
|
+
AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule });
|
|
165
|
+
AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
|
|
166
|
+
{
|
|
167
|
+
provide: ProductsIndex,
|
|
168
|
+
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
169
|
+
deps: [ES_CONFIG],
|
|
170
|
+
},
|
|
171
|
+
] });
|
|
172
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
|
|
173
|
+
type: NgModule,
|
|
174
|
+
args: [{
|
|
175
|
+
providers: [
|
|
176
|
+
{
|
|
177
|
+
provide: ProductsIndex,
|
|
178
|
+
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
179
|
+
deps: [ES_CONFIG],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
}]
|
|
183
|
+
}] });
|
|
69
184
|
|
|
70
|
-
class
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.orderRepository = orderRepository;
|
|
75
|
-
this.subscriptionRepository = subscriptionRepository;
|
|
76
|
-
this.categoryRepository = categoryRepository;
|
|
77
|
-
this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
|
|
78
|
-
}
|
|
79
|
-
checkCoupon(nickname, userEmail, checkoutType, plan, checkout, isSubscription) {
|
|
80
|
-
return from(this.couponRepository.find({
|
|
81
|
-
filters: {
|
|
82
|
-
nickname: { operator: Where.EQUALS, value: nickname },
|
|
83
|
-
active: { operator: Where.EQUALS, value: true },
|
|
84
|
-
},
|
|
85
|
-
})).pipe(concatMap((coupons) => this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)), concatMap((coupon) => this.checkCouponUseAndLimit(coupon, userEmail, checkout)), map((coupon) => this.isValidCoupon(coupon, userEmail)), map((coupon) => coupon));
|
|
185
|
+
class MobileOperationSystemCheckerHelper {
|
|
186
|
+
static isAppleDevice() {
|
|
187
|
+
return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator?.platform) ||
|
|
188
|
+
(navigator?.userAgent?.includes?.('Mac') && 'ontouchend' in (document || {})));
|
|
86
189
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// Verifica se o coupon é aplicado no checkout que está sendo realizado
|
|
100
|
-
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
101
|
-
// Cupon não aplicavel ao checkout retorna erro
|
|
102
|
-
if (!isCheckoutType)
|
|
103
|
-
return throwError('Cupom inválido. Erro de checkout.');
|
|
104
|
-
// Verifica se o cupom é ou pode ser aplicado para subscription
|
|
105
|
-
if (checkoutType === CheckoutTypes.ALL || checkoutType === CheckoutTypes.SUBSCRIPTION) {
|
|
106
|
-
// Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
|
|
107
|
-
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
108
|
-
return throwError('Cupom inválido para sua assinatura.');
|
|
109
|
-
}
|
|
110
|
-
if (isSubscription)
|
|
111
|
-
return of(coupon);
|
|
112
|
-
// Verifica se possui o valor minimo de compra para utilização do cupom
|
|
113
|
-
const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
|
|
114
|
-
// Se não tem valor mínimo atingido, retorna erro
|
|
115
|
-
if (!hasMinSubTotal)
|
|
116
|
-
return throwError('Valor mínimo não atingido');
|
|
117
|
-
return of(coupon);
|
|
118
|
-
}
|
|
119
|
-
isValidCoupon(coupon, userEmail) {
|
|
120
|
-
// Verifica a data de inicio de validade do cupom
|
|
121
|
-
if (coupon?.beginAt > new Date())
|
|
122
|
-
throw new InvalidCouponError('Cupom ainda não liberado.');
|
|
123
|
-
// Verifica a data de validade do cupom
|
|
124
|
-
if (coupon?.expiresIn < new Date())
|
|
125
|
-
throw new InvalidCouponError('Cupom expirado.');
|
|
126
|
-
return coupon;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
class AngularFirestoreModule {
|
|
193
|
+
static initializeApp(options, nameOrConfig) {
|
|
194
|
+
return {
|
|
195
|
+
ngModule: AngularFirestoreModule,
|
|
196
|
+
providers: [
|
|
197
|
+
{ provide: FIREBASE_OPTIONS, useValue: options.firebase },
|
|
198
|
+
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
199
|
+
{ provide: ES_CONFIG, useValue: options.elasticSearch },
|
|
200
|
+
],
|
|
201
|
+
};
|
|
127
202
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
203
|
+
}
|
|
204
|
+
AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
205
|
+
AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1.FirebaseAppModule, i1$2.FirestoreModule] });
|
|
206
|
+
AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, providers: [
|
|
207
|
+
{
|
|
208
|
+
provide: 'FirestoreOptions',
|
|
209
|
+
useFactory: (firestore, platformId) => ({
|
|
210
|
+
firestore,
|
|
211
|
+
interceptors: {
|
|
212
|
+
request: (request) => {
|
|
213
|
+
if (isPlatformBrowser(platformId))
|
|
214
|
+
return request;
|
|
215
|
+
const interval = setInterval(() => { }, 100);
|
|
216
|
+
request.interval = interval;
|
|
217
|
+
return request;
|
|
218
|
+
},
|
|
219
|
+
response: (response, request) => {
|
|
220
|
+
if (isPlatformBrowser(platformId))
|
|
221
|
+
return response;
|
|
222
|
+
clearInterval(request.interval);
|
|
223
|
+
return response;
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
}),
|
|
227
|
+
deps: [Firestore, PLATFORM_ID],
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
provide: 'BeautyProfileRepository',
|
|
231
|
+
useFactory: (config, userRepository) => {
|
|
232
|
+
return new UserBeautyProfileFirestoreRepository(config, userRepository);
|
|
133
233
|
},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
234
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
provide: 'Buy2WinRepository',
|
|
238
|
+
useFactory: (options) => {
|
|
239
|
+
return new Buy2WinFirestoreRepository(options);
|
|
240
|
+
},
|
|
241
|
+
deps: ['FirestoreOptions'],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
provide: CategoryFirestoreRepository,
|
|
245
|
+
useFactory: (options) => {
|
|
246
|
+
return new CategoryFirestoreRepository(options);
|
|
247
|
+
},
|
|
248
|
+
deps: ['FirestoreOptions'],
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
provide: 'CheckoutRepository',
|
|
252
|
+
useFactory: (options) => {
|
|
253
|
+
return new CheckoutFirestoreRepository(options);
|
|
254
|
+
},
|
|
255
|
+
deps: ['FirestoreOptions'],
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
provide: 'CheckoutSubscriptionRepository',
|
|
259
|
+
useFactory: (options) => {
|
|
260
|
+
return new CheckoutSubscriptionFirestoreRepository(options);
|
|
261
|
+
},
|
|
262
|
+
deps: ['FirestoreOptions'],
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
provide: 'CouponRepository',
|
|
266
|
+
useFactory: (options) => {
|
|
267
|
+
return new CouponFirestoreRepository(options);
|
|
268
|
+
},
|
|
269
|
+
deps: ['FirestoreOptions'],
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
provide: 'CampaignHashtagRepository',
|
|
273
|
+
useFactory: (options) => {
|
|
274
|
+
return new CampaignHashtagFirestoreRepository(options);
|
|
275
|
+
},
|
|
276
|
+
deps: ['FirestoreOptions'],
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
provide: 'CampaignDashboardRepository',
|
|
280
|
+
useFactory: (options) => {
|
|
281
|
+
return new CampaignDashboardFirestoreRepository(options);
|
|
282
|
+
},
|
|
283
|
+
deps: ['FirestoreOptions'],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
provide: 'EditionRepository',
|
|
287
|
+
useFactory: (options, subscriptionRepository) => {
|
|
288
|
+
return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
|
|
289
|
+
},
|
|
290
|
+
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
provide: 'HomeRepository',
|
|
294
|
+
useFactory: (options) => {
|
|
295
|
+
return new HomeFirestoreRepository(options);
|
|
296
|
+
},
|
|
297
|
+
deps: ['FirestoreOptions'],
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
provide: 'LeadRepository',
|
|
301
|
+
useFactory: (options) => {
|
|
302
|
+
return new LeadFirestoreRepository(options);
|
|
303
|
+
},
|
|
304
|
+
deps: ['FirestoreOptions'],
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
provide: 'LegacyOrderRepository',
|
|
308
|
+
useFactory: (options) => {
|
|
309
|
+
return new LegacyOrderFirestoreRepository(options);
|
|
310
|
+
},
|
|
311
|
+
deps: ['FirestoreOptions'],
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
provide: 'ShopMenuRepository',
|
|
315
|
+
useFactory: (options) => {
|
|
316
|
+
return new ShopMenuFirestoreRepository(options);
|
|
317
|
+
},
|
|
318
|
+
deps: ['FirestoreOptions'],
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
provide: 'OrderRepository',
|
|
322
|
+
useFactory: (options) => {
|
|
323
|
+
return new OrderFirestoreRepository(options);
|
|
324
|
+
},
|
|
325
|
+
deps: ['FirestoreOptions'],
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
provide: 'PaymentRepository',
|
|
329
|
+
useFactory: (options) => {
|
|
330
|
+
return new PaymentFirestoreRepository(options);
|
|
331
|
+
},
|
|
332
|
+
deps: ['FirestoreOptions'],
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
provide: ProductFirestoreRepository,
|
|
336
|
+
useFactory: (options) => {
|
|
337
|
+
return new ProductFirestoreRepository(options);
|
|
338
|
+
},
|
|
339
|
+
deps: ['FirestoreOptions'],
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
provide: 'ShopSettingsRepository',
|
|
343
|
+
useFactory: (options) => {
|
|
344
|
+
return new ShopSettingsFirestoreRepository(options);
|
|
345
|
+
},
|
|
346
|
+
deps: ['FirestoreOptions'],
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
provide: 'SubscriptionPaymentRepository',
|
|
350
|
+
useFactory: (options, subscriptionRepository) => {
|
|
351
|
+
return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
|
|
352
|
+
},
|
|
353
|
+
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
provide: 'SubscriptionPlanRepository',
|
|
357
|
+
useFactory: (options) => {
|
|
358
|
+
return new SubscriptionPlanFirestoreRepository(options);
|
|
359
|
+
},
|
|
360
|
+
deps: ['FirestoreOptions'],
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
provide: 'SubscriptionProductRepository',
|
|
364
|
+
useFactory: (options) => {
|
|
365
|
+
return new SubscriptionProductFirestoreRepository(options);
|
|
366
|
+
},
|
|
367
|
+
deps: ['FirestoreOptions'],
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
provide: 'SubscriptionRepository',
|
|
371
|
+
useFactory: (options) => {
|
|
372
|
+
return new SubscriptionFirestoreRepository(options);
|
|
373
|
+
},
|
|
374
|
+
deps: ['FirestoreOptions'],
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
provide: 'UserRepository',
|
|
378
|
+
useFactory: (options) => {
|
|
379
|
+
return new UserFirestoreRepository(options);
|
|
380
|
+
},
|
|
381
|
+
deps: ['FirestoreOptions'],
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
provide: 'UserAddressRepository',
|
|
385
|
+
useFactory: (options, userRepository) => {
|
|
386
|
+
return new UserAddressFirestoreRepository(options, userRepository);
|
|
387
|
+
},
|
|
388
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
provide: 'UserPaymentMethodRepository',
|
|
392
|
+
useFactory: (options, userRepository) => {
|
|
393
|
+
return new UserPaymentMethodFirestoreRepository(options, userRepository);
|
|
394
|
+
},
|
|
395
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
provide: ProductVariantFirestoreRepository,
|
|
399
|
+
useFactory: (options, productRepository) => {
|
|
400
|
+
return new ProductVariantFirestoreRepository(options, productRepository);
|
|
401
|
+
},
|
|
402
|
+
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
403
|
+
},
|
|
404
|
+
], imports: [AngularElasticSeachModule,
|
|
405
|
+
provideFirebaseApp((injector) => {
|
|
406
|
+
const appName = injector.get(FIREBASE_APP_NAME);
|
|
407
|
+
return appName
|
|
408
|
+
? initializeApp$1(injector.get(FIREBASE_OPTIONS), appName)
|
|
409
|
+
: initializeApp$1(injector.get(FIREBASE_OPTIONS));
|
|
410
|
+
}),
|
|
411
|
+
provideFirestore((injector) => {
|
|
412
|
+
if (!MobileOperationSystemCheckerHelper.isAppleDevice())
|
|
413
|
+
return getFirestore();
|
|
414
|
+
const firestore = initializeFirestore(injector.get(FirebaseApp), { experimentalForceLongPolling: true });
|
|
415
|
+
enableIndexedDbPersistence(firestore).catch(console.error);
|
|
416
|
+
return firestore;
|
|
417
|
+
})] });
|
|
418
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, decorators: [{
|
|
419
|
+
type: NgModule,
|
|
420
|
+
args: [{
|
|
421
|
+
imports: [
|
|
422
|
+
AngularElasticSeachModule,
|
|
423
|
+
provideFirebaseApp((injector) => {
|
|
424
|
+
const appName = injector.get(FIREBASE_APP_NAME);
|
|
425
|
+
return appName
|
|
426
|
+
? initializeApp$1(injector.get(FIREBASE_OPTIONS), appName)
|
|
427
|
+
: initializeApp$1(injector.get(FIREBASE_OPTIONS));
|
|
428
|
+
}),
|
|
429
|
+
provideFirestore((injector) => {
|
|
430
|
+
if (!MobileOperationSystemCheckerHelper.isAppleDevice())
|
|
431
|
+
return getFirestore();
|
|
432
|
+
const firestore = initializeFirestore(injector.get(FirebaseApp), { experimentalForceLongPolling: true });
|
|
433
|
+
enableIndexedDbPersistence(firestore).catch(console.error);
|
|
434
|
+
return firestore;
|
|
435
|
+
}),
|
|
436
|
+
],
|
|
437
|
+
providers: [
|
|
438
|
+
{
|
|
439
|
+
provide: 'FirestoreOptions',
|
|
440
|
+
useFactory: (firestore, platformId) => ({
|
|
441
|
+
firestore,
|
|
442
|
+
interceptors: {
|
|
443
|
+
request: (request) => {
|
|
444
|
+
if (isPlatformBrowser(platformId))
|
|
445
|
+
return request;
|
|
446
|
+
const interval = setInterval(() => { }, 100);
|
|
447
|
+
request.interval = interval;
|
|
448
|
+
return request;
|
|
449
|
+
},
|
|
450
|
+
response: (response, request) => {
|
|
451
|
+
if (isPlatformBrowser(platformId))
|
|
452
|
+
return response;
|
|
453
|
+
clearInterval(request.interval);
|
|
454
|
+
return response;
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
}),
|
|
458
|
+
deps: [Firestore, PLATFORM_ID],
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
provide: 'BeautyProfileRepository',
|
|
462
|
+
useFactory: (config, userRepository) => {
|
|
463
|
+
return new UserBeautyProfileFirestoreRepository(config, userRepository);
|
|
464
|
+
},
|
|
465
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
provide: 'Buy2WinRepository',
|
|
469
|
+
useFactory: (options) => {
|
|
470
|
+
return new Buy2WinFirestoreRepository(options);
|
|
471
|
+
},
|
|
472
|
+
deps: ['FirestoreOptions'],
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
provide: CategoryFirestoreRepository,
|
|
476
|
+
useFactory: (options) => {
|
|
477
|
+
return new CategoryFirestoreRepository(options);
|
|
478
|
+
},
|
|
479
|
+
deps: ['FirestoreOptions'],
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
provide: 'CheckoutRepository',
|
|
483
|
+
useFactory: (options) => {
|
|
484
|
+
return new CheckoutFirestoreRepository(options);
|
|
485
|
+
},
|
|
486
|
+
deps: ['FirestoreOptions'],
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
provide: 'CheckoutSubscriptionRepository',
|
|
490
|
+
useFactory: (options) => {
|
|
491
|
+
return new CheckoutSubscriptionFirestoreRepository(options);
|
|
492
|
+
},
|
|
493
|
+
deps: ['FirestoreOptions'],
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
provide: 'CouponRepository',
|
|
497
|
+
useFactory: (options) => {
|
|
498
|
+
return new CouponFirestoreRepository(options);
|
|
499
|
+
},
|
|
500
|
+
deps: ['FirestoreOptions'],
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
provide: 'CampaignHashtagRepository',
|
|
504
|
+
useFactory: (options) => {
|
|
505
|
+
return new CampaignHashtagFirestoreRepository(options);
|
|
506
|
+
},
|
|
507
|
+
deps: ['FirestoreOptions'],
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
provide: 'CampaignDashboardRepository',
|
|
511
|
+
useFactory: (options) => {
|
|
512
|
+
return new CampaignDashboardFirestoreRepository(options);
|
|
513
|
+
},
|
|
514
|
+
deps: ['FirestoreOptions'],
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
provide: 'EditionRepository',
|
|
518
|
+
useFactory: (options, subscriptionRepository) => {
|
|
519
|
+
return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
|
|
520
|
+
},
|
|
521
|
+
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
provide: 'HomeRepository',
|
|
525
|
+
useFactory: (options) => {
|
|
526
|
+
return new HomeFirestoreRepository(options);
|
|
527
|
+
},
|
|
528
|
+
deps: ['FirestoreOptions'],
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
provide: 'LeadRepository',
|
|
532
|
+
useFactory: (options) => {
|
|
533
|
+
return new LeadFirestoreRepository(options);
|
|
534
|
+
},
|
|
535
|
+
deps: ['FirestoreOptions'],
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
provide: 'LegacyOrderRepository',
|
|
539
|
+
useFactory: (options) => {
|
|
540
|
+
return new LegacyOrderFirestoreRepository(options);
|
|
541
|
+
},
|
|
542
|
+
deps: ['FirestoreOptions'],
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
provide: 'ShopMenuRepository',
|
|
546
|
+
useFactory: (options) => {
|
|
547
|
+
return new ShopMenuFirestoreRepository(options);
|
|
548
|
+
},
|
|
549
|
+
deps: ['FirestoreOptions'],
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
provide: 'OrderRepository',
|
|
553
|
+
useFactory: (options) => {
|
|
554
|
+
return new OrderFirestoreRepository(options);
|
|
555
|
+
},
|
|
556
|
+
deps: ['FirestoreOptions'],
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
provide: 'PaymentRepository',
|
|
560
|
+
useFactory: (options) => {
|
|
561
|
+
return new PaymentFirestoreRepository(options);
|
|
562
|
+
},
|
|
563
|
+
deps: ['FirestoreOptions'],
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
provide: ProductFirestoreRepository,
|
|
567
|
+
useFactory: (options) => {
|
|
568
|
+
return new ProductFirestoreRepository(options);
|
|
569
|
+
},
|
|
570
|
+
deps: ['FirestoreOptions'],
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
provide: 'ShopSettingsRepository',
|
|
574
|
+
useFactory: (options) => {
|
|
575
|
+
return new ShopSettingsFirestoreRepository(options);
|
|
576
|
+
},
|
|
577
|
+
deps: ['FirestoreOptions'],
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
provide: 'SubscriptionPaymentRepository',
|
|
581
|
+
useFactory: (options, subscriptionRepository) => {
|
|
582
|
+
return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
|
|
583
|
+
},
|
|
584
|
+
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
provide: 'SubscriptionPlanRepository',
|
|
588
|
+
useFactory: (options) => {
|
|
589
|
+
return new SubscriptionPlanFirestoreRepository(options);
|
|
590
|
+
},
|
|
591
|
+
deps: ['FirestoreOptions'],
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
provide: 'SubscriptionProductRepository',
|
|
595
|
+
useFactory: (options) => {
|
|
596
|
+
return new SubscriptionProductFirestoreRepository(options);
|
|
597
|
+
},
|
|
598
|
+
deps: ['FirestoreOptions'],
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
provide: 'SubscriptionRepository',
|
|
602
|
+
useFactory: (options) => {
|
|
603
|
+
return new SubscriptionFirestoreRepository(options);
|
|
604
|
+
},
|
|
605
|
+
deps: ['FirestoreOptions'],
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
provide: 'UserRepository',
|
|
609
|
+
useFactory: (options) => {
|
|
610
|
+
return new UserFirestoreRepository(options);
|
|
611
|
+
},
|
|
612
|
+
deps: ['FirestoreOptions'],
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
provide: 'UserAddressRepository',
|
|
616
|
+
useFactory: (options, userRepository) => {
|
|
617
|
+
return new UserAddressFirestoreRepository(options, userRepository);
|
|
618
|
+
},
|
|
619
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
provide: 'UserPaymentMethodRepository',
|
|
623
|
+
useFactory: (options, userRepository) => {
|
|
624
|
+
return new UserPaymentMethodFirestoreRepository(options, userRepository);
|
|
625
|
+
},
|
|
626
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
provide: ProductVariantFirestoreRepository,
|
|
630
|
+
useFactory: (options, productRepository) => {
|
|
631
|
+
return new ProductVariantFirestoreRepository(options, productRepository);
|
|
632
|
+
},
|
|
633
|
+
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
634
|
+
},
|
|
635
|
+
],
|
|
636
|
+
}]
|
|
637
|
+
}] });
|
|
638
|
+
|
|
639
|
+
class AngularHasuraGraphQLModule {
|
|
640
|
+
static initializeApp(options) {
|
|
641
|
+
return {
|
|
642
|
+
ngModule: AngularHasuraGraphQLModule,
|
|
643
|
+
providers: [{ provide: HASURA_OPTIONS, useValue: options }],
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
648
|
+
AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule });
|
|
649
|
+
AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
|
|
650
|
+
{
|
|
651
|
+
provide: 'HasuraConfig',
|
|
652
|
+
useFactory: (options, platformId) => ({
|
|
653
|
+
endpoint: options.endpoint,
|
|
654
|
+
authOptions: options.credentials,
|
|
655
|
+
interceptors: {
|
|
656
|
+
request: (request) => {
|
|
657
|
+
if (isPlatformBrowser(platformId))
|
|
658
|
+
return request;
|
|
659
|
+
const interval = setInterval(() => { }, 100);
|
|
660
|
+
request.interval = interval;
|
|
661
|
+
return request;
|
|
662
|
+
},
|
|
663
|
+
response: (response, request) => {
|
|
664
|
+
if (isPlatformBrowser(platformId))
|
|
665
|
+
return response;
|
|
666
|
+
clearInterval(request.interval);
|
|
667
|
+
return response;
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
}),
|
|
671
|
+
deps: [HASURA_OPTIONS, PLATFORM_ID],
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
provide: 'CategoryRepository',
|
|
675
|
+
useExisting: CategoryHasuraGraphQLRepository,
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
provide: CategoryHasuraGraphQLRepository,
|
|
679
|
+
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
680
|
+
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
681
|
+
},
|
|
682
|
+
deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
provide: 'ProductRepository',
|
|
686
|
+
useExisting: ProductHasuraGraphQLRepository,
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
provide: ProductHasuraGraphQLRepository,
|
|
690
|
+
useFactory: (hasuraConfig) => {
|
|
691
|
+
return new ProductHasuraGraphQLRepository(hasuraConfig);
|
|
692
|
+
},
|
|
693
|
+
deps: ['HasuraConfig'],
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
provide: 'VariantRepository',
|
|
697
|
+
useExisting: VariantHasuraGraphQLRepository,
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
provide: VariantHasuraGraphQLRepository,
|
|
701
|
+
useFactory: (hasuraConfig) => {
|
|
702
|
+
return new VariantHasuraGraphQLRepository(hasuraConfig);
|
|
703
|
+
},
|
|
704
|
+
deps: ['HasuraConfig'],
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
provide: 'CategoryFilterRepository',
|
|
708
|
+
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
provide: CategoryFilterHasuraGraphQLRepository,
|
|
712
|
+
useFactory: (options) => {
|
|
713
|
+
return new CategoryFilterHasuraGraphQLRepository(options);
|
|
714
|
+
},
|
|
715
|
+
deps: ['HasuraConfig'],
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
provide: 'FilterOptionRepository',
|
|
719
|
+
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
provide: FilterOptionHasuraGraphQLRepository,
|
|
723
|
+
useFactory: (options) => {
|
|
724
|
+
return new FilterOptionHasuraGraphQLRepository(options);
|
|
725
|
+
},
|
|
726
|
+
deps: ['HasuraConfig'],
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
provide: 'FilterRepository',
|
|
730
|
+
useExisting: FilterHasuraGraphQLRepository,
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
provide: FilterHasuraGraphQLRepository,
|
|
734
|
+
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
735
|
+
return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
|
|
736
|
+
},
|
|
737
|
+
deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
provide: CategoryCollectionChildrenHasuraGraphQLRepository,
|
|
741
|
+
useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options.endpoint, options.credentials),
|
|
742
|
+
},
|
|
743
|
+
{
|
|
744
|
+
provide: 'CategoryCollectionChildrenRepository',
|
|
745
|
+
useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
provide: WishlistHasuraGraphQLRepository,
|
|
749
|
+
useFactory: (options, categoryFilterRepository) => {
|
|
750
|
+
return new WishlistHasuraGraphQLRepository(options, categoryFilterRepository);
|
|
751
|
+
},
|
|
752
|
+
deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
provide: 'WishlistRepository',
|
|
756
|
+
useExisting: WishlistHasuraGraphQLRepository,
|
|
757
|
+
},
|
|
758
|
+
] });
|
|
759
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
|
|
760
|
+
type: NgModule,
|
|
761
|
+
args: [{
|
|
762
|
+
providers: [
|
|
763
|
+
{
|
|
764
|
+
provide: 'HasuraConfig',
|
|
765
|
+
useFactory: (options, platformId) => ({
|
|
766
|
+
endpoint: options.endpoint,
|
|
767
|
+
authOptions: options.credentials,
|
|
768
|
+
interceptors: {
|
|
769
|
+
request: (request) => {
|
|
770
|
+
if (isPlatformBrowser(platformId))
|
|
771
|
+
return request;
|
|
772
|
+
const interval = setInterval(() => { }, 100);
|
|
773
|
+
request.interval = interval;
|
|
774
|
+
return request;
|
|
775
|
+
},
|
|
776
|
+
response: (response, request) => {
|
|
777
|
+
if (isPlatformBrowser(platformId))
|
|
778
|
+
return response;
|
|
779
|
+
clearInterval(request.interval);
|
|
780
|
+
return response;
|
|
781
|
+
},
|
|
782
|
+
},
|
|
783
|
+
}),
|
|
784
|
+
deps: [HASURA_OPTIONS, PLATFORM_ID],
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
provide: 'CategoryRepository',
|
|
788
|
+
useExisting: CategoryHasuraGraphQLRepository,
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
provide: CategoryHasuraGraphQLRepository,
|
|
792
|
+
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
793
|
+
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
794
|
+
},
|
|
795
|
+
deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
provide: 'ProductRepository',
|
|
799
|
+
useExisting: ProductHasuraGraphQLRepository,
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
provide: ProductHasuraGraphQLRepository,
|
|
803
|
+
useFactory: (hasuraConfig) => {
|
|
804
|
+
return new ProductHasuraGraphQLRepository(hasuraConfig);
|
|
805
|
+
},
|
|
806
|
+
deps: ['HasuraConfig'],
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
provide: 'VariantRepository',
|
|
810
|
+
useExisting: VariantHasuraGraphQLRepository,
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
provide: VariantHasuraGraphQLRepository,
|
|
814
|
+
useFactory: (hasuraConfig) => {
|
|
815
|
+
return new VariantHasuraGraphQLRepository(hasuraConfig);
|
|
816
|
+
},
|
|
817
|
+
deps: ['HasuraConfig'],
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
provide: 'CategoryFilterRepository',
|
|
821
|
+
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
provide: CategoryFilterHasuraGraphQLRepository,
|
|
825
|
+
useFactory: (options) => {
|
|
826
|
+
return new CategoryFilterHasuraGraphQLRepository(options);
|
|
827
|
+
},
|
|
828
|
+
deps: ['HasuraConfig'],
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
provide: 'FilterOptionRepository',
|
|
832
|
+
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
provide: FilterOptionHasuraGraphQLRepository,
|
|
836
|
+
useFactory: (options) => {
|
|
837
|
+
return new FilterOptionHasuraGraphQLRepository(options);
|
|
838
|
+
},
|
|
839
|
+
deps: ['HasuraConfig'],
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
provide: 'FilterRepository',
|
|
843
|
+
useExisting: FilterHasuraGraphQLRepository,
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
provide: FilterHasuraGraphQLRepository,
|
|
847
|
+
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
848
|
+
return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
|
|
849
|
+
},
|
|
850
|
+
deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
provide: CategoryCollectionChildrenHasuraGraphQLRepository,
|
|
854
|
+
useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options.endpoint, options.credentials),
|
|
855
|
+
},
|
|
856
|
+
{
|
|
857
|
+
provide: 'CategoryCollectionChildrenRepository',
|
|
858
|
+
useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
provide: WishlistHasuraGraphQLRepository,
|
|
862
|
+
useFactory: (options, categoryFilterRepository) => {
|
|
863
|
+
return new WishlistHasuraGraphQLRepository(options, categoryFilterRepository);
|
|
864
|
+
},
|
|
865
|
+
deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
provide: 'WishlistRepository',
|
|
869
|
+
useExisting: WishlistHasuraGraphQLRepository,
|
|
870
|
+
},
|
|
871
|
+
],
|
|
872
|
+
}]
|
|
873
|
+
}] });
|
|
874
|
+
|
|
875
|
+
class AuthService {
|
|
876
|
+
constructor(angularFireAuth, userRepository) {
|
|
877
|
+
this.angularFireAuth = angularFireAuth;
|
|
878
|
+
this.userRepository = userRepository;
|
|
879
|
+
}
|
|
880
|
+
getAuthstate() {
|
|
881
|
+
const observables = [this.getFireUser(), this.getUser()];
|
|
882
|
+
return combineLatest(observables).pipe(map(([fireUser, user]) => ({
|
|
883
|
+
user,
|
|
884
|
+
isAnonymous: fireUser?.isAnonymous,
|
|
885
|
+
})));
|
|
886
|
+
}
|
|
887
|
+
getUser() {
|
|
888
|
+
return this.getFireUser().pipe(map((user) => user?.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
|
|
889
|
+
}
|
|
890
|
+
getTokenId() {
|
|
891
|
+
return from(getIdToken(this.angularFireAuth.currentUser));
|
|
892
|
+
}
|
|
893
|
+
getFireUser() {
|
|
894
|
+
return authState(this.angularFireAuth).pipe(catchError(() => of(null)));
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, deps: [{ token: i1$1.Auth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
898
|
+
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService });
|
|
899
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, decorators: [{
|
|
900
|
+
type: Injectable
|
|
901
|
+
}], ctorParameters: function () { return [{ type: i1$1.Auth }, { type: undefined, decorators: [{
|
|
902
|
+
type: Inject,
|
|
903
|
+
args: ['UserRepository']
|
|
904
|
+
}] }]; } });
|
|
905
|
+
|
|
906
|
+
class CouponService {
|
|
907
|
+
constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
|
|
908
|
+
this.couponRepository = couponRepository;
|
|
909
|
+
this.defaultShop = defaultShop;
|
|
910
|
+
this.orderRepository = orderRepository;
|
|
911
|
+
this.categoryRepository = categoryRepository;
|
|
912
|
+
this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
|
|
913
|
+
}
|
|
914
|
+
checkCoupon(nickname, checkoutType, checkout, plan) {
|
|
915
|
+
return from(this.couponRepository
|
|
916
|
+
.find({
|
|
917
|
+
filters: {
|
|
918
|
+
nickname: { operator: Where.EQUALS, value: nickname },
|
|
919
|
+
active: { operator: Where.EQUALS, value: true },
|
|
920
|
+
},
|
|
921
|
+
})
|
|
922
|
+
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
|
|
923
|
+
}
|
|
924
|
+
async couponValidation(coupon, checkoutType) {
|
|
925
|
+
if (!coupon)
|
|
926
|
+
throw 'Cupom inválido.';
|
|
927
|
+
if (coupon?.beginAt && coupon?.beginAt.getTime() > new Date().getTime())
|
|
928
|
+
throw 'Cupom inválido.';
|
|
929
|
+
if (coupon?.expiresIn && coupon?.expiresIn.getTime() < new Date().getTime())
|
|
930
|
+
throw 'Cupom expirado.';
|
|
931
|
+
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
932
|
+
if (!isInShop)
|
|
933
|
+
throw 'Cupom inválido para loja.';
|
|
934
|
+
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
935
|
+
if (!isCheckoutType)
|
|
936
|
+
throw 'Cupom inválido. Erro de checkout.';
|
|
937
|
+
return coupon;
|
|
938
|
+
}
|
|
939
|
+
async couponRulesValidation(coupon, checkoutType, checkout, plan) {
|
|
940
|
+
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
941
|
+
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
942
|
+
throw 'Cupom inválido para sua assinatura.';
|
|
943
|
+
return coupon;
|
|
944
|
+
}
|
|
945
|
+
const validUser = this.coupomUserValidation(coupon, checkout?.user);
|
|
946
|
+
if (!validUser)
|
|
947
|
+
throw 'Usuário não elegível.';
|
|
948
|
+
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
949
|
+
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
950
|
+
const orders = await this.getOrdersWithCoupon(coupon);
|
|
951
|
+
if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
|
|
952
|
+
throw 'Limite de uso atingido.';
|
|
953
|
+
if (couponUseLimits.limitedPerUser) {
|
|
954
|
+
const ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
|
|
955
|
+
if (ordersWithUser > 0)
|
|
956
|
+
throw 'Limite de uso por usuário atingido.';
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
const hasProductCategories = await this.hasProductCategories(coupon, checkout);
|
|
960
|
+
if (!hasProductCategories)
|
|
961
|
+
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
962
|
+
const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
|
|
963
|
+
if (!hasMinSubTotal)
|
|
964
|
+
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`;
|
|
965
|
+
return coupon;
|
|
966
|
+
}
|
|
967
|
+
calcDiscountSubscription(coupon, checkout) {
|
|
968
|
+
let discount = 0;
|
|
969
|
+
if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
|
|
970
|
+
discount = coupon.discount.subscription.value;
|
|
971
|
+
else
|
|
972
|
+
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
|
|
973
|
+
return of(discount);
|
|
974
|
+
}
|
|
975
|
+
async calcDiscountShopping(coupon, checkout) {
|
|
976
|
+
let discount = 0;
|
|
977
|
+
if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
|
|
978
|
+
discount = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
discount = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
|
|
982
|
+
}
|
|
983
|
+
return discount;
|
|
984
|
+
}
|
|
985
|
+
async calcDiscountByType(type, value, categories, checkout) {
|
|
986
|
+
let discount = 0;
|
|
987
|
+
let lineItensDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
|
|
988
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
|
|
989
|
+
if (type == CouponTypes.ABSOLUTE) {
|
|
990
|
+
discount = value > subTotal ? subTotal : value;
|
|
991
|
+
}
|
|
992
|
+
else {
|
|
993
|
+
discount = subTotal * (value / 100);
|
|
994
|
+
}
|
|
194
995
|
return discount;
|
|
195
996
|
}
|
|
196
|
-
hasMinSubTotal(coupon, checkout) {
|
|
997
|
+
async hasMinSubTotal(coupon, checkout) {
|
|
197
998
|
if (!coupon.minSubTotalValue)
|
|
198
999
|
return true;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
202
|
-
: acc + curr.pricePaid * curr.quantity, 0) || 0;
|
|
1000
|
+
let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
1001
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
|
|
203
1002
|
if (coupon.minSubTotalValue <= subTotal)
|
|
204
1003
|
return true;
|
|
205
1004
|
return false;
|
|
@@ -208,60 +1007,93 @@ class CouponService {
|
|
|
208
1007
|
if (!coupon.productsCategories || !coupon.productsCategories.length) {
|
|
209
1008
|
return true;
|
|
210
1009
|
}
|
|
211
|
-
const couponCategories = await this.getCouponCategoriesId(coupon);
|
|
1010
|
+
const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
|
|
212
1011
|
const hasCategories = checkout.lineItems?.filter((i) => {
|
|
213
1012
|
if (!i.categories || !i.categories?.length)
|
|
214
1013
|
return true;
|
|
215
|
-
return i.categories.some((c) => couponCategories.some((cat) => cat
|
|
1014
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
216
1015
|
});
|
|
217
1016
|
return hasCategories.length ? true : false;
|
|
218
1017
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return false;
|
|
1018
|
+
coupomUserValidation(coupon, user) {
|
|
1019
|
+
if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
|
|
1020
|
+
return true;
|
|
1021
|
+
let userTypes = [];
|
|
1022
|
+
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) && this.emailIsFromCollaborator(user.email))
|
|
1023
|
+
userTypes.push(Exclusivities.COLLABORATORS);
|
|
1024
|
+
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) && coupon.userExclusiveEmail.includes(user.email))
|
|
1025
|
+
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
1026
|
+
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
1027
|
+
user.isSubscriber &&
|
|
1028
|
+
user.subscriptionPlan != '')
|
|
1029
|
+
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
1030
|
+
if (user.isSubscriber &&
|
|
1031
|
+
user.subscriptionPlan == '' &&
|
|
1032
|
+
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
1033
|
+
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
1034
|
+
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
1035
|
+
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
1036
|
+
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
1037
|
+
}
|
|
1038
|
+
async getCouponCategoriesId(productsCategories) {
|
|
1039
|
+
const couponCategories = [];
|
|
1040
|
+
for (let index = 0; index < productsCategories.length; index++) {
|
|
1041
|
+
const category = await this.categoryRepository.get({
|
|
1042
|
+
id: productsCategories[index],
|
|
1043
|
+
});
|
|
1044
|
+
if (category) {
|
|
1045
|
+
const children = await this.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
1046
|
+
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
249
1047
|
}
|
|
250
1048
|
}
|
|
251
|
-
return
|
|
1049
|
+
return [...new Set(couponCategories)];
|
|
252
1050
|
}
|
|
253
|
-
async
|
|
254
|
-
let
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
1051
|
+
async getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
1052
|
+
let lineItensDiscount = [];
|
|
1053
|
+
const couponCategories = await this.getCouponCategoriesId(productsCategories);
|
|
1054
|
+
if (productsCategories && productsCategories.length) {
|
|
1055
|
+
lineItensDiscount = checkout.lineItems?.filter((i) => {
|
|
1056
|
+
if (i.categories?.length) {
|
|
1057
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
1058
|
+
}
|
|
1059
|
+
return true;
|
|
258
1060
|
});
|
|
259
|
-
couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
|
|
260
1061
|
}
|
|
261
|
-
|
|
1062
|
+
else {
|
|
1063
|
+
lineItensDiscount = checkout.lineItems;
|
|
1064
|
+
}
|
|
1065
|
+
return lineItensDiscount;
|
|
1066
|
+
}
|
|
1067
|
+
calcCheckoutSubtotal(lineItens, user, shop) {
|
|
1068
|
+
return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
|
|
1069
|
+
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
1070
|
+
: acc + curr.pricePaid * curr.quantity, 0) || 0);
|
|
1071
|
+
}
|
|
1072
|
+
async getOrdersWithCoupon(coupon) {
|
|
1073
|
+
return await this.orderRepository
|
|
1074
|
+
.find({
|
|
1075
|
+
filters: {
|
|
1076
|
+
coupon: { id: coupon.id },
|
|
1077
|
+
payment: { status: 'paid' },
|
|
1078
|
+
},
|
|
1079
|
+
})
|
|
1080
|
+
.then((result) => result.data);
|
|
1081
|
+
}
|
|
1082
|
+
countOrdersWithUser(orders, email) {
|
|
1083
|
+
return orders.filter((o) => o.user.email == email).length;
|
|
1084
|
+
}
|
|
1085
|
+
getCouponUseLimits(coupon, checkoutType, user) {
|
|
1086
|
+
let couponUseLimits;
|
|
1087
|
+
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
1088
|
+
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
1089
|
+
}
|
|
1090
|
+
else {
|
|
1091
|
+
couponUseLimits = coupon.useLimits.subscription;
|
|
1092
|
+
}
|
|
1093
|
+
return couponUseLimits;
|
|
262
1094
|
}
|
|
263
1095
|
}
|
|
264
|
-
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: '
|
|
1096
|
+
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 });
|
|
265
1097
|
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
266
1098
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
267
1099
|
type: Injectable,
|
|
@@ -271,15 +1103,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
271
1103
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
272
1104
|
type: Inject,
|
|
273
1105
|
args: ['CouponRepository']
|
|
274
|
-
}] }, { type:
|
|
1106
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
275
1107
|
type: Inject,
|
|
276
1108
|
args: [DEFAULT_SHOP]
|
|
277
1109
|
}] }, { type: undefined, decorators: [{
|
|
278
1110
|
type: Inject,
|
|
279
1111
|
args: ['OrderRepository']
|
|
280
|
-
}] }, { type: undefined, decorators: [{
|
|
281
|
-
type: Inject,
|
|
282
|
-
args: ['SubscriptionRepository']
|
|
283
1112
|
}] }, { type: undefined, decorators: [{
|
|
284
1113
|
type: Inject,
|
|
285
1114
|
args: ['CategoryRepository']
|
|
@@ -316,9 +1145,7 @@ class CheckoutService {
|
|
|
316
1145
|
return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
|
|
317
1146
|
}
|
|
318
1147
|
checkCoupon(nickname, checkoutType) {
|
|
319
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.couponService
|
|
320
|
-
.checkCoupon(nickname, checkout.user?.email, CheckoutTypes.ECOMMERCE, checkout.user.subscriptionPlan, checkout, false)
|
|
321
|
-
.pipe()));
|
|
1148
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, CheckoutTypes.ECOMMERCE, checkout, null).pipe()));
|
|
322
1149
|
}
|
|
323
1150
|
async createCheckout(checkoutData) {
|
|
324
1151
|
const checkout = await this.checkoutRepository.create({
|
|
@@ -343,21 +1170,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
343
1170
|
}] }, { type: undefined, decorators: [{
|
|
344
1171
|
type: Inject,
|
|
345
1172
|
args: ['UserRepository']
|
|
346
|
-
}] }, { type:
|
|
1173
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
347
1174
|
type: Inject,
|
|
348
1175
|
args: [DEFAULT_SHOP]
|
|
349
1176
|
}] }]; } });
|
|
350
1177
|
|
|
351
1178
|
class CartService {
|
|
352
|
-
constructor(authService, checkoutService, defaultShop, productRepository) {
|
|
1179
|
+
constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
|
|
353
1180
|
this.authService = authService;
|
|
354
1181
|
this.checkoutService = checkoutService;
|
|
355
1182
|
this.defaultShop = defaultShop;
|
|
356
1183
|
this.productRepository = productRepository;
|
|
1184
|
+
this.categoryRepository = categoryRepository;
|
|
1185
|
+
this.variantRepository = variantRepository;
|
|
1186
|
+
this.buy2WinRepository = buy2WinRepository;
|
|
357
1187
|
this.cartSubject = new Subject();
|
|
358
1188
|
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
359
1189
|
const items = [];
|
|
360
|
-
const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.
|
|
1190
|
+
const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
361
1191
|
if (index > -1) {
|
|
362
1192
|
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
363
1193
|
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
@@ -368,27 +1198,27 @@ class CartService {
|
|
|
368
1198
|
.updateCheckoutLineItems(checkoutLoaded)
|
|
369
1199
|
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
370
1200
|
}));
|
|
371
|
-
this.generateCartObject = (items) => {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
...(cart[item.
|
|
375
|
-
quantity: (cart[item.
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
};
|
|
1201
|
+
this.generateCartObject = (items) => items?.reduce((cart, item) => ({
|
|
1202
|
+
...cart,
|
|
1203
|
+
[item.id]: LineItem.toInstance({
|
|
1204
|
+
...(cart[item.id] || item),
|
|
1205
|
+
quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
|
|
1206
|
+
}),
|
|
1207
|
+
}), {}) || {};
|
|
379
1208
|
this.buildLineItem = async ({ checkout, item, quantity, }) => {
|
|
380
|
-
const product = await this.
|
|
381
|
-
item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.
|
|
1209
|
+
const product = await this.getProductData(item.id);
|
|
1210
|
+
item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
|
|
382
1211
|
if (this.checkMaxStock(item, quantity || 0))
|
|
383
1212
|
throw new Error('Desculpe! Temos apenas ' + item.stock?.quantity + ' em estoque.');
|
|
384
1213
|
const image = item.image || item.images?.shift();
|
|
385
|
-
const { id, name, EAN,
|
|
1214
|
+
const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
|
|
386
1215
|
const isGift = item.isGift || null;
|
|
387
1216
|
const pricePaid = this.getProductPrice({
|
|
388
1217
|
product: item,
|
|
389
1218
|
shop: checkout.shop || this.defaultShop,
|
|
390
1219
|
isSubscriber: checkout.user?.isSubscriber,
|
|
391
1220
|
});
|
|
1221
|
+
RoundProductPricesHelper.roundProductPrices(item);
|
|
392
1222
|
return {
|
|
393
1223
|
checkout,
|
|
394
1224
|
lineItem: LineItem.toInstance({
|
|
@@ -399,7 +1229,7 @@ class CartService {
|
|
|
399
1229
|
slug: slug ?? product.slug,
|
|
400
1230
|
sku: sku ?? product.sku,
|
|
401
1231
|
stock,
|
|
402
|
-
price,
|
|
1232
|
+
price: this.roundPrice(price),
|
|
403
1233
|
image,
|
|
404
1234
|
weight: weight ?? product.weight,
|
|
405
1235
|
quantity: (item.quantity || 0) + (quantity || 0),
|
|
@@ -415,7 +1245,9 @@ class CartService {
|
|
|
415
1245
|
const info = product.price;
|
|
416
1246
|
if (product.isGift)
|
|
417
1247
|
return 0;
|
|
418
|
-
return isSubscriber && info.subscriberPrice > 0
|
|
1248
|
+
return isSubscriber && info.subscriberPrice > 0
|
|
1249
|
+
? Number(info.subscriberPrice.toFixed(2))
|
|
1250
|
+
: Number(info.price.toFixed(2));
|
|
419
1251
|
};
|
|
420
1252
|
this.checkMaxStock = (item, quantity) => {
|
|
421
1253
|
const maxStock = item.stock?.quantity || 0;
|
|
@@ -428,7 +1260,7 @@ class CartService {
|
|
|
428
1260
|
}
|
|
429
1261
|
decreaseItem(item) {
|
|
430
1262
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
431
|
-
const checkoutItem = checkout.lineItems?.find((lineItem) => lineItem.
|
|
1263
|
+
const checkoutItem = checkout.lineItems?.find((lineItem) => lineItem.id === item.id);
|
|
432
1264
|
if (!isNil(checkoutItem))
|
|
433
1265
|
checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
|
|
434
1266
|
return checkout;
|
|
@@ -446,17 +1278,21 @@ class CartService {
|
|
|
446
1278
|
}
|
|
447
1279
|
removeItem(item) {
|
|
448
1280
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
449
|
-
const index = checkout.lineItems.findIndex((lineItem) => lineItem.
|
|
1281
|
+
const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
|
|
450
1282
|
if (index >= 0)
|
|
451
1283
|
checkout.lineItems.splice(index, 1);
|
|
452
1284
|
return checkout;
|
|
453
1285
|
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
454
1286
|
}
|
|
455
1287
|
updateUserCart(user) {
|
|
456
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => this.checkoutService
|
|
1288
|
+
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => this.checkoutService
|
|
1289
|
+
.updateCheckoutLineItems(Checkout.toInstance({
|
|
457
1290
|
...checkout.toPlain(),
|
|
458
|
-
lineItems: checkout.lineItems?.length
|
|
459
|
-
|
|
1291
|
+
lineItems: checkout.lineItems?.length
|
|
1292
|
+
? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
|
|
1293
|
+
: [],
|
|
1294
|
+
}))
|
|
1295
|
+
.toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
460
1296
|
}
|
|
461
1297
|
clearCart() {
|
|
462
1298
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
@@ -467,843 +1303,761 @@ class CartService {
|
|
|
467
1303
|
buildCartFromCheckout(checkoutData) {
|
|
468
1304
|
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
469
1305
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}] }, { type: undefined, decorators: [{
|
|
479
|
-
type: Inject,
|
|
480
|
-
args: ['ProductRepository']
|
|
481
|
-
}] }]; } });
|
|
482
|
-
|
|
483
|
-
class CheckoutSubscriptionService {
|
|
484
|
-
constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
|
|
485
|
-
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
486
|
-
this.subscriptionRepository = subscriptionRepository;
|
|
487
|
-
this.couponService = couponService;
|
|
488
|
-
}
|
|
489
|
-
getCheckoutSubscription(checkoutData) {
|
|
490
|
-
const checkoutId = cookie.get('checkoutSubscriptionId');
|
|
491
|
-
if (!isNil(checkoutId))
|
|
492
|
-
return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
|
|
493
|
-
return from(this.createCheckoutSubscription(checkoutData));
|
|
494
|
-
}
|
|
495
|
-
async createCheckoutSubscription(checkoutData) {
|
|
496
|
-
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
497
|
-
createdAt: new Date(),
|
|
498
|
-
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
499
|
-
});
|
|
500
|
-
cookie.set('checkoutSubscriptionId', checkout.id);
|
|
501
|
-
return checkout;
|
|
502
|
-
}
|
|
503
|
-
clearCheckoutSubscriptionFromSession() {
|
|
504
|
-
cookie.remove('checkoutSubscriptionId');
|
|
505
|
-
return of();
|
|
506
|
-
}
|
|
507
|
-
checkCoupon(nickname, userEmail) {
|
|
508
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, null, true).pipe()));
|
|
509
|
-
}
|
|
510
|
-
calcDiscountSubscription(coupon) {
|
|
511
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
1306
|
+
roundPrice(productPrice) {
|
|
1307
|
+
const { price, fullPrice, subscriberPrice } = productPrice;
|
|
1308
|
+
return {
|
|
1309
|
+
...productPrice,
|
|
1310
|
+
price: Number(price.toFixed(2)),
|
|
1311
|
+
fullPrice: Number(fullPrice.toFixed(2)),
|
|
1312
|
+
...(subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }),
|
|
1313
|
+
};
|
|
512
1314
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
1315
|
+
async getProductData(productId) {
|
|
1316
|
+
let product;
|
|
1317
|
+
let variant;
|
|
1318
|
+
try {
|
|
1319
|
+
product = await this.productRepository.get({ id: productId });
|
|
1320
|
+
}
|
|
1321
|
+
catch (error) {
|
|
1322
|
+
if (!(error instanceof NotFoundError))
|
|
1323
|
+
throw error;
|
|
1324
|
+
const { data: variants } = await this.variantRepository.find({ filters: { id: productId } });
|
|
1325
|
+
variant = variants.shift();
|
|
1326
|
+
if (!variant)
|
|
1327
|
+
throw error;
|
|
1328
|
+
product = await this.productRepository.get({ id: variant.productId });
|
|
1329
|
+
}
|
|
1330
|
+
return {
|
|
1331
|
+
...product.toPlain(),
|
|
1332
|
+
...(variant && { ...variant.toPlain() }),
|
|
1333
|
+
};
|
|
531
1334
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
.
|
|
535
|
-
|
|
536
|
-
|
|
1335
|
+
getGifts() {
|
|
1336
|
+
return this.checkoutService.getCheckout().pipe(mergeMap(async (checkout) => {
|
|
1337
|
+
const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
|
|
1338
|
+
if (!notGiftItems.length)
|
|
1339
|
+
return { ...checkout, lineItems: [] };
|
|
1340
|
+
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
1341
|
+
const campaigns = await this.buy2WinRepository
|
|
1342
|
+
.find({
|
|
1343
|
+
filters: {
|
|
1344
|
+
active: { operator: Where.EQUALS, value: true },
|
|
1345
|
+
shop: { operator: Where.EQUALS, value: this.defaultShop },
|
|
1346
|
+
},
|
|
1347
|
+
})
|
|
1348
|
+
.then((data) => data.data);
|
|
1349
|
+
if (!campaigns.length)
|
|
1350
|
+
return { ...checkout, lineItems: notGiftItems };
|
|
1351
|
+
const elegibleCampaigns = [];
|
|
1352
|
+
for (const campaign of campaigns) {
|
|
1353
|
+
const today = new Date().getDate();
|
|
1354
|
+
if (!(campaign.startDate.getDate() <= today) && !(campaign.endDate.getDate() >= today))
|
|
1355
|
+
continue;
|
|
1356
|
+
if (campaign.activeCategory) {
|
|
1357
|
+
const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
|
|
1358
|
+
const categoriesCampaingFullTree = [];
|
|
1359
|
+
for (const id of categoriesCampaing) {
|
|
1360
|
+
const children = await this.categoryRepository.getChildren(parseInt(id));
|
|
1361
|
+
categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
|
|
1362
|
+
}
|
|
1363
|
+
const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
|
|
1364
|
+
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
1365
|
+
if (!l.categories || !l.categories?.length)
|
|
1366
|
+
return true;
|
|
1367
|
+
return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
|
|
1368
|
+
});
|
|
1369
|
+
if (filterProductsCategories.length) {
|
|
1370
|
+
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
1371
|
+
if (cartTotalCategories >= campaign.cartValueMin)
|
|
1372
|
+
elegibleCampaigns.push(campaign);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
else {
|
|
1376
|
+
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
1377
|
+
if (campaign.cartValue <= cartTotal)
|
|
1378
|
+
elegibleCampaigns.push(campaign);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
if (!elegibleCampaigns.length)
|
|
1383
|
+
return { ...checkout, lineItems: notGiftItems };
|
|
1384
|
+
const campaingnProducts = [];
|
|
1385
|
+
for (const campaign of elegibleCampaigns) {
|
|
1386
|
+
let elegibleProducts = [];
|
|
1387
|
+
for (const product of campaign.products) {
|
|
1388
|
+
const { data: productData } = await this.productRepository.find({ filters: { sku: product } });
|
|
1389
|
+
if (!productData.length)
|
|
1390
|
+
continue;
|
|
1391
|
+
const gift = productData.shift();
|
|
1392
|
+
if (gift.stock.quantity < 1)
|
|
1393
|
+
continue;
|
|
1394
|
+
elegibleProducts.push(gift);
|
|
1395
|
+
}
|
|
1396
|
+
campaingnProducts.push(elegibleProducts);
|
|
1397
|
+
}
|
|
1398
|
+
if (!campaingnProducts.length)
|
|
1399
|
+
return { ...checkout, lineItems: notGiftItems };
|
|
1400
|
+
const gifts = this.giftToLineItems([].concat(...campaingnProducts));
|
|
1401
|
+
return { ...checkout, lineItems: notGiftItems.concat(gifts) };
|
|
1402
|
+
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
537
1403
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
'price',
|
|
559
|
-
'reviews',
|
|
560
|
-
'hasVariants',
|
|
561
|
-
'slug',
|
|
562
|
-
'sku',
|
|
563
|
-
'stock',
|
|
564
|
-
'costPrice',
|
|
565
|
-
'images',
|
|
566
|
-
'miniatures',
|
|
567
|
-
'name',
|
|
568
|
-
'weight',
|
|
569
|
-
'rate',
|
|
570
|
-
'type',
|
|
571
|
-
]))) || [],
|
|
1404
|
+
giftToLineItems(items) {
|
|
1405
|
+
return items.map((item) => {
|
|
1406
|
+
const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
1407
|
+
const image = item?.miniatures?.length ? item.miniatures[0] : item.images[0];
|
|
1408
|
+
return LineItem.toInstance({
|
|
1409
|
+
brand,
|
|
1410
|
+
categories,
|
|
1411
|
+
id: id.toString(),
|
|
1412
|
+
name,
|
|
1413
|
+
price,
|
|
1414
|
+
sku,
|
|
1415
|
+
slug,
|
|
1416
|
+
stock,
|
|
1417
|
+
weight,
|
|
1418
|
+
EAN,
|
|
1419
|
+
image,
|
|
1420
|
+
pricePaid: 0,
|
|
1421
|
+
quantity: 1,
|
|
1422
|
+
isGift: true,
|
|
1423
|
+
});
|
|
572
1424
|
});
|
|
573
1425
|
}
|
|
574
|
-
get homeId() {
|
|
575
|
-
if (this.defaultShop === Shops.GLAMSHOP)
|
|
576
|
-
return 'glamshop';
|
|
577
|
-
if (this.defaultShop === Shops.MENSMARKET)
|
|
578
|
-
return 'mens_market';
|
|
579
|
-
return null;
|
|
580
|
-
}
|
|
581
|
-
getHomeData() {
|
|
582
|
-
return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
|
|
583
|
-
? of(home)
|
|
584
|
-
: forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
|
|
585
|
-
discoverProducts,
|
|
586
|
-
featuredProducts,
|
|
587
|
-
verticalProducts,
|
|
588
|
-
})), concatMap((data) => this.saveHomeData(data)))));
|
|
589
|
-
}
|
|
590
|
-
getBanners(type) {
|
|
591
|
-
return this.getHomeConfiguration().pipe(map((home) => {
|
|
592
|
-
if (type === 'brand')
|
|
593
|
-
return home.brandsCarousel;
|
|
594
|
-
if (type === 'buyToWin')
|
|
595
|
-
return [home.buyToWinBanner];
|
|
596
|
-
if (type === 'block')
|
|
597
|
-
return home.blockBanners;
|
|
598
|
-
if (type === 'blog')
|
|
599
|
-
return [home.blogBanner];
|
|
600
|
-
return [];
|
|
601
|
-
}));
|
|
602
|
-
}
|
|
603
|
-
getMinValueForFreeShipping() {
|
|
604
|
-
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
605
|
-
}
|
|
606
|
-
getDiscoverProducts() {
|
|
607
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
608
|
-
}
|
|
609
|
-
getFeaturedProducts() {
|
|
610
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
611
|
-
}
|
|
612
|
-
getVerticalProducts() {
|
|
613
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => forkJoin(home.verticalCarousels.filter(Boolean).map((id) => from(this.categoryRepository.get({ id })).pipe(concatMap((category) => from(this.productRepository.find({
|
|
614
|
-
filters: { categories: { operator: Where.IN, value: [category.id] } },
|
|
615
|
-
limits: { limit: 12 },
|
|
616
|
-
})).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
|
|
617
|
-
}
|
|
618
|
-
getHomeConfiguration() {
|
|
619
|
-
return of(this.homeConfiguration).pipe(concatMap((home) => home
|
|
620
|
-
? of(home)
|
|
621
|
-
: !this.homeId
|
|
622
|
-
? throwError(new RequiredArgumentError(['homeId']))
|
|
623
|
-
: from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
|
|
624
|
-
}
|
|
625
|
-
saveHomeData(homeData) {
|
|
626
|
-
const data = {
|
|
627
|
-
createdAt: new Date(),
|
|
628
|
-
expiresAt: add(new Date(), { hours: 1 }),
|
|
629
|
-
data: homeData,
|
|
630
|
-
};
|
|
631
|
-
return from(this.homeRepository.update({
|
|
632
|
-
id: this.homeId,
|
|
633
|
-
data,
|
|
634
|
-
})).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
|
|
635
|
-
}
|
|
636
1426
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type:
|
|
1427
|
+
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: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1428
|
+
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
1429
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
640
1430
|
type: Injectable
|
|
641
|
-
}], ctorParameters: function () { return [{ type:
|
|
1431
|
+
}], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$3.Shops, decorators: [{
|
|
642
1432
|
type: Inject,
|
|
643
|
-
args: [
|
|
1433
|
+
args: [DEFAULT_SHOP]
|
|
644
1434
|
}] }, { type: undefined, decorators: [{
|
|
645
1435
|
type: Inject,
|
|
646
|
-
args: ['
|
|
1436
|
+
args: ['ProductRepository']
|
|
647
1437
|
}] }, { type: undefined, decorators: [{
|
|
648
1438
|
type: Inject,
|
|
649
|
-
args: ['
|
|
650
|
-
}] }, { type:
|
|
1439
|
+
args: ['CategoryRepository']
|
|
1440
|
+
}] }, { type: undefined, decorators: [{
|
|
651
1441
|
type: Inject,
|
|
652
|
-
args: [
|
|
1442
|
+
args: ['VariantRepository']
|
|
1443
|
+
}] }, { type: i1$3.Buy2WinFirestoreRepository, decorators: [{
|
|
1444
|
+
type: Inject,
|
|
1445
|
+
args: ['Buy2WinRepository']
|
|
653
1446
|
}] }]; } });
|
|
654
1447
|
|
|
655
|
-
class
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
1448
|
+
class CatalogService {
|
|
1449
|
+
constructor(productRepository, categoryStructureAdapter, shop) {
|
|
1450
|
+
this.productRepository = productRepository;
|
|
1451
|
+
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
1452
|
+
this.shop = shop;
|
|
1453
|
+
this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
|
|
1454
|
+
const filters = {};
|
|
1455
|
+
if (clubDiscount?.length)
|
|
1456
|
+
set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
|
|
1457
|
+
if (brands?.length)
|
|
1458
|
+
filters.brand = { operator: Where.IN, value: brands };
|
|
1459
|
+
if (gender?.length)
|
|
1460
|
+
filters.tags = {
|
|
1461
|
+
operator: Where.IN,
|
|
1462
|
+
value: gender
|
|
1463
|
+
.map((genderOptions) => genderOptions === 'female' ? 'feminino' : genderOptions === 'male' ? 'masculino' : null)
|
|
1464
|
+
.filter(Boolean),
|
|
1465
|
+
};
|
|
1466
|
+
if (prices?.min || prices?.max)
|
|
1467
|
+
set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
|
|
1468
|
+
...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
|
|
1469
|
+
...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
|
|
1470
|
+
]);
|
|
1471
|
+
if (rate)
|
|
1472
|
+
filters.rate = { operator: Where.GTE, value: rate };
|
|
1473
|
+
if (tags?.length)
|
|
1474
|
+
filters.tags = { operator: Where.LIKE, value: tags };
|
|
1475
|
+
if (customOptions?.length)
|
|
1476
|
+
filters.filters = { operator: Where.LIKE, value: customOptions };
|
|
1477
|
+
return filters;
|
|
663
1478
|
};
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
return
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
provide: 'AuthenticationService',
|
|
678
|
-
useFactory: (angularFireAuth) => {
|
|
679
|
-
return new AuthenticationFirebaseAuthService(angularFireAuth);
|
|
680
|
-
},
|
|
681
|
-
deps: [Auth],
|
|
682
|
-
},
|
|
683
|
-
{
|
|
684
|
-
provide: 'Register',
|
|
685
|
-
useFactory: (registerService, userRepository) => {
|
|
686
|
-
return new Register(registerService, userRepository);
|
|
687
|
-
},
|
|
688
|
-
deps: ['RegisterService', 'UserRepository'],
|
|
689
|
-
},
|
|
690
|
-
{
|
|
691
|
-
provide: 'RegisterService',
|
|
692
|
-
useFactory: (angularFireAuth) => {
|
|
693
|
-
return new RegisterFirebaseAuthService(angularFireAuth);
|
|
694
|
-
},
|
|
695
|
-
deps: [Auth],
|
|
696
|
-
},
|
|
697
|
-
{
|
|
698
|
-
provide: 'SignOut',
|
|
699
|
-
useFactory: (authenticationService) => {
|
|
700
|
-
return new SignOut(authenticationService);
|
|
701
|
-
},
|
|
702
|
-
deps: ['AuthenticationService'],
|
|
703
|
-
},
|
|
704
|
-
{
|
|
705
|
-
provide: 'RecoveryPassword',
|
|
706
|
-
useFactory: (authenticationService) => {
|
|
707
|
-
return new RecoveryPassword(authenticationService);
|
|
708
|
-
},
|
|
709
|
-
deps: ['AuthenticationService'],
|
|
710
|
-
},
|
|
711
|
-
], imports: [provideFirebaseApp((injector) => {
|
|
712
|
-
const appName = injector.get(FIREBASE_APP_NAME);
|
|
713
|
-
return appName
|
|
714
|
-
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
715
|
-
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
716
|
-
}),
|
|
717
|
-
provideAuth(() => getAuth())] });
|
|
718
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
|
|
719
|
-
type: NgModule,
|
|
720
|
-
args: [{
|
|
721
|
-
imports: [
|
|
722
|
-
provideFirebaseApp((injector) => {
|
|
723
|
-
const appName = injector.get(FIREBASE_APP_NAME);
|
|
724
|
-
return appName
|
|
725
|
-
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
726
|
-
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
727
|
-
}),
|
|
728
|
-
provideAuth(() => getAuth()),
|
|
729
|
-
],
|
|
730
|
-
providers: [
|
|
731
|
-
{
|
|
732
|
-
provide: 'Authentication',
|
|
733
|
-
useFactory: (authenticationService, userRepository) => {
|
|
734
|
-
return new Authentication(authenticationService, userRepository);
|
|
735
|
-
},
|
|
736
|
-
deps: ['AuthenticationService', 'UserRepository'],
|
|
737
|
-
},
|
|
738
|
-
{
|
|
739
|
-
provide: 'AuthenticationService',
|
|
740
|
-
useFactory: (angularFireAuth) => {
|
|
741
|
-
return new AuthenticationFirebaseAuthService(angularFireAuth);
|
|
742
|
-
},
|
|
743
|
-
deps: [Auth],
|
|
744
|
-
},
|
|
745
|
-
{
|
|
746
|
-
provide: 'Register',
|
|
747
|
-
useFactory: (registerService, userRepository) => {
|
|
748
|
-
return new Register(registerService, userRepository);
|
|
749
|
-
},
|
|
750
|
-
deps: ['RegisterService', 'UserRepository'],
|
|
751
|
-
},
|
|
752
|
-
{
|
|
753
|
-
provide: 'RegisterService',
|
|
754
|
-
useFactory: (angularFireAuth) => {
|
|
755
|
-
return new RegisterFirebaseAuthService(angularFireAuth);
|
|
756
|
-
},
|
|
757
|
-
deps: [Auth],
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
provide: 'SignOut',
|
|
761
|
-
useFactory: (authenticationService) => {
|
|
762
|
-
return new SignOut(authenticationService);
|
|
763
|
-
},
|
|
764
|
-
deps: ['AuthenticationService'],
|
|
765
|
-
},
|
|
766
|
-
{
|
|
767
|
-
provide: 'RecoveryPassword',
|
|
768
|
-
useFactory: (authenticationService) => {
|
|
769
|
-
return new RecoveryPassword(authenticationService);
|
|
770
|
-
},
|
|
771
|
-
deps: ['AuthenticationService'],
|
|
772
|
-
},
|
|
773
|
-
],
|
|
774
|
-
}]
|
|
775
|
-
}] });
|
|
776
|
-
|
|
777
|
-
class AngularElasticSeachModule {
|
|
778
|
-
static initializeApp(options) {
|
|
779
|
-
return {
|
|
780
|
-
ngModule: AngularElasticSeachModule,
|
|
781
|
-
providers: [{ provide: ES_CONFIG, useValue: options }],
|
|
1479
|
+
this.buildSortQuery = (sort) => {
|
|
1480
|
+
if (!sort || sort === 'most-relevant')
|
|
1481
|
+
return {};
|
|
1482
|
+
if (sort === 'best-sellers')
|
|
1483
|
+
return { shoppingCount: 'desc' };
|
|
1484
|
+
if (sort === 'biggest-price')
|
|
1485
|
+
return { price: 'desc' };
|
|
1486
|
+
if (sort === 'lowest-price')
|
|
1487
|
+
return { price: 'asc' };
|
|
1488
|
+
if (sort === 'best-rating')
|
|
1489
|
+
return { rate: 'desc' };
|
|
1490
|
+
if (sort === 'news')
|
|
1491
|
+
return { createdAt: 'desc' };
|
|
782
1492
|
};
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
provide: ProductsIndex,
|
|
790
|
-
useFactory: (configuration) => {
|
|
791
|
-
return new ProductsIndex(new AxiosAdapter(configuration));
|
|
792
|
-
},
|
|
793
|
-
deps: [ES_CONFIG],
|
|
794
|
-
},
|
|
795
|
-
] });
|
|
796
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
|
|
797
|
-
type: NgModule,
|
|
798
|
-
args: [{
|
|
799
|
-
providers: [
|
|
800
|
-
{
|
|
801
|
-
provide: ProductsIndex,
|
|
802
|
-
useFactory: (configuration) => {
|
|
803
|
-
return new ProductsIndex(new AxiosAdapter(configuration));
|
|
804
|
-
},
|
|
805
|
-
deps: [ES_CONFIG],
|
|
806
|
-
},
|
|
807
|
-
],
|
|
808
|
-
}]
|
|
809
|
-
}] });
|
|
810
|
-
|
|
811
|
-
class AngularFirestoreModule {
|
|
812
|
-
static initializeApp(options, nameOrConfig) {
|
|
813
|
-
return {
|
|
814
|
-
ngModule: AngularFirestoreModule,
|
|
815
|
-
providers: [
|
|
816
|
-
{ provide: FIREBASE_OPTIONS, useValue: options.firebase },
|
|
817
|
-
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
818
|
-
{ provide: ES_CONFIG, useValue: options.elasticSearch },
|
|
819
|
-
],
|
|
1493
|
+
this.buildLimitQuery = (options) => {
|
|
1494
|
+
const limit = options?.perPage || 20;
|
|
1495
|
+
return {
|
|
1496
|
+
limit,
|
|
1497
|
+
offset: ((options?.page || 1) - 1) * limit,
|
|
1498
|
+
};
|
|
820
1499
|
};
|
|
821
1500
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
return new UserBeautyProfileFirestoreRepository(firestore, userRepository);
|
|
830
|
-
},
|
|
831
|
-
deps: [Firestore, 'UserRepository'],
|
|
832
|
-
},
|
|
833
|
-
{
|
|
834
|
-
provide: 'Buy2WinRepository',
|
|
835
|
-
useFactory: (firestore) => {
|
|
836
|
-
return new Buy2WinFirestoreRepository(firestore);
|
|
837
|
-
},
|
|
838
|
-
deps: [Firestore],
|
|
839
|
-
},
|
|
840
|
-
{
|
|
841
|
-
provide: CategoryFirestoreRepository,
|
|
842
|
-
useFactory: (firestore) => {
|
|
843
|
-
return new CategoryFirestoreRepository(firestore);
|
|
844
|
-
},
|
|
845
|
-
deps: [Firestore],
|
|
846
|
-
},
|
|
847
|
-
{
|
|
848
|
-
provide: 'CheckoutRepository',
|
|
849
|
-
useFactory: (firestore) => {
|
|
850
|
-
return new CheckoutFirestoreRepository(firestore);
|
|
851
|
-
},
|
|
852
|
-
deps: [Firestore],
|
|
853
|
-
},
|
|
854
|
-
{
|
|
855
|
-
provide: 'CheckoutSubscriptionRepository',
|
|
856
|
-
useFactory: (firestore) => {
|
|
857
|
-
return new CheckoutSubscriptionFirestoreRepository(firestore);
|
|
858
|
-
},
|
|
859
|
-
deps: [Firestore],
|
|
860
|
-
},
|
|
861
|
-
{
|
|
862
|
-
provide: 'CouponRepository',
|
|
863
|
-
useFactory: (firestore) => {
|
|
864
|
-
return new CouponFirestoreRepository(firestore);
|
|
865
|
-
},
|
|
866
|
-
deps: [Firestore],
|
|
867
|
-
},
|
|
868
|
-
{
|
|
869
|
-
provide: 'EditionRepository',
|
|
870
|
-
useFactory: (firestore, subscriptionRepository) => {
|
|
871
|
-
return new SubscriptionEditionFirestoreRepository(firestore, subscriptionRepository);
|
|
872
|
-
},
|
|
873
|
-
deps: [Firestore, 'SubscriptionRepository'],
|
|
874
|
-
},
|
|
875
|
-
{
|
|
876
|
-
provide: 'HomeRepository',
|
|
877
|
-
useFactory: (firestore) => {
|
|
878
|
-
return new HomeFirestoreRepository(firestore);
|
|
879
|
-
},
|
|
880
|
-
deps: [Firestore],
|
|
881
|
-
},
|
|
882
|
-
{
|
|
883
|
-
provide: 'LeadRepository',
|
|
884
|
-
useFactory: (firestore) => {
|
|
885
|
-
return new LeadFirestoreRepository(firestore);
|
|
886
|
-
},
|
|
887
|
-
deps: [Firestore],
|
|
888
|
-
},
|
|
889
|
-
{
|
|
890
|
-
provide: 'LegacyOrderRepository',
|
|
891
|
-
useFactory: (firestore) => {
|
|
892
|
-
return new LegacyOrderFirestoreRepository(firestore);
|
|
893
|
-
},
|
|
894
|
-
deps: [Firestore],
|
|
895
|
-
},
|
|
896
|
-
{
|
|
897
|
-
provide: 'ShopMenuRepository',
|
|
898
|
-
useFactory: (firestore) => {
|
|
899
|
-
return new ShopMenuFirestoreRepository(firestore);
|
|
900
|
-
},
|
|
901
|
-
deps: [Firestore],
|
|
902
|
-
},
|
|
903
|
-
{
|
|
904
|
-
provide: 'OrderRepository',
|
|
905
|
-
useFactory: (firestore) => {
|
|
906
|
-
return new OrderFirestoreRepository(firestore);
|
|
907
|
-
},
|
|
908
|
-
deps: [Firestore],
|
|
909
|
-
},
|
|
910
|
-
{
|
|
911
|
-
provide: 'PaymentRepository',
|
|
912
|
-
useFactory: (firestore) => {
|
|
913
|
-
return new PaymentFirestoreRepository(firestore);
|
|
914
|
-
},
|
|
915
|
-
deps: [Firestore],
|
|
916
|
-
},
|
|
917
|
-
{
|
|
918
|
-
provide: ProductFirestoreRepository,
|
|
919
|
-
useFactory: (firestore) => {
|
|
920
|
-
return new ProductFirestoreRepository(firestore);
|
|
921
|
-
},
|
|
922
|
-
deps: [Firestore],
|
|
923
|
-
},
|
|
924
|
-
{
|
|
925
|
-
provide: 'SubscriptionPaymentRepository',
|
|
926
|
-
useFactory: (firestore, subscriptionRepository) => {
|
|
927
|
-
return new SubscriptionPaymentFirestoreRepository(firestore, subscriptionRepository);
|
|
928
|
-
},
|
|
929
|
-
deps: [Firestore, 'SubscriptionRepository'],
|
|
930
|
-
},
|
|
931
|
-
{
|
|
932
|
-
provide: 'SubscriptionPlanRepository',
|
|
933
|
-
useFactory: (firestore) => {
|
|
934
|
-
return new SubscriptionPlanFirestoreRepository(firestore);
|
|
935
|
-
},
|
|
936
|
-
deps: [Firestore],
|
|
937
|
-
},
|
|
938
|
-
{
|
|
939
|
-
provide: 'SubscriptionProductRepository',
|
|
940
|
-
useFactory: (firestore) => {
|
|
941
|
-
return new SubscriptionProductFirestoreRepository(firestore);
|
|
942
|
-
},
|
|
943
|
-
deps: [Firestore],
|
|
944
|
-
},
|
|
945
|
-
{
|
|
946
|
-
provide: 'SubscriptionRepository',
|
|
947
|
-
useFactory: (firestore) => {
|
|
948
|
-
return new SubscriptionFirestoreRepository(firestore);
|
|
949
|
-
},
|
|
950
|
-
deps: [Firestore],
|
|
951
|
-
},
|
|
952
|
-
{
|
|
953
|
-
provide: 'UserRepository',
|
|
954
|
-
useFactory: (firestore) => {
|
|
955
|
-
return new UserFirestoreRepository(firestore);
|
|
956
|
-
},
|
|
957
|
-
deps: [Firestore],
|
|
958
|
-
},
|
|
959
|
-
{
|
|
960
|
-
provide: 'UserAddressRepository',
|
|
961
|
-
useFactory: (firestore, userRepository) => {
|
|
962
|
-
return new UserAddressFirestoreRepository(firestore, userRepository);
|
|
1501
|
+
async fetchProducts(category, options) {
|
|
1502
|
+
const limits = this.buildLimitQuery(options);
|
|
1503
|
+
return await this.productRepository
|
|
1504
|
+
.findCatalog({
|
|
1505
|
+
filters: {
|
|
1506
|
+
...(await this.categoryStructureAdapter.buildProductFilterByCategory(category)),
|
|
1507
|
+
...this.buildFilterQuery(options?.filters || {}),
|
|
963
1508
|
},
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1509
|
+
...(options?.sort ? { orderBy: this.buildSortQuery(options?.sort) } : {}),
|
|
1510
|
+
limits,
|
|
1511
|
+
options: { minimal: ['price'], maximum: ['price'] },
|
|
1512
|
+
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
|
|
1513
|
+
.then(({ data, count: total, maximum, minimal }) => ({
|
|
1514
|
+
products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
|
|
1515
|
+
pages: Math.ceil(total / limits.limit),
|
|
1516
|
+
prices: {
|
|
1517
|
+
price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
|
|
1518
|
+
subscriberPrice: {
|
|
1519
|
+
min: +minimal?.price?.subscriberPrice?.toFixed(2),
|
|
1520
|
+
max: +maximum?.price?.subscriberPrice?.toFixed(2),
|
|
1521
|
+
},
|
|
970
1522
|
},
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1523
|
+
}));
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1527
|
+
CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
|
|
1528
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
|
|
1529
|
+
type: Injectable
|
|
1530
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1531
|
+
type: Inject,
|
|
1532
|
+
args: ['ProductRepository']
|
|
1533
|
+
}] }, { type: undefined, decorators: [{
|
|
1534
|
+
type: Inject,
|
|
1535
|
+
args: [CATEGORY_STRUCTURE]
|
|
1536
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
1537
|
+
type: Inject,
|
|
1538
|
+
args: [DEFAULT_SHOP]
|
|
1539
|
+
}] }]; } });
|
|
1540
|
+
|
|
1541
|
+
class CategoryService {
|
|
1542
|
+
constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
|
|
1543
|
+
this.productRepository = productRepository;
|
|
1544
|
+
this.categoryRepository = categoryRepository;
|
|
1545
|
+
this.categoryFilterRepository = categoryFilterRepository;
|
|
1546
|
+
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
1547
|
+
this.shop = shop;
|
|
1548
|
+
}
|
|
1549
|
+
async fetchBrands(category, mainGender) {
|
|
1550
|
+
const brands = await this.productRepository
|
|
1551
|
+
.findCatalog({
|
|
1552
|
+
filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
|
|
1553
|
+
fields: ['brand'],
|
|
1554
|
+
}, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
|
|
1555
|
+
.then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
|
|
1556
|
+
return this.categoryRepository
|
|
1557
|
+
.find({ filters: { brandCategory: true }, orderBy: { name: 'asc' } })
|
|
1558
|
+
.then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
|
|
1559
|
+
}
|
|
1560
|
+
async fetchFilterOptions(category, filters) {
|
|
1561
|
+
return await this.categoryFilterRepository
|
|
1562
|
+
.find({ filters: { categoryId: +category.id } })
|
|
1563
|
+
.then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'CategoryFilterRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1567
|
+
CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
|
|
1568
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
|
|
1569
|
+
type: Injectable
|
|
1570
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1571
|
+
type: Inject,
|
|
1572
|
+
args: ['ProductRepository']
|
|
1573
|
+
}] }, { type: undefined, decorators: [{
|
|
1574
|
+
type: Inject,
|
|
1575
|
+
args: ['CategoryRepository']
|
|
1576
|
+
}] }, { type: undefined, decorators: [{
|
|
1577
|
+
type: Inject,
|
|
1578
|
+
args: ['CategoryFilterRepository']
|
|
1579
|
+
}] }, { type: undefined, decorators: [{
|
|
1580
|
+
type: Inject,
|
|
1581
|
+
args: [CATEGORY_STRUCTURE]
|
|
1582
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
1583
|
+
type: Inject,
|
|
1584
|
+
args: [DEFAULT_SHOP]
|
|
1585
|
+
}] }]; } });
|
|
1586
|
+
|
|
1587
|
+
var ProductSorts;
|
|
1588
|
+
(function (ProductSorts) {
|
|
1589
|
+
ProductSorts["MOST_RELEVANT"] = "most-relevant";
|
|
1590
|
+
ProductSorts["BEST_SELLER"] = "best-sellers";
|
|
1591
|
+
ProductSorts["BIGGEST_PRICE"] = "biggest-price";
|
|
1592
|
+
ProductSorts["LOWEST_PRICE"] = "lowest-price";
|
|
1593
|
+
ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
|
|
1594
|
+
ProductSorts["BEST_RATING"] = "best-rating";
|
|
1595
|
+
ProductSorts["NEWS"] = "news";
|
|
1596
|
+
})(ProductSorts || (ProductSorts = {}));
|
|
1597
|
+
|
|
1598
|
+
class CategoryWithTree extends Category {
|
|
1599
|
+
}
|
|
1600
|
+
__decorate([
|
|
1601
|
+
Type(() => CategoryWithTree),
|
|
1602
|
+
__metadata("design:type", Array)
|
|
1603
|
+
], CategoryWithTree.prototype, "children", void 0);
|
|
1604
|
+
|
|
1605
|
+
class UtilService {
|
|
1606
|
+
constructor() { }
|
|
1607
|
+
createSlug(name) {
|
|
1608
|
+
return name
|
|
1609
|
+
.toLowerCase()
|
|
1610
|
+
.replace(/\s+/g, '-') // Replace spaces with -
|
|
1611
|
+
.replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
|
|
1612
|
+
.replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
|
|
1613
|
+
.replace(/[ìíïî]/g, 'i') // Replace spaces with -
|
|
1614
|
+
.replace(/[õòóöô]/g, 'o') // Replace spaces with -
|
|
1615
|
+
.replace(/[ùúüû]/g, 'u') // Replace spaces with -
|
|
1616
|
+
.replace(/[ñ]/g, 'n') // Replace spaces with -
|
|
1617
|
+
.replace(/[ç]/g, 'c') // Replace spaces with -
|
|
1618
|
+
.replace(/[&]/g, 'and') // Replace spaces with -
|
|
1619
|
+
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
|
|
1620
|
+
.replace(/\-\-+/g, '-'); // Replace multiple - with single -
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
UtilService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: UtilService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1624
|
+
UtilService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: UtilService });
|
|
1625
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: UtilService, decorators: [{
|
|
1626
|
+
type: Injectable
|
|
1627
|
+
}], ctorParameters: function () { return []; } });
|
|
1628
|
+
|
|
1629
|
+
class NewCategoryStructureAdapter {
|
|
1630
|
+
constructor(categoryRepository, categoryCollectionChildrenRepository) {
|
|
1631
|
+
this.categoryRepository = categoryRepository;
|
|
1632
|
+
this.categoryCollectionChildrenRepository = categoryCollectionChildrenRepository;
|
|
1633
|
+
}
|
|
1634
|
+
async buildProductFilterByCategory(category) {
|
|
1635
|
+
const categoriesIds = (await this.isCollection(category))
|
|
1636
|
+
? await this.getAllCategoriesIdFromCollection(category)
|
|
1637
|
+
: [...(await this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
|
|
1638
|
+
return { category: { id: { operator: Where.IN, value: categoriesIds } } };
|
|
1639
|
+
}
|
|
1640
|
+
async getAllCategoriesIdFromCategory(category) {
|
|
1641
|
+
return this.categoryRepository
|
|
1642
|
+
.getChildren(+category.id)
|
|
1643
|
+
.then((categories) => categories.map((category) => category.id.toString()));
|
|
1644
|
+
}
|
|
1645
|
+
async getAllCategoriesIdFromCollection(category) {
|
|
1646
|
+
return this.categoryCollectionChildrenRepository
|
|
1647
|
+
.find({ filters: { collectionId: +category.id } })
|
|
1648
|
+
.then(({ data }) => data.map((categoryCollection) => categoryCollection.categoryId.toString()));
|
|
1649
|
+
}
|
|
1650
|
+
async isCollection(category) {
|
|
1651
|
+
return !isNil(category.isCollection)
|
|
1652
|
+
? category.isCollection
|
|
1653
|
+
: this.categoryRepository.get({ id: category.id }).then((category) => category.isCollection);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }, { token: 'CategoryCollectionChildrenRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1657
|
+
NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
|
|
1658
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
|
|
1659
|
+
type: Injectable
|
|
1660
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1661
|
+
type: Inject,
|
|
1662
|
+
args: ['CategoryRepository']
|
|
1663
|
+
}] }, { type: undefined, decorators: [{
|
|
1664
|
+
type: Inject,
|
|
1665
|
+
args: ['CategoryCollectionChildrenRepository']
|
|
1666
|
+
}] }]; } });
|
|
1667
|
+
|
|
1668
|
+
class OldCategoryStructureAdapter {
|
|
1669
|
+
constructor(categoryRepository) {
|
|
1670
|
+
this.categoryRepository = categoryRepository;
|
|
1671
|
+
}
|
|
1672
|
+
async buildProductFilterByCategory(category) {
|
|
1673
|
+
const productsIds = category.products?.length
|
|
1674
|
+
? category.products
|
|
1675
|
+
: await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
|
|
1676
|
+
return { id: { operator: Where.IN, value: productsIds } };
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1680
|
+
OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
|
|
1681
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
|
|
1682
|
+
type: Injectable
|
|
1683
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1684
|
+
type: Inject,
|
|
1685
|
+
args: ['CategoryRepository']
|
|
1686
|
+
}] }]; } });
|
|
1687
|
+
|
|
1688
|
+
class WishlistService {
|
|
1689
|
+
constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryCollectionChildrenRepository, categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository, categoryCollectionChildrenRepository), catalogService = new CatalogService(productRepository, categoryStructureAdapter, shop), categoryService = new CategoryService(productRepository, wishlistRepository, categoryFilterRepository, categoryStructureAdapter, shop), utilService) {
|
|
1690
|
+
this.wishlistRepository = wishlistRepository;
|
|
1691
|
+
this.shop = shop;
|
|
1692
|
+
this.catalogService = catalogService;
|
|
1693
|
+
this.categoryService = categoryService;
|
|
1694
|
+
this.utilService = utilService;
|
|
1695
|
+
}
|
|
1696
|
+
getCatalogService() {
|
|
1697
|
+
return this.catalogService;
|
|
1698
|
+
}
|
|
1699
|
+
getCategoryService() {
|
|
1700
|
+
return this.categoryService;
|
|
1701
|
+
}
|
|
1702
|
+
async create(personId, title, description, userFullName) {
|
|
1703
|
+
const data = {
|
|
1704
|
+
slug: this.utilService.createSlug(`favoritos ${userFullName} ${title}`),
|
|
1705
|
+
name: title,
|
|
1706
|
+
description,
|
|
1707
|
+
metadata: {
|
|
1708
|
+
title: `${userFullName} - ${title}`,
|
|
1709
|
+
description: `${userFullName} - ${description}`,
|
|
977
1710
|
},
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
},
|
|
1051
|
-
{
|
|
1052
|
-
provide: 'HomeRepository',
|
|
1053
|
-
useFactory: (firestore) => {
|
|
1054
|
-
return new HomeFirestoreRepository(firestore);
|
|
1055
|
-
},
|
|
1056
|
-
deps: [Firestore],
|
|
1057
|
-
},
|
|
1058
|
-
{
|
|
1059
|
-
provide: 'LeadRepository',
|
|
1060
|
-
useFactory: (firestore) => {
|
|
1061
|
-
return new LeadFirestoreRepository(firestore);
|
|
1062
|
-
},
|
|
1063
|
-
deps: [Firestore],
|
|
1064
|
-
},
|
|
1065
|
-
{
|
|
1066
|
-
provide: 'LegacyOrderRepository',
|
|
1067
|
-
useFactory: (firestore) => {
|
|
1068
|
-
return new LegacyOrderFirestoreRepository(firestore);
|
|
1069
|
-
},
|
|
1070
|
-
deps: [Firestore],
|
|
1071
|
-
},
|
|
1072
|
-
{
|
|
1073
|
-
provide: 'ShopMenuRepository',
|
|
1074
|
-
useFactory: (firestore) => {
|
|
1075
|
-
return new ShopMenuFirestoreRepository(firestore);
|
|
1076
|
-
},
|
|
1077
|
-
deps: [Firestore],
|
|
1078
|
-
},
|
|
1079
|
-
{
|
|
1080
|
-
provide: 'OrderRepository',
|
|
1081
|
-
useFactory: (firestore) => {
|
|
1082
|
-
return new OrderFirestoreRepository(firestore);
|
|
1083
|
-
},
|
|
1084
|
-
deps: [Firestore],
|
|
1085
|
-
},
|
|
1086
|
-
{
|
|
1087
|
-
provide: 'PaymentRepository',
|
|
1088
|
-
useFactory: (firestore) => {
|
|
1089
|
-
return new PaymentFirestoreRepository(firestore);
|
|
1090
|
-
},
|
|
1091
|
-
deps: [Firestore],
|
|
1092
|
-
},
|
|
1093
|
-
{
|
|
1094
|
-
provide: ProductFirestoreRepository,
|
|
1095
|
-
useFactory: (firestore) => {
|
|
1096
|
-
return new ProductFirestoreRepository(firestore);
|
|
1097
|
-
},
|
|
1098
|
-
deps: [Firestore],
|
|
1099
|
-
},
|
|
1100
|
-
{
|
|
1101
|
-
provide: 'SubscriptionPaymentRepository',
|
|
1102
|
-
useFactory: (firestore, subscriptionRepository) => {
|
|
1103
|
-
return new SubscriptionPaymentFirestoreRepository(firestore, subscriptionRepository);
|
|
1104
|
-
},
|
|
1105
|
-
deps: [Firestore, 'SubscriptionRepository'],
|
|
1106
|
-
},
|
|
1107
|
-
{
|
|
1108
|
-
provide: 'SubscriptionPlanRepository',
|
|
1109
|
-
useFactory: (firestore) => {
|
|
1110
|
-
return new SubscriptionPlanFirestoreRepository(firestore);
|
|
1111
|
-
},
|
|
1112
|
-
deps: [Firestore],
|
|
1113
|
-
},
|
|
1114
|
-
{
|
|
1115
|
-
provide: 'SubscriptionProductRepository',
|
|
1116
|
-
useFactory: (firestore) => {
|
|
1117
|
-
return new SubscriptionProductFirestoreRepository(firestore);
|
|
1118
|
-
},
|
|
1119
|
-
deps: [Firestore],
|
|
1120
|
-
},
|
|
1121
|
-
{
|
|
1122
|
-
provide: 'SubscriptionRepository',
|
|
1123
|
-
useFactory: (firestore) => {
|
|
1124
|
-
return new SubscriptionFirestoreRepository(firestore);
|
|
1125
|
-
},
|
|
1126
|
-
deps: [Firestore],
|
|
1127
|
-
},
|
|
1128
|
-
{
|
|
1129
|
-
provide: 'UserRepository',
|
|
1130
|
-
useFactory: (firestore) => {
|
|
1131
|
-
return new UserFirestoreRepository(firestore);
|
|
1132
|
-
},
|
|
1133
|
-
deps: [Firestore],
|
|
1134
|
-
},
|
|
1135
|
-
{
|
|
1136
|
-
provide: 'UserAddressRepository',
|
|
1137
|
-
useFactory: (firestore, userRepository) => {
|
|
1138
|
-
return new UserAddressFirestoreRepository(firestore, userRepository);
|
|
1139
|
-
},
|
|
1140
|
-
deps: [Firestore, 'UserRepository'],
|
|
1141
|
-
},
|
|
1142
|
-
{
|
|
1143
|
-
provide: 'UserPaymentMethodRepository',
|
|
1144
|
-
useFactory: (firestore, userRepository) => {
|
|
1145
|
-
return new UserPaymentMethodFirestoreRepository(firestore, userRepository);
|
|
1146
|
-
},
|
|
1147
|
-
deps: [Firestore, 'UserRepository'],
|
|
1148
|
-
},
|
|
1149
|
-
{
|
|
1150
|
-
provide: ProductVariantFirestoreRepository,
|
|
1151
|
-
useFactory: (firestore, productRepository) => {
|
|
1152
|
-
return new ProductVariantFirestoreRepository(firestore, productRepository);
|
|
1153
|
-
},
|
|
1154
|
-
deps: [Firestore, ProductFirestoreRepository],
|
|
1155
|
-
},
|
|
1156
|
-
],
|
|
1157
|
-
}]
|
|
1158
|
-
}] });
|
|
1711
|
+
shop: this.shop,
|
|
1712
|
+
shops: [this.shop],
|
|
1713
|
+
personId,
|
|
1714
|
+
brandCategory: false,
|
|
1715
|
+
published: true,
|
|
1716
|
+
};
|
|
1717
|
+
const newWishlist = await this.wishlistRepository.create(data);
|
|
1718
|
+
return this.wishlistRepository.update({ id: newWishlist.id, slug: `${newWishlist.id}-${newWishlist.slug}` });
|
|
1719
|
+
}
|
|
1720
|
+
update(id, title, description, userFullName) {
|
|
1721
|
+
const data = {
|
|
1722
|
+
id,
|
|
1723
|
+
slug: this.utilService.createSlug(`${id}-favoritos ${userFullName} ${title}`),
|
|
1724
|
+
name: title,
|
|
1725
|
+
description,
|
|
1726
|
+
metadata: {
|
|
1727
|
+
title: `${userFullName} - ${title}`,
|
|
1728
|
+
description: `${userFullName} - ${description}`,
|
|
1729
|
+
},
|
|
1730
|
+
};
|
|
1731
|
+
return this.wishlistRepository.update(data);
|
|
1732
|
+
}
|
|
1733
|
+
delete(wishlistId) {
|
|
1734
|
+
return this.wishlistRepository.delete({ id: wishlistId });
|
|
1735
|
+
}
|
|
1736
|
+
getWishlistBySlug(slug) {
|
|
1737
|
+
return this.wishlistRepository.getWishlistBySlug(slug);
|
|
1738
|
+
}
|
|
1739
|
+
getWishlistsByPerson(personId) {
|
|
1740
|
+
return this.wishlistRepository.getWishlistByPerson(personId);
|
|
1741
|
+
}
|
|
1742
|
+
async addProduct(wishlistId, productId) {
|
|
1743
|
+
const wishlist = await this.wishlistRepository.get({ id: wishlistId });
|
|
1744
|
+
const hasProduct = wishlist.products.some((p) => p == productId);
|
|
1745
|
+
if (!hasProduct) {
|
|
1746
|
+
wishlist.products = [...wishlist.products, productId];
|
|
1747
|
+
return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
|
|
1748
|
+
}
|
|
1749
|
+
return wishlist;
|
|
1750
|
+
}
|
|
1751
|
+
async removeProduct(wishlistId, productId) {
|
|
1752
|
+
const wishlist = await this.wishlistRepository.get({ id: wishlistId });
|
|
1753
|
+
const productIndex = wishlist.products.findIndex((p) => p == productId);
|
|
1754
|
+
if (productIndex != -1) {
|
|
1755
|
+
wishlist.products.splice(productIndex, 1);
|
|
1756
|
+
if (!wishlist.products.length)
|
|
1757
|
+
return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
|
|
1758
|
+
return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
|
|
1759
|
+
}
|
|
1760
|
+
return wishlist;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: "invalid", target: i0.ɵɵFactoryTarget.Injectable });
|
|
1764
|
+
WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
|
|
1765
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
|
|
1766
|
+
type: Injectable
|
|
1767
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1768
|
+
type: Inject,
|
|
1769
|
+
args: ['WishlistRepository']
|
|
1770
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
1771
|
+
type: Inject,
|
|
1772
|
+
args: [DEFAULT_SHOP]
|
|
1773
|
+
}] }, { type: undefined, decorators: [{
|
|
1774
|
+
type: Inject,
|
|
1775
|
+
args: ['ProductRepository']
|
|
1776
|
+
}] }, { type: undefined, decorators: [{
|
|
1777
|
+
type: Inject,
|
|
1778
|
+
args: ['CategoryFilterRepository']
|
|
1779
|
+
}] }, { type: undefined, decorators: [{
|
|
1780
|
+
type: Inject,
|
|
1781
|
+
args: ['CategoryCollectionChildrenRepository']
|
|
1782
|
+
}] }, { type: undefined }, { type: undefined }, { type: undefined }, { type: UtilService }]; } });
|
|
1159
1783
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1784
|
+
class CheckoutSubscriptionService {
|
|
1785
|
+
constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
|
|
1786
|
+
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
1787
|
+
this.subscriptionRepository = subscriptionRepository;
|
|
1788
|
+
this.couponService = couponService;
|
|
1789
|
+
}
|
|
1790
|
+
getCheckoutSubscription(checkoutData) {
|
|
1791
|
+
const checkoutId = cookie.get('checkoutSubscriptionId');
|
|
1792
|
+
if (!isNil(checkoutId))
|
|
1793
|
+
return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
|
|
1794
|
+
return from(this.createCheckoutSubscription(checkoutData));
|
|
1795
|
+
}
|
|
1796
|
+
async createCheckoutSubscription(checkoutData) {
|
|
1797
|
+
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
1798
|
+
createdAt: new Date(),
|
|
1799
|
+
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
1800
|
+
});
|
|
1801
|
+
cookie.set('checkoutSubscriptionId', checkout.id);
|
|
1802
|
+
return checkout;
|
|
1803
|
+
}
|
|
1804
|
+
clearCheckoutSubscriptionFromSession() {
|
|
1805
|
+
cookie.remove('checkoutSubscriptionId');
|
|
1806
|
+
return of();
|
|
1807
|
+
}
|
|
1808
|
+
checkCoupon(nickname, userEmail) {
|
|
1809
|
+
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
1810
|
+
.checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
|
|
1811
|
+
.pipe()));
|
|
1812
|
+
}
|
|
1813
|
+
calcDiscountSubscription(coupon) {
|
|
1814
|
+
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1818
|
+
CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
|
|
1819
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
1820
|
+
type: Injectable
|
|
1821
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1822
|
+
type: Inject,
|
|
1823
|
+
args: ['CheckoutSubscriptionRepository']
|
|
1824
|
+
}] }, { type: undefined, decorators: [{
|
|
1825
|
+
type: Inject,
|
|
1826
|
+
args: ['SubscriptionRepository']
|
|
1827
|
+
}] }, { type: CouponService }]; } });
|
|
1828
|
+
|
|
1829
|
+
class HomeShopService {
|
|
1830
|
+
constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
|
|
1831
|
+
this.categoryRepository = categoryRepository;
|
|
1832
|
+
this.homeRepository = homeRepository;
|
|
1833
|
+
this.productRepository = productRepository;
|
|
1834
|
+
this.defaultShop = defaultShop;
|
|
1835
|
+
this.buildCategoryGroupWithRequiredData = (group) => ({
|
|
1836
|
+
category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
|
|
1837
|
+
products: group?.products?.map((product) => Product.toInstance(pick(product?.toPlain() || {}, [
|
|
1838
|
+
'id',
|
|
1839
|
+
'price',
|
|
1840
|
+
'reviews',
|
|
1841
|
+
'hasVariants',
|
|
1842
|
+
'slug',
|
|
1843
|
+
'sku',
|
|
1844
|
+
'stock',
|
|
1845
|
+
'costPrice',
|
|
1846
|
+
'images',
|
|
1847
|
+
'miniatures',
|
|
1848
|
+
'name',
|
|
1849
|
+
'weight',
|
|
1850
|
+
'rate',
|
|
1851
|
+
'type',
|
|
1852
|
+
]))) || [],
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
get homeId() {
|
|
1856
|
+
if (this.defaultShop === Shops.GLAMSHOP)
|
|
1857
|
+
return 'glamshop';
|
|
1858
|
+
if (this.defaultShop === Shops.MENSMARKET)
|
|
1859
|
+
return 'mens_market';
|
|
1860
|
+
return null;
|
|
1861
|
+
}
|
|
1862
|
+
getHomeData() {
|
|
1863
|
+
return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
|
|
1864
|
+
? of(home)
|
|
1865
|
+
: forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
|
|
1866
|
+
discoverProducts,
|
|
1867
|
+
featuredProducts,
|
|
1868
|
+
verticalProducts,
|
|
1869
|
+
})), concatMap((data) => this.saveHomeData(data)))));
|
|
1870
|
+
}
|
|
1871
|
+
getBanners(type) {
|
|
1872
|
+
return this.getHomeConfiguration().pipe(map((home) => {
|
|
1873
|
+
if (type === 'brand')
|
|
1874
|
+
return home.brandsCarousel;
|
|
1875
|
+
if (type === 'buyToWin')
|
|
1876
|
+
return [home.buyToWinBanner];
|
|
1877
|
+
if (type === 'block')
|
|
1878
|
+
return home.blockBanners;
|
|
1879
|
+
if (type === 'blog')
|
|
1880
|
+
return [home.blogBanner];
|
|
1881
|
+
return [];
|
|
1882
|
+
}));
|
|
1883
|
+
}
|
|
1884
|
+
getMinValueForFreeShipping() {
|
|
1885
|
+
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
1886
|
+
}
|
|
1887
|
+
getDiscoverProducts() {
|
|
1888
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
1889
|
+
}
|
|
1890
|
+
getFeaturedProducts() {
|
|
1891
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
1892
|
+
}
|
|
1893
|
+
getVerticalProducts() {
|
|
1894
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => forkJoin(home.verticalCarousels.filter(Boolean).map((id) => from(this.categoryRepository.get({ id })).pipe(concatMap((category) => from(this.productRepository.find({
|
|
1895
|
+
filters: { categories: { operator: Where.IN, value: [category.id] } },
|
|
1896
|
+
limits: { limit: 12 },
|
|
1897
|
+
})).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
|
|
1898
|
+
}
|
|
1899
|
+
getHomeConfiguration() {
|
|
1900
|
+
return of(this.homeConfiguration).pipe(concatMap((home) => home
|
|
1901
|
+
? of(home)
|
|
1902
|
+
: !this.homeId
|
|
1903
|
+
? throwError(new RequiredArgumentError(['homeId']))
|
|
1904
|
+
: from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
|
|
1905
|
+
}
|
|
1906
|
+
saveHomeData(homeData) {
|
|
1907
|
+
const data = {
|
|
1908
|
+
createdAt: new Date(),
|
|
1909
|
+
expiresAt: add(new Date(), { hours: 1 }),
|
|
1910
|
+
data: homeData,
|
|
1166
1911
|
};
|
|
1912
|
+
return from(this.homeRepository.update({
|
|
1913
|
+
id: this.homeId,
|
|
1914
|
+
data,
|
|
1915
|
+
})).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
|
|
1167
1916
|
}
|
|
1168
1917
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
{
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
return
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
{
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
}]
|
|
1295
|
-
}] });
|
|
1918
|
+
HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1919
|
+
HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
|
|
1920
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
|
|
1921
|
+
type: Injectable
|
|
1922
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1923
|
+
type: Inject,
|
|
1924
|
+
args: ['CategoryRepository']
|
|
1925
|
+
}] }, { type: undefined, decorators: [{
|
|
1926
|
+
type: Inject,
|
|
1927
|
+
args: ['HomeRepository']
|
|
1928
|
+
}] }, { type: undefined, decorators: [{
|
|
1929
|
+
type: Inject,
|
|
1930
|
+
args: ['ProductRepository']
|
|
1931
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
1932
|
+
type: Inject,
|
|
1933
|
+
args: [DEFAULT_SHOP]
|
|
1934
|
+
}] }]; } });
|
|
1935
|
+
|
|
1936
|
+
class OrderService {
|
|
1937
|
+
constructor(angularFirestore, orderRepository) {
|
|
1938
|
+
this.angularFirestore = angularFirestore;
|
|
1939
|
+
this.orderRepository = orderRepository;
|
|
1940
|
+
this.orderSubject = new Subject();
|
|
1941
|
+
}
|
|
1942
|
+
getOrder(id) {
|
|
1943
|
+
docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
|
|
1944
|
+
.pipe(map((doc) => Order.toInstance(doc.data())))
|
|
1945
|
+
.subscribe((doc) => this.orderSubject.next(doc));
|
|
1946
|
+
return this.orderSubject;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, deps: [{ token: i1$2.Firestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1950
|
+
OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
|
|
1951
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
1952
|
+
type: Injectable
|
|
1953
|
+
}], ctorParameters: function () { return [{ type: i1$2.Firestore }, { type: i1$3.OrderFirestoreRepository, decorators: [{
|
|
1954
|
+
type: Inject,
|
|
1955
|
+
args: ['OrderRepository']
|
|
1956
|
+
}] }]; } });
|
|
1957
|
+
|
|
1958
|
+
class ShippingService {
|
|
1959
|
+
constructor(http, apiUrl, homeService) {
|
|
1960
|
+
this.http = http;
|
|
1961
|
+
this.apiUrl = apiUrl;
|
|
1962
|
+
this.homeService = homeService;
|
|
1963
|
+
}
|
|
1964
|
+
getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
|
|
1965
|
+
return combineLatest([
|
|
1966
|
+
this.homeService.getHomeData(),
|
|
1967
|
+
this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
|
|
1968
|
+
]).pipe(map(([datas, shippingMethodsResponse]) => {
|
|
1969
|
+
let shippingMethods = shippingMethodsResponse.result;
|
|
1970
|
+
if (!shippingMethods.length)
|
|
1971
|
+
return [];
|
|
1972
|
+
shippingMethods = shippingMethods.map((shippingMethod) => {
|
|
1973
|
+
if (shippingMethod.ShippingCompanyName == 'Same Day EG')
|
|
1974
|
+
shippingMethod.ShippingCompanyName = 'Same Day';
|
|
1975
|
+
return shippingMethod;
|
|
1976
|
+
});
|
|
1977
|
+
const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
|
|
1978
|
+
if (this.isHolidays(datasSameDayNotAvaliable)) {
|
|
1979
|
+
shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
|
|
1980
|
+
}
|
|
1981
|
+
if (totalPrice >= 200) {
|
|
1982
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
1983
|
+
if (s.serviceName !== 'Same Day')
|
|
1984
|
+
return { ...s, totalPrice: 0 };
|
|
1985
|
+
else
|
|
1986
|
+
return s;
|
|
1987
|
+
});
|
|
1988
|
+
}
|
|
1989
|
+
if (shop == Shops.GLAMSHOP)
|
|
1990
|
+
return shippingMethods;
|
|
1991
|
+
if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
|
|
1992
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
1993
|
+
if (s.serviceName == 'Same Day')
|
|
1994
|
+
return { ...s, totalPrice: s.totalPrice / 2 };
|
|
1995
|
+
else
|
|
1996
|
+
return { ...s, totalPrice: 0 };
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
|
|
2000
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
2001
|
+
return { ...s, totalPrice: s.totalPrice / 2 };
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
return shippingMethods;
|
|
2005
|
+
}));
|
|
2006
|
+
}
|
|
2007
|
+
isFreeShippingBySubscription(shop, subscriptionPlan) {
|
|
2008
|
+
if (!subscriptionPlan)
|
|
2009
|
+
return false;
|
|
2010
|
+
if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
|
|
2011
|
+
return true;
|
|
2012
|
+
return false;
|
|
2013
|
+
}
|
|
2014
|
+
isHalfShippingBySubscription(shop, subscriptionPlan) {
|
|
2015
|
+
if (!subscriptionPlan)
|
|
2016
|
+
return false;
|
|
2017
|
+
if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
|
|
2018
|
+
return true;
|
|
2019
|
+
}
|
|
2020
|
+
return false;
|
|
2021
|
+
}
|
|
2022
|
+
isHolidays(datas) {
|
|
2023
|
+
const today = new Date();
|
|
2024
|
+
for (const key in datas) {
|
|
2025
|
+
let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
|
|
2026
|
+
let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
|
|
2027
|
+
if (start > end)
|
|
2028
|
+
end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
|
|
2029
|
+
if (today >= start && today <= end)
|
|
2030
|
+
return true;
|
|
2031
|
+
}
|
|
2032
|
+
return false;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i1$4.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2036
|
+
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
|
|
2037
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
|
|
2038
|
+
type: Injectable
|
|
2039
|
+
}], ctorParameters: function () { return [{ type: i1$4.HttpClient }, { type: undefined, decorators: [{
|
|
2040
|
+
type: Inject,
|
|
2041
|
+
args: [BACKEND_URL]
|
|
2042
|
+
}] }, { type: HomeShopService }]; } });
|
|
1296
2043
|
|
|
1297
2044
|
class AngularConnectModule {
|
|
1298
2045
|
static initializeApp(defaultShop, options, nameOrConfig) {
|
|
1299
2046
|
return {
|
|
1300
2047
|
ngModule: AngularConnectModule,
|
|
1301
2048
|
providers: [
|
|
2049
|
+
{
|
|
2050
|
+
provide: CATEGORY_STRUCTURE,
|
|
2051
|
+
useClass: isNil(options?.oldCategoryStructure) || options?.oldCategoryStructure
|
|
2052
|
+
? OldCategoryStructureAdapter
|
|
2053
|
+
: NewCategoryStructureAdapter,
|
|
2054
|
+
},
|
|
1302
2055
|
...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
|
|
1303
2056
|
...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
|
|
1304
2057
|
...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
|
|
1305
2058
|
...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
|
|
1306
2059
|
...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
|
|
2060
|
+
...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
|
|
1307
2061
|
],
|
|
1308
2062
|
};
|
|
1309
2063
|
}
|
|
@@ -1313,11 +2067,15 @@ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", ve
|
|
|
1313
2067
|
AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, providers: [
|
|
1314
2068
|
AuthService,
|
|
1315
2069
|
CartService,
|
|
2070
|
+
CatalogService,
|
|
2071
|
+
CategoryService,
|
|
1316
2072
|
CheckoutService,
|
|
1317
2073
|
CheckoutSubscriptionService,
|
|
1318
2074
|
CouponService,
|
|
1319
2075
|
HomeShopService,
|
|
1320
2076
|
OrderService,
|
|
2077
|
+
ShippingService,
|
|
2078
|
+
WishlistService,
|
|
1321
2079
|
], imports: [AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
|
|
1322
2080
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, decorators: [{
|
|
1323
2081
|
type: NgModule,
|
|
@@ -1326,11 +2084,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1326
2084
|
providers: [
|
|
1327
2085
|
AuthService,
|
|
1328
2086
|
CartService,
|
|
2087
|
+
CatalogService,
|
|
2088
|
+
CategoryService,
|
|
1329
2089
|
CheckoutService,
|
|
1330
2090
|
CheckoutSubscriptionService,
|
|
1331
2091
|
CouponService,
|
|
1332
2092
|
HomeShopService,
|
|
1333
2093
|
OrderService,
|
|
2094
|
+
ShippingService,
|
|
2095
|
+
WishlistService,
|
|
1334
2096
|
],
|
|
1335
2097
|
}]
|
|
1336
2098
|
}] });
|
|
@@ -1339,5 +2101,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1339
2101
|
* Generated bundle index. Do not edit.
|
|
1340
2102
|
*/
|
|
1341
2103
|
|
|
1342
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService };
|
|
2104
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ProductSorts, ShippingService, UtilService, WishlistService };
|
|
1343
2105
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|