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