@infrab4a/connect-angular 4.1.3-beta.1 → 4.1.3

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