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