@infrab4a/connect-angular 4.0.0-beta.43 → 4.0.0-beta.44

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