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