@infrab4a/connect-angular 4.0.0-beta.39 → 4.0.0-beta.40

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