@infrab4a/connect-angular 4.1.5-beta.1 → 4.1.5-beta.2

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 +166 -163
  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 +2173 -2173
  61. package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
  62. package/fesm2020/infrab4a-connect-angular.mjs +2105 -2102
  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 +83 -83
  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,2126 +54,2129 @@ 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.productsByTerm = {};
1440
- this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1441
- const filters = {};
1442
- if (clubDiscount?.length)
1443
- set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1444
- if (brands?.length)
1445
- filters.brand = { operator: Where.IN, value: brands };
1446
- if (gender?.length)
1447
- filters.gender = { operator: Where.IN, value: gender };
1448
- if (prices?.min || prices?.max)
1449
- set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1450
- ...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
1451
- ...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
1452
- ]);
1453
- if (rate)
1454
- filters.rate = { operator: Where.GTE, value: rate };
1455
- if (tags?.length)
1456
- filters.tags = { operator: Where.LIKE, value: tags };
1457
- if (customOptions?.length)
1458
- filters.filters = { operator: Where.LIKE, value: customOptions };
1459
- return filters;
1460
- };
1461
- this.buildSortQuery = (sort) => {
1462
- if (!sort || sort === 'most-relevant')
1463
- return {};
1464
- if (sort === 'best-sellers')
1465
- return { shoppingCount: 'desc' };
1466
- if (sort === 'biggest-price')
1467
- return { subscriberPrice: 'desc' };
1468
- if (sort === 'lowest-price')
1469
- return { subscriberPrice: 'asc' };
1470
- if (sort === 'best-rating')
1471
- return { rate: 'desc' };
1472
- if (sort === 'news')
1473
- return { createdAt: 'desc' };
1474
- if (sort === 'biggest-discount')
1475
- return { subscriberDiscountPercentage: 'desc' };
1476
- };
1477
- this.buildLimitQuery = (options) => {
1478
- const limit = options?.perPage || 20;
1479
- return {
1480
- limit,
1481
- offset: ((options?.page || 1) - 1) * limit,
1482
- };
1483
- };
1484
- this.hasProfile = (options) => 'profile' in options;
1485
- this.hasTerm = (options) => 'term' in options;
1486
- this.hasCategory = (options) => 'category' in options;
1487
- }
1488
- async fetchProducts(options) {
1489
- const limits = this.buildLimitQuery(options);
1490
- if (this.hasProfile(options) && options.filters?.customOptions)
1491
- throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
1492
- if (this.hasProfile(options) && options.filters?.tags)
1493
- throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1494
- if (this.hasTerm(options) && options.filters?.customOptions)
1495
- throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1496
- return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
1497
- products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1498
- pages: Math.ceil(total / limits.limit),
1499
- prices: {
1500
- price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1501
- subscriberPrice: {
1502
- min: +minimal?.price?.subscriberPrice?.toFixed(2),
1503
- max: +maximum?.price?.subscriberPrice?.toFixed(2),
1504
- },
1505
- },
1506
- brands: distinct?.brand,
1507
- }));
1508
- }
1509
- async findCatalog(options, limits) {
1510
- if (this.hasTerm(options) && options.sort === 'most-relevant')
1511
- return this.findCatalogByTermAndSortByMostRevelant(options, limits);
1512
- const repoParams = {
1513
- filters: {
1514
- ...(await this.buildMainFilter(options)),
1515
- ...this.buildFilterQuery(options?.filters || {}),
1516
- },
1517
- ...(options?.sort ? { orderBy: this.buildSortQuery(options?.sort) } : {}),
1518
- limits,
1519
- options: {
1520
- minimal: ['price'],
1521
- maximum: ['price'],
1522
- ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1523
- },
1524
- };
1525
- if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1526
- return this.productRepository.findCatalog(repoParams);
1527
- return this.productRepository.findCatalog(repoParams, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1528
- }
1529
- async buildMainFilter({ category, profile, term, }) {
1530
- if (category)
1531
- return this.categoryStructureAdapter.buildProductFilterByCategory(category);
1532
- if (profile)
1533
- return { tags: { operator: Where.LIKE, value: profile } };
1534
- if (term)
1535
- return this.productIndex
1536
- .search(term, 999, this.shop)
1537
- .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1538
- }
1539
- async findCatalogByTermAndSortByMostRevelant(options, limits) {
1540
- const productIds = await this.findCatalogIdsByElasticSearch(options.term);
1541
- const limitedProductId = productIds.slice(limits.offset, limits.offset + limits.limit);
1542
- const productResult = await this.productRepository.findCatalog({
1543
- filters: { id: { operator: Where.IN, value: limitedProductId } },
1544
- }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1545
- const totalResult = await this.productRepository.findCatalog({
1546
- fields: ['id'],
1547
- filters: { id: { operator: Where.IN, value: productIds } },
1548
- limits: { limit: 1, offset: 0 },
1549
- options: {
1550
- minimal: ['price'],
1551
- maximum: ['price'],
1552
- distinct: ['brand'],
1553
- },
1554
- }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1555
- return {
1556
- data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1557
- count: totalResult.count,
1558
- maximum: totalResult.maximum,
1559
- minimal: totalResult.minimal,
1560
- distinct: totalResult.distinct,
1561
- };
1562
- }
1563
- async findCatalogIdsByElasticSearch(term) {
1564
- if (this.productsByTerm[term])
1565
- return this.productsByTerm[term];
1566
- return (this.productsByTerm[term] = await this.productIndex
1567
- .search(term, 999, this.shop)
1568
- .then(({ hits: products }) => {
1569
- const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
1570
- const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
1571
- const sorted = [...withStock, ...withOutStock];
1572
- return [...new Set(sorted.map(({ _source }) => _source.id))];
1573
- }));
1574
- }
1575
- }
1576
- 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 });
1577
- CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1578
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1579
- type: Injectable
1580
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1581
- type: Inject,
1582
- args: ['ProductRepository']
1583
- }] }, { type: undefined, decorators: [{
1584
- type: Inject,
1585
- args: [CATEGORY_STRUCTURE]
1586
- }] }, { type: i1$2.Shops, decorators: [{
1587
- type: Inject,
1588
- 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.productsByTerm = {};
1440
+ this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1441
+ const filters = {};
1442
+ if (clubDiscount?.length)
1443
+ set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1444
+ if (brands?.length)
1445
+ filters.brand = { operator: Where.IN, value: brands };
1446
+ if (gender?.length)
1447
+ filters.gender = { operator: Where.IN, value: gender };
1448
+ if (prices?.min || prices?.max)
1449
+ set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1450
+ ...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
1451
+ ...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
1452
+ ]);
1453
+ if (rate)
1454
+ filters.rate = { operator: Where.GTE, value: rate };
1455
+ if (tags?.length)
1456
+ filters.tags = { operator: Where.LIKE, value: tags };
1457
+ if (customOptions?.length)
1458
+ filters.filters = { operator: Where.LIKE, value: customOptions };
1459
+ return filters;
1460
+ };
1461
+ this.buildSortQuery = (sort) => {
1462
+ if (!sort || sort === 'most-relevant')
1463
+ return {};
1464
+ if (sort === 'best-sellers')
1465
+ return { shoppingCount: 'desc' };
1466
+ if (sort === 'biggest-price')
1467
+ return { subscriberPrice: 'desc' };
1468
+ if (sort === 'lowest-price')
1469
+ return { subscriberPrice: 'asc' };
1470
+ if (sort === 'best-rating')
1471
+ return { rate: 'desc' };
1472
+ if (sort === 'news')
1473
+ return { createdAt: 'desc' };
1474
+ if (sort === 'biggest-discount')
1475
+ return { subscriberDiscountPercentage: 'desc' };
1476
+ };
1477
+ this.buildLimitQuery = (options) => {
1478
+ const limit = options?.perPage || 20;
1479
+ return {
1480
+ limit,
1481
+ offset: ((options?.page || 1) - 1) * limit,
1482
+ };
1483
+ };
1484
+ this.hasProfile = (options) => 'profile' in options;
1485
+ this.hasTerm = (options) => 'term' in options;
1486
+ this.hasCategory = (options) => 'category' in options;
1487
+ }
1488
+ async fetchProducts(options) {
1489
+ const limits = this.buildLimitQuery(options);
1490
+ if (this.hasProfile(options) && options.filters?.customOptions)
1491
+ throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
1492
+ if (this.hasProfile(options) && options.filters?.tags)
1493
+ throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1494
+ if (this.hasTerm(options) && options.filters?.customOptions)
1495
+ throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1496
+ return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
1497
+ products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1498
+ pages: Math.ceil(total / limits.limit),
1499
+ prices: {
1500
+ price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1501
+ subscriberPrice: {
1502
+ min: +minimal?.price?.subscriberPrice?.toFixed(2),
1503
+ max: +maximum?.price?.subscriberPrice?.toFixed(2),
1504
+ },
1505
+ },
1506
+ brands: distinct?.brand,
1507
+ }));
1508
+ }
1509
+ async findCatalog(options, limits) {
1510
+ if (this.hasTerm(options) && options.sort === 'most-relevant')
1511
+ return this.findCatalogByTermAndSortByMostRevelant(options, limits);
1512
+ const repoParams = {
1513
+ filters: {
1514
+ ...(await this.buildMainFilter(options)),
1515
+ ...this.buildFilterQuery(options?.filters || {}),
1516
+ },
1517
+ ...(options?.sort ? { orderBy: this.buildSortQuery(options?.sort) } : {}),
1518
+ limits,
1519
+ options: {
1520
+ minimal: ['price'],
1521
+ maximum: ['price'],
1522
+ ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1523
+ },
1524
+ };
1525
+ if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1526
+ return this.productRepository.findCatalog(repoParams);
1527
+ return this.productRepository.findCatalog(repoParams, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1528
+ }
1529
+ async buildMainFilter({ category, profile, term, }) {
1530
+ if (category)
1531
+ return this.categoryStructureAdapter.buildProductFilterByCategory(category);
1532
+ if (profile)
1533
+ return { tags: { operator: Where.LIKE, value: profile } };
1534
+ if (term)
1535
+ return this.productIndex
1536
+ .search(term, 999, this.shop)
1537
+ .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1538
+ }
1539
+ async findCatalogByTermAndSortByMostRevelant(options, limits) {
1540
+ const productIds = await this.findCatalogIdsByElasticSearch(options.term);
1541
+ const limitedProductId = productIds.slice(limits.offset, limits.offset + limits.limit);
1542
+ const productResult = await this.productRepository.findCatalog({
1543
+ filters: {
1544
+ id: { operator: Where.IN, value: limitedProductId },
1545
+ ...this.buildFilterQuery(options?.filters || {}),
1546
+ },
1547
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1548
+ const totalResult = await this.productRepository.findCatalog({
1549
+ fields: ['id'],
1550
+ filters: { id: { operator: Where.IN, value: productIds } },
1551
+ limits: { limit: 1, offset: 0 },
1552
+ options: {
1553
+ minimal: ['price'],
1554
+ maximum: ['price'],
1555
+ distinct: ['brand'],
1556
+ },
1557
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1558
+ return {
1559
+ data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1560
+ count: totalResult.count,
1561
+ maximum: totalResult.maximum,
1562
+ minimal: totalResult.minimal,
1563
+ distinct: totalResult.distinct,
1564
+ };
1565
+ }
1566
+ async findCatalogIdsByElasticSearch(term) {
1567
+ if (this.productsByTerm[term])
1568
+ return this.productsByTerm[term];
1569
+ return (this.productsByTerm[term] = await this.productIndex
1570
+ .search(term, 999, this.shop)
1571
+ .then(({ hits: products }) => {
1572
+ const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
1573
+ const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
1574
+ const sorted = [...withStock, ...withOutStock];
1575
+ return [...new Set(sorted.map(({ _source }) => _source.id))];
1576
+ }));
1577
+ }
1578
+ }
1579
+ 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 });
1580
+ CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1581
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1582
+ type: Injectable
1583
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1584
+ type: Inject,
1585
+ args: ['ProductRepository']
1586
+ }] }, { type: undefined, decorators: [{
1587
+ type: Inject,
1588
+ args: [CATEGORY_STRUCTURE]
1589
+ }] }, { type: i1$2.Shops, decorators: [{
1590
+ type: Inject,
1591
+ args: [DEFAULT_SHOP]
1589
1592
  }] }, { type: i1$2.ProductsIndex }]; } });
1590
1593
 
1591
- class CategoryService {
1592
- constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1593
- this.productRepository = productRepository;
1594
- this.categoryRepository = categoryRepository;
1595
- this.categoryFilterRepository = categoryFilterRepository;
1596
- this.categoryStructureAdapter = categoryStructureAdapter;
1597
- this.shop = shop;
1598
- }
1599
- async fetchBrands(category, mainGender) {
1600
- const brands = await this.productRepository
1601
- .findCatalog({
1602
- filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1603
- fields: ['brand'],
1604
- }, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1605
- .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1606
- return this.categoryRepository
1607
- .find({ filters: { brandCategory: true, shop: this.shop }, orderBy: { name: 'asc' } })
1608
- .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1609
- }
1610
- async fetchFilterOptions(category) {
1611
- return await this.categoryFilterRepository
1612
- .find({ filters: { categoryId: +category.id } })
1613
- .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1614
- }
1615
- }
1616
- 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 });
1617
- CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1618
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1619
- type: Injectable
1620
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1621
- type: Inject,
1622
- args: ['ProductRepository']
1623
- }] }, { type: undefined, decorators: [{
1624
- type: Inject,
1625
- args: ['CategoryRepository']
1626
- }] }, { type: undefined, decorators: [{
1627
- type: Inject,
1628
- args: ['CategoryFilterRepository']
1629
- }] }, { type: undefined, decorators: [{
1630
- type: Inject,
1631
- args: [CATEGORY_STRUCTURE]
1632
- }] }, { type: i1$2.Shops, decorators: [{
1633
- type: Inject,
1634
- args: [DEFAULT_SHOP]
1594
+ class CategoryService {
1595
+ constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1596
+ this.productRepository = productRepository;
1597
+ this.categoryRepository = categoryRepository;
1598
+ this.categoryFilterRepository = categoryFilterRepository;
1599
+ this.categoryStructureAdapter = categoryStructureAdapter;
1600
+ this.shop = shop;
1601
+ }
1602
+ async fetchBrands(category, mainGender) {
1603
+ const brands = await this.productRepository
1604
+ .findCatalog({
1605
+ filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1606
+ fields: ['brand'],
1607
+ }, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1608
+ .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1609
+ return this.categoryRepository
1610
+ .find({ filters: { brandCategory: true, shop: this.shop }, orderBy: { name: 'asc' } })
1611
+ .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1612
+ }
1613
+ async fetchFilterOptions(category) {
1614
+ return await this.categoryFilterRepository
1615
+ .find({ filters: { categoryId: +category.id } })
1616
+ .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1617
+ }
1618
+ }
1619
+ 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 });
1620
+ CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1621
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1622
+ type: Injectable
1623
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1624
+ type: Inject,
1625
+ args: ['ProductRepository']
1626
+ }] }, { type: undefined, decorators: [{
1627
+ type: Inject,
1628
+ args: ['CategoryRepository']
1629
+ }] }, { type: undefined, decorators: [{
1630
+ type: Inject,
1631
+ args: ['CategoryFilterRepository']
1632
+ }] }, { type: undefined, decorators: [{
1633
+ type: Inject,
1634
+ args: [CATEGORY_STRUCTURE]
1635
+ }] }, { type: i1$2.Shops, decorators: [{
1636
+ type: Inject,
1637
+ args: [DEFAULT_SHOP]
1635
1638
  }] }]; } });
1636
1639
 
1637
- var ProductSorts;
1638
- (function (ProductSorts) {
1639
- ProductSorts["MOST_RELEVANT"] = "most-relevant";
1640
- ProductSorts["BEST_SELLER"] = "best-sellers";
1641
- ProductSorts["BIGGEST_PRICE"] = "biggest-price";
1642
- ProductSorts["LOWEST_PRICE"] = "lowest-price";
1643
- ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1644
- ProductSorts["BEST_RATING"] = "best-rating";
1645
- ProductSorts["NEWS"] = "news";
1640
+ var ProductSorts;
1641
+ (function (ProductSorts) {
1642
+ ProductSorts["MOST_RELEVANT"] = "most-relevant";
1643
+ ProductSorts["BEST_SELLER"] = "best-sellers";
1644
+ ProductSorts["BIGGEST_PRICE"] = "biggest-price";
1645
+ ProductSorts["LOWEST_PRICE"] = "lowest-price";
1646
+ ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1647
+ ProductSorts["BEST_RATING"] = "best-rating";
1648
+ ProductSorts["NEWS"] = "news";
1646
1649
  })(ProductSorts || (ProductSorts = {}));
1647
1650
 
1648
- class CategoryWithTree extends Category {
1649
- }
1650
- __decorate([
1651
- Type(() => CategoryWithTree),
1652
- __metadata("design:type", Array)
1651
+ class CategoryWithTree extends Category {
1652
+ }
1653
+ __decorate([
1654
+ Type(() => CategoryWithTree),
1655
+ __metadata("design:type", Array)
1653
1656
  ], CategoryWithTree.prototype, "children", void 0);
1654
1657
 
1655
- class NewCategoryStructureAdapter {
1656
- constructor(categoryRepository) {
1657
- this.categoryRepository = categoryRepository;
1658
- }
1659
- async buildProductFilterByCategory(category) {
1660
- const loadedCategory = await this.getCategory(category);
1661
- if (loadedCategory.isCollection)
1662
- return { id: { operator: Where.IN, value: loadedCategory.products } };
1663
- const categoryIds = [...(await this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1664
- return {
1665
- category: {
1666
- id: {
1667
- operator: Where.IN,
1668
- value: categoryIds,
1669
- },
1670
- },
1671
- };
1672
- }
1673
- async getAllCategoriesIdFromCategory(category) {
1674
- return this.categoryRepository
1675
- .getChildren(+category.id)
1676
- .then((categories) => categories.map((category) => category.id.toString()));
1677
- }
1678
- async getCategory(category) {
1679
- return isNil(category.isCollection) || (category.isCollection && !category.products?.length)
1680
- ? this.categoryRepository.get({ id: category.id })
1681
- : category;
1682
- }
1683
- }
1684
- NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1685
- NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
1686
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1687
- type: Injectable
1688
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1689
- type: Inject,
1690
- args: ['CategoryRepository']
1658
+ class NewCategoryStructureAdapter {
1659
+ constructor(categoryRepository) {
1660
+ this.categoryRepository = categoryRepository;
1661
+ }
1662
+ async buildProductFilterByCategory(category) {
1663
+ const loadedCategory = await this.getCategory(category);
1664
+ if (loadedCategory.isCollection)
1665
+ return { id: { operator: Where.IN, value: loadedCategory.products } };
1666
+ const categoryIds = [...(await this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1667
+ return {
1668
+ category: {
1669
+ id: {
1670
+ operator: Where.IN,
1671
+ value: categoryIds,
1672
+ },
1673
+ },
1674
+ };
1675
+ }
1676
+ async getAllCategoriesIdFromCategory(category) {
1677
+ return this.categoryRepository
1678
+ .getChildren(+category.id)
1679
+ .then((categories) => categories.map((category) => category.id.toString()));
1680
+ }
1681
+ async getCategory(category) {
1682
+ return isNil(category.isCollection) || (category.isCollection && !category.products?.length)
1683
+ ? this.categoryRepository.get({ id: category.id })
1684
+ : category;
1685
+ }
1686
+ }
1687
+ NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1688
+ NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
1689
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1690
+ type: Injectable
1691
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1692
+ type: Inject,
1693
+ args: ['CategoryRepository']
1691
1694
  }] }]; } });
1692
1695
 
1693
- class OldCategoryStructureAdapter {
1694
- constructor(categoryRepository) {
1695
- this.categoryRepository = categoryRepository;
1696
- }
1697
- async buildProductFilterByCategory(category) {
1698
- const productsIds = category.products?.length
1699
- ? category.products
1700
- : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1701
- return { id: { operator: Where.IN, value: productsIds } };
1702
- }
1703
- }
1704
- OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1705
- OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
1706
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1707
- type: Injectable
1708
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1709
- type: Inject,
1710
- args: ['CategoryRepository']
1696
+ class OldCategoryStructureAdapter {
1697
+ constructor(categoryRepository) {
1698
+ this.categoryRepository = categoryRepository;
1699
+ }
1700
+ async buildProductFilterByCategory(category) {
1701
+ const productsIds = category.products?.length
1702
+ ? category.products
1703
+ : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1704
+ return { id: { operator: Where.IN, value: productsIds } };
1705
+ }
1706
+ }
1707
+ OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1708
+ OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
1709
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1710
+ type: Injectable
1711
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1712
+ type: Inject,
1713
+ args: ['CategoryRepository']
1711
1714
  }] }]; } });
1712
1715
 
1713
- class WishlistService {
1714
- constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, productIndex) {
1715
- this.wishlistRepository = wishlistRepository;
1716
- this.shop = shop;
1717
- const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1718
- this.catalogService = new CatalogService(productRepository, categoryStructureAdapter, shop, productIndex);
1719
- this.categoryService = new CategoryService(productRepository, wishlistRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1720
- }
1721
- getCatalogService() {
1722
- return this.catalogService;
1723
- }
1724
- getCategoryService() {
1725
- return this.categoryService;
1726
- }
1727
- async create(personId, title, description, userFullName, userPhoto) {
1728
- const data = {
1729
- slug: '',
1730
- name: title,
1731
- description,
1732
- metadata: {
1733
- title: `${userFullName} - ${title}`,
1734
- description: `${userFullName} - ${description}`,
1735
- },
1736
- shop: this.shop,
1737
- shops: [this.shop],
1738
- personId,
1739
- personName: userFullName,
1740
- personPhoto: userPhoto,
1741
- brandCategory: false,
1742
- published: true,
1743
- };
1744
- const newWishlist = await this.wishlistRepository.create(data);
1745
- return this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
1746
- }
1747
- update(id, title, description, userFullName, userPhoto) {
1748
- const data = {
1749
- id,
1750
- name: title,
1751
- description,
1752
- metadata: {
1753
- title: `${userFullName} - ${title}`,
1754
- description: `${userFullName} - ${description}`,
1755
- },
1756
- personName: userFullName,
1757
- personPhoto: userPhoto,
1758
- };
1759
- return this.wishlistRepository.update(data);
1760
- }
1761
- delete(wishlistId) {
1762
- return this.wishlistRepository.delete({ id: wishlistId });
1763
- }
1764
- getWishlistBySlug(slug) {
1765
- const [id] = slug.split('-');
1766
- if (+id)
1767
- return this.wishlistRepository.get({ id });
1768
- return this.wishlistRepository.getWishlistBySlug(slug);
1769
- }
1770
- getWishlistsByPerson(personId) {
1771
- return this.wishlistRepository.getWishlistByPerson(personId);
1772
- }
1773
- async addProduct(wishlistId, productId) {
1774
- const wishlist = await this.wishlistRepository.get({ id: wishlistId });
1775
- const hasProduct = wishlist.products.some((p) => p == productId);
1776
- if (!hasProduct) {
1777
- wishlist.products = [...wishlist.products, productId];
1778
- return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
1779
- }
1780
- return wishlist;
1781
- }
1782
- async removeProduct(wishlistId, productId) {
1783
- const wishlist = await this.wishlistRepository.get({ id: wishlistId });
1784
- const productIndex = wishlist.products.findIndex((p) => p == productId);
1785
- if (productIndex != -1) {
1786
- wishlist.products.splice(productIndex, 1);
1787
- if (!wishlist.products.length)
1788
- return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
1789
- return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
1790
- }
1791
- return wishlist;
1792
- }
1793
- }
1794
- 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 });
1795
- WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
1796
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
1797
- type: Injectable
1798
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1799
- type: Inject,
1800
- args: ['WishlistRepository']
1801
- }] }, { type: i1$2.Shops, decorators: [{
1802
- type: Inject,
1803
- args: [DEFAULT_SHOP]
1804
- }] }, { type: undefined, decorators: [{
1805
- type: Inject,
1806
- args: ['ProductRepository']
1807
- }] }, { type: undefined, decorators: [{
1808
- type: Inject,
1809
- args: ['CategoryFilterRepository']
1716
+ class WishlistService {
1717
+ constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, productIndex) {
1718
+ this.wishlistRepository = wishlistRepository;
1719
+ this.shop = shop;
1720
+ const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1721
+ this.catalogService = new CatalogService(productRepository, categoryStructureAdapter, shop, productIndex);
1722
+ this.categoryService = new CategoryService(productRepository, wishlistRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1723
+ }
1724
+ getCatalogService() {
1725
+ return this.catalogService;
1726
+ }
1727
+ getCategoryService() {
1728
+ return this.categoryService;
1729
+ }
1730
+ async create(personId, title, description, userFullName, userPhoto) {
1731
+ const data = {
1732
+ slug: '',
1733
+ name: title,
1734
+ description,
1735
+ metadata: {
1736
+ title: `${userFullName} - ${title}`,
1737
+ description: `${userFullName} - ${description}`,
1738
+ },
1739
+ shop: this.shop,
1740
+ shops: [this.shop],
1741
+ personId,
1742
+ personName: userFullName,
1743
+ personPhoto: userPhoto,
1744
+ brandCategory: false,
1745
+ published: true,
1746
+ };
1747
+ const newWishlist = await this.wishlistRepository.create(data);
1748
+ return this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
1749
+ }
1750
+ update(id, title, description, userFullName, userPhoto) {
1751
+ const data = {
1752
+ id,
1753
+ name: title,
1754
+ description,
1755
+ metadata: {
1756
+ title: `${userFullName} - ${title}`,
1757
+ description: `${userFullName} - ${description}`,
1758
+ },
1759
+ personName: userFullName,
1760
+ personPhoto: userPhoto,
1761
+ };
1762
+ return this.wishlistRepository.update(data);
1763
+ }
1764
+ delete(wishlistId) {
1765
+ return this.wishlistRepository.delete({ id: wishlistId });
1766
+ }
1767
+ getWishlistBySlug(slug) {
1768
+ const [id] = slug.split('-');
1769
+ if (+id)
1770
+ return this.wishlistRepository.get({ id });
1771
+ return this.wishlistRepository.getWishlistBySlug(slug);
1772
+ }
1773
+ getWishlistsByPerson(personId) {
1774
+ return this.wishlistRepository.getWishlistByPerson(personId);
1775
+ }
1776
+ async addProduct(wishlistId, productId) {
1777
+ const wishlist = await this.wishlistRepository.get({ id: wishlistId });
1778
+ const hasProduct = wishlist.products.some((p) => p == productId);
1779
+ if (!hasProduct) {
1780
+ wishlist.products = [...wishlist.products, productId];
1781
+ return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
1782
+ }
1783
+ return wishlist;
1784
+ }
1785
+ async removeProduct(wishlistId, productId) {
1786
+ const wishlist = await this.wishlistRepository.get({ id: wishlistId });
1787
+ const productIndex = wishlist.products.findIndex((p) => p == productId);
1788
+ if (productIndex != -1) {
1789
+ wishlist.products.splice(productIndex, 1);
1790
+ if (!wishlist.products.length)
1791
+ return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
1792
+ return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
1793
+ }
1794
+ return wishlist;
1795
+ }
1796
+ }
1797
+ 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 });
1798
+ WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
1799
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
1800
+ type: Injectable
1801
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1802
+ type: Inject,
1803
+ args: ['WishlistRepository']
1804
+ }] }, { type: i1$2.Shops, decorators: [{
1805
+ type: Inject,
1806
+ args: [DEFAULT_SHOP]
1807
+ }] }, { type: undefined, decorators: [{
1808
+ type: Inject,
1809
+ args: ['ProductRepository']
1810
+ }] }, { type: undefined, decorators: [{
1811
+ type: Inject,
1812
+ args: ['CategoryFilterRepository']
1810
1813
  }] }, { type: i1$2.ProductsIndex }]; } });
1811
1814
 
1812
- class CheckoutSubscriptionService {
1813
- constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
1814
- this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
1815
- this.subscriptionRepository = subscriptionRepository;
1816
- this.couponService = couponService;
1817
- }
1818
- getCheckoutSubscription(checkoutData) {
1819
- const checkoutId = cookie.get('checkoutSubscriptionId');
1820
- if (!isNil(checkoutId))
1821
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
1822
- return from(this.createCheckoutSubscription(checkoutData));
1823
- }
1824
- async createCheckoutSubscription(checkoutData) {
1825
- const checkout = await this.checkoutSubscriptionRepository.create({
1826
- createdAt: new Date(),
1827
- ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1828
- });
1829
- cookie.set('checkoutSubscriptionId', checkout.id);
1830
- return checkout;
1831
- }
1832
- clearCheckoutSubscriptionFromSession() {
1833
- cookie.remove('checkoutSubscriptionId');
1834
- return of();
1835
- }
1836
- checkCoupon(nickname, userEmail) {
1837
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
1838
- .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
1839
- .pipe()));
1840
- }
1841
- calcDiscountSubscription(coupon) {
1842
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
1843
- }
1844
- }
1845
- 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 });
1846
- CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
1847
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
1848
- type: Injectable
1849
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1850
- type: Inject,
1851
- args: ['CheckoutSubscriptionRepository']
1852
- }] }, { type: undefined, decorators: [{
1853
- type: Inject,
1854
- args: ['SubscriptionRepository']
1815
+ class CheckoutSubscriptionService {
1816
+ constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
1817
+ this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
1818
+ this.subscriptionRepository = subscriptionRepository;
1819
+ this.couponService = couponService;
1820
+ }
1821
+ getCheckoutSubscription(checkoutData) {
1822
+ const checkoutId = cookie.get('checkoutSubscriptionId');
1823
+ if (!isNil(checkoutId))
1824
+ return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
1825
+ return from(this.createCheckoutSubscription(checkoutData));
1826
+ }
1827
+ async createCheckoutSubscription(checkoutData) {
1828
+ const checkout = await this.checkoutSubscriptionRepository.create({
1829
+ createdAt: new Date(),
1830
+ ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1831
+ });
1832
+ cookie.set('checkoutSubscriptionId', checkout.id);
1833
+ return checkout;
1834
+ }
1835
+ clearCheckoutSubscriptionFromSession() {
1836
+ cookie.remove('checkoutSubscriptionId');
1837
+ return of();
1838
+ }
1839
+ checkCoupon(nickname, userEmail) {
1840
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
1841
+ .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
1842
+ .pipe()));
1843
+ }
1844
+ calcDiscountSubscription(coupon) {
1845
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
1846
+ }
1847
+ }
1848
+ 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 });
1849
+ CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
1850
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
1851
+ type: Injectable
1852
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1853
+ type: Inject,
1854
+ args: ['CheckoutSubscriptionRepository']
1855
+ }] }, { type: undefined, decorators: [{
1856
+ type: Inject,
1857
+ args: ['SubscriptionRepository']
1855
1858
  }] }, { type: CouponService }]; } });
1856
1859
 
1857
- class UtilHelper {
1858
- static createSlug(name) {
1859
- return name
1860
- .toLowerCase()
1861
- .replace(/\s+/g, '-') // Replace spaces with -
1862
- .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
1863
- .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
1864
- .replace(/[ìíïî]/g, 'i') // Replace spaces with -
1865
- .replace(/[õòóöô]/g, 'o') // Replace spaces with -
1866
- .replace(/[ùúüû]/g, 'u') // Replace spaces with -
1867
- .replace(/[ñ]/g, 'n') // Replace spaces with -
1868
- .replace(/[ç]/g, 'c') // Replace spaces with -
1869
- .replace(/[&]/g, 'and') // Replace spaces with -
1870
- .replace(/[^\w\-]+/g, '') // Remove all non-word chars
1871
- .replace(/\-\-+/g, '-'); // Replace multiple - with single -
1872
- }
1860
+ class UtilHelper {
1861
+ static createSlug(name) {
1862
+ return name
1863
+ .toLowerCase()
1864
+ .replace(/\s+/g, '-') // Replace spaces with -
1865
+ .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
1866
+ .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
1867
+ .replace(/[ìíïî]/g, 'i') // Replace spaces with -
1868
+ .replace(/[õòóöô]/g, 'o') // Replace spaces with -
1869
+ .replace(/[ùúüû]/g, 'u') // Replace spaces with -
1870
+ .replace(/[ñ]/g, 'n') // Replace spaces with -
1871
+ .replace(/[ç]/g, 'c') // Replace spaces with -
1872
+ .replace(/[&]/g, 'and') // Replace spaces with -
1873
+ .replace(/[^\w\-]+/g, '') // Remove all non-word chars
1874
+ .replace(/\-\-+/g, '-'); // Replace multiple - with single -
1875
+ }
1873
1876
  }
1874
1877
 
1875
- class HomeShopService {
1876
- get homeId() {
1877
- if (this.defaultShop === Shops.GLAMSHOP)
1878
- return 'glamshop';
1879
- if (this.defaultShop === Shops.MENSMARKET)
1880
- return 'mens_market';
1881
- return null;
1882
- }
1883
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
1884
- this.categoryRepository = categoryRepository;
1885
- this.homeRepository = homeRepository;
1886
- this.productRepository = productRepository;
1887
- this.defaultShop = defaultShop;
1888
- this.buildCategoryGroupWithRequiredData = (group) => ({
1889
- category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
1890
- products: group?.products?.map((product) => Product.toInstance(pick(product?.toPlain() || {}, [
1891
- 'id',
1892
- 'price',
1893
- 'reviews',
1894
- 'hasVariants',
1895
- 'slug',
1896
- 'sku',
1897
- 'stock',
1898
- 'costPrice',
1899
- 'images',
1900
- 'miniatures',
1901
- 'name',
1902
- 'weight',
1903
- 'rate',
1904
- 'type',
1905
- ]))) || [],
1906
- });
1907
- }
1908
- getHomeData() {
1909
- return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
1910
- ? of(home)
1911
- : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
1912
- discoverProducts,
1913
- featuredProducts,
1914
- verticalProducts,
1915
- })), concatMap((data) => this.saveHomeData(data)))));
1916
- }
1917
- getBanners(type) {
1918
- return this.getHomeConfiguration().pipe(map((home) => {
1919
- if (type === 'brand')
1920
- return home.brandsCarousel;
1921
- if (type === 'buyToWin')
1922
- return [home.buyToWinBanner];
1923
- if (type === 'block')
1924
- return home.blockBanners;
1925
- if (type === 'blog')
1926
- return [home.blogBanner];
1927
- return [];
1928
- }));
1929
- }
1930
- getMinValueForFreeShipping() {
1931
- return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
1932
- }
1933
- getDiscoverProducts() {
1934
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
1935
- }
1936
- getFeaturedProducts() {
1937
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
1938
- }
1939
- getVerticalProducts() {
1940
- 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({
1941
- filters: { categories: { operator: Where.IN, value: [category.id] } },
1942
- limits: { limit: 12 },
1943
- })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
1944
- }
1945
- getHomeConfiguration() {
1946
- return of(this.homeConfiguration).pipe(concatMap((home) => home
1947
- ? of(home)
1948
- : !this.homeId
1949
- ? throwError(new RequiredArgumentError(['homeId']))
1950
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
1951
- }
1952
- saveHomeData(homeData) {
1953
- const data = {
1954
- createdAt: new Date(),
1955
- expiresAt: add(new Date(), { hours: 1 }),
1956
- data: homeData,
1957
- };
1958
- return from(this.homeRepository.update({
1959
- id: this.homeId,
1960
- data,
1961
- })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
1962
- }
1963
- }
1964
- 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 });
1965
- HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
1966
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
1967
- type: Injectable
1968
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1969
- type: Inject,
1970
- args: ['CategoryRepository']
1971
- }] }, { type: undefined, decorators: [{
1972
- type: Inject,
1973
- args: ['HomeRepository']
1974
- }] }, { type: undefined, decorators: [{
1975
- type: Inject,
1976
- args: ['ProductRepository']
1977
- }] }, { type: i1$2.Shops, decorators: [{
1978
- type: Inject,
1979
- args: [DEFAULT_SHOP]
1878
+ class HomeShopService {
1879
+ get homeId() {
1880
+ if (this.defaultShop === Shops.GLAMSHOP)
1881
+ return 'glamshop';
1882
+ if (this.defaultShop === Shops.MENSMARKET)
1883
+ return 'mens_market';
1884
+ return null;
1885
+ }
1886
+ constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
1887
+ this.categoryRepository = categoryRepository;
1888
+ this.homeRepository = homeRepository;
1889
+ this.productRepository = productRepository;
1890
+ this.defaultShop = defaultShop;
1891
+ this.buildCategoryGroupWithRequiredData = (group) => ({
1892
+ category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
1893
+ products: group?.products?.map((product) => Product.toInstance(pick(product?.toPlain() || {}, [
1894
+ 'id',
1895
+ 'price',
1896
+ 'reviews',
1897
+ 'hasVariants',
1898
+ 'slug',
1899
+ 'sku',
1900
+ 'stock',
1901
+ 'costPrice',
1902
+ 'images',
1903
+ 'miniatures',
1904
+ 'name',
1905
+ 'weight',
1906
+ 'rate',
1907
+ 'type',
1908
+ ]))) || [],
1909
+ });
1910
+ }
1911
+ getHomeData() {
1912
+ return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
1913
+ ? of(home)
1914
+ : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
1915
+ discoverProducts,
1916
+ featuredProducts,
1917
+ verticalProducts,
1918
+ })), concatMap((data) => this.saveHomeData(data)))));
1919
+ }
1920
+ getBanners(type) {
1921
+ return this.getHomeConfiguration().pipe(map((home) => {
1922
+ if (type === 'brand')
1923
+ return home.brandsCarousel;
1924
+ if (type === 'buyToWin')
1925
+ return [home.buyToWinBanner];
1926
+ if (type === 'block')
1927
+ return home.blockBanners;
1928
+ if (type === 'blog')
1929
+ return [home.blogBanner];
1930
+ return [];
1931
+ }));
1932
+ }
1933
+ getMinValueForFreeShipping() {
1934
+ return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
1935
+ }
1936
+ getDiscoverProducts() {
1937
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
1938
+ }
1939
+ getFeaturedProducts() {
1940
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
1941
+ }
1942
+ getVerticalProducts() {
1943
+ 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({
1944
+ filters: { categories: { operator: Where.IN, value: [category.id] } },
1945
+ limits: { limit: 12 },
1946
+ })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
1947
+ }
1948
+ getHomeConfiguration() {
1949
+ return of(this.homeConfiguration).pipe(concatMap((home) => home
1950
+ ? of(home)
1951
+ : !this.homeId
1952
+ ? throwError(new RequiredArgumentError(['homeId']))
1953
+ : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
1954
+ }
1955
+ saveHomeData(homeData) {
1956
+ const data = {
1957
+ createdAt: new Date(),
1958
+ expiresAt: add(new Date(), { hours: 1 }),
1959
+ data: homeData,
1960
+ };
1961
+ return from(this.homeRepository.update({
1962
+ id: this.homeId,
1963
+ data,
1964
+ })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
1965
+ }
1966
+ }
1967
+ 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 });
1968
+ HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
1969
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
1970
+ type: Injectable
1971
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1972
+ type: Inject,
1973
+ args: ['CategoryRepository']
1974
+ }] }, { type: undefined, decorators: [{
1975
+ type: Inject,
1976
+ args: ['HomeRepository']
1977
+ }] }, { type: undefined, decorators: [{
1978
+ type: Inject,
1979
+ args: ['ProductRepository']
1980
+ }] }, { type: i1$2.Shops, decorators: [{
1981
+ type: Inject,
1982
+ args: [DEFAULT_SHOP]
1980
1983
  }] }]; } });
1981
1984
 
1982
- class OrderService {
1983
- constructor(angularFirestore, orderRepository) {
1984
- this.angularFirestore = angularFirestore;
1985
- this.orderRepository = orderRepository;
1986
- this.orderSubject = new Subject();
1987
- }
1988
- getOrder(id) {
1989
- docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
1990
- .pipe(map((doc) => Order.toInstance(doc.data())))
1991
- .subscribe((doc) => this.orderSubject.next(doc));
1992
- return this.orderSubject;
1993
- }
1994
- }
1995
- 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 });
1996
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
1997
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
1998
- type: Injectable
1999
- }], ctorParameters: function () { return [{ type: i1$1.Firestore }, { type: i1$2.OrderFirestoreRepository, decorators: [{
2000
- type: Inject,
2001
- args: ['OrderRepository']
1985
+ class OrderService {
1986
+ constructor(angularFirestore, orderRepository) {
1987
+ this.angularFirestore = angularFirestore;
1988
+ this.orderRepository = orderRepository;
1989
+ this.orderSubject = new Subject();
1990
+ }
1991
+ getOrder(id) {
1992
+ docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
1993
+ .pipe(map((doc) => Order.toInstance(doc.data())))
1994
+ .subscribe((doc) => this.orderSubject.next(doc));
1995
+ return this.orderSubject;
1996
+ }
1997
+ }
1998
+ 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 });
1999
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
2000
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
2001
+ type: Injectable
2002
+ }], ctorParameters: function () { return [{ type: i1$1.Firestore }, { type: i1$2.OrderFirestoreRepository, decorators: [{
2003
+ type: Inject,
2004
+ args: ['OrderRepository']
2002
2005
  }] }]; } });
2003
2006
 
2004
- class ShippingService {
2005
- constructor(http, apiUrl, homeService) {
2006
- this.http = http;
2007
- this.apiUrl = apiUrl;
2008
- this.homeService = homeService;
2009
- }
2010
- getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
2011
- return combineLatest([
2012
- this.homeService.getHomeData(),
2013
- this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
2014
- ]).pipe(map(([datas, shippingMethodsResponse]) => {
2015
- let shippingMethods = shippingMethodsResponse.result;
2016
- if (!shippingMethods.length)
2017
- return [];
2018
- shippingMethods = shippingMethods.map((shippingMethod) => {
2019
- if (shippingMethod.ShippingCompanyName == 'Same Day EG')
2020
- shippingMethod.ShippingCompanyName = 'Same Day';
2021
- return shippingMethod;
2022
- });
2023
- const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
2024
- if (this.isHolidays(datasSameDayNotAvaliable)) {
2025
- shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
2026
- }
2027
- if (totalPrice >= 200) {
2028
- shippingMethods = shippingMethods.map((s) => {
2029
- if (s.serviceName !== 'Same Day')
2030
- return { ...s, totalPrice: 0 };
2031
- else
2032
- return s;
2033
- });
2034
- }
2035
- if (shop == Shops.GLAMSHOP)
2036
- return shippingMethods;
2037
- if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
2038
- shippingMethods = shippingMethods.map((s) => {
2039
- if (s.serviceName == 'Same Day')
2040
- return { ...s, totalPrice: s.totalPrice / 2 };
2041
- else
2042
- return { ...s, totalPrice: 0 };
2043
- });
2044
- }
2045
- if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
2046
- shippingMethods = shippingMethods.map((s) => {
2047
- return { ...s, totalPrice: s.totalPrice / 2 };
2048
- });
2049
- }
2050
- return shippingMethods;
2051
- }));
2052
- }
2053
- isFreeShippingBySubscription(shop, subscriptionPlan) {
2054
- if (!subscriptionPlan)
2055
- return false;
2056
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
2057
- return true;
2058
- return false;
2059
- }
2060
- isHalfShippingBySubscription(shop, subscriptionPlan) {
2061
- if (!subscriptionPlan)
2062
- return false;
2063
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
2064
- return true;
2065
- }
2066
- return false;
2067
- }
2068
- isHolidays(datas) {
2069
- const today = new Date();
2070
- for (const key in datas) {
2071
- let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
2072
- let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
2073
- if (start > end)
2074
- end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
2075
- if (today >= start && today <= end)
2076
- return true;
2077
- }
2078
- return false;
2079
- }
2080
- }
2081
- 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 });
2082
- ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
2083
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
2084
- type: Injectable
2085
- }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
2086
- type: Inject,
2087
- args: [BACKEND_URL]
2007
+ class ShippingService {
2008
+ constructor(http, apiUrl, homeService) {
2009
+ this.http = http;
2010
+ this.apiUrl = apiUrl;
2011
+ this.homeService = homeService;
2012
+ }
2013
+ getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
2014
+ return combineLatest([
2015
+ this.homeService.getHomeData(),
2016
+ this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
2017
+ ]).pipe(map(([datas, shippingMethodsResponse]) => {
2018
+ let shippingMethods = shippingMethodsResponse.result;
2019
+ if (!shippingMethods.length)
2020
+ return [];
2021
+ shippingMethods = shippingMethods.map((shippingMethod) => {
2022
+ if (shippingMethod.ShippingCompanyName == 'Same Day EG')
2023
+ shippingMethod.ShippingCompanyName = 'Same Day';
2024
+ return shippingMethod;
2025
+ });
2026
+ const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
2027
+ if (this.isHolidays(datasSameDayNotAvaliable)) {
2028
+ shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
2029
+ }
2030
+ if (totalPrice >= 200) {
2031
+ shippingMethods = shippingMethods.map((s) => {
2032
+ if (s.serviceName !== 'Same Day')
2033
+ return { ...s, totalPrice: 0 };
2034
+ else
2035
+ return s;
2036
+ });
2037
+ }
2038
+ if (shop == Shops.GLAMSHOP)
2039
+ return shippingMethods;
2040
+ if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
2041
+ shippingMethods = shippingMethods.map((s) => {
2042
+ if (s.serviceName == 'Same Day')
2043
+ return { ...s, totalPrice: s.totalPrice / 2 };
2044
+ else
2045
+ return { ...s, totalPrice: 0 };
2046
+ });
2047
+ }
2048
+ if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
2049
+ shippingMethods = shippingMethods.map((s) => {
2050
+ return { ...s, totalPrice: s.totalPrice / 2 };
2051
+ });
2052
+ }
2053
+ return shippingMethods;
2054
+ }));
2055
+ }
2056
+ isFreeShippingBySubscription(shop, subscriptionPlan) {
2057
+ if (!subscriptionPlan)
2058
+ return false;
2059
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
2060
+ return true;
2061
+ return false;
2062
+ }
2063
+ isHalfShippingBySubscription(shop, subscriptionPlan) {
2064
+ if (!subscriptionPlan)
2065
+ return false;
2066
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
2067
+ return true;
2068
+ }
2069
+ return false;
2070
+ }
2071
+ isHolidays(datas) {
2072
+ const today = new Date();
2073
+ for (const key in datas) {
2074
+ let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
2075
+ let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
2076
+ if (start > end)
2077
+ end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
2078
+ if (today >= start && today <= end)
2079
+ return true;
2080
+ }
2081
+ return false;
2082
+ }
2083
+ }
2084
+ 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 });
2085
+ ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
2086
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
2087
+ type: Injectable
2088
+ }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
2089
+ type: Inject,
2090
+ args: [BACKEND_URL]
2088
2091
  }] }, { type: HomeShopService }]; } });
2089
2092
 
2090
- class AngularConnectModule {
2091
- static initializeApp(defaultShop, options, nameOrConfig) {
2092
- return {
2093
- ngModule: AngularConnectModule,
2094
- providers: [
2095
- {
2096
- provide: CATEGORY_STRUCTURE,
2097
- useClass: isNil(options?.oldCategoryStructure) || options?.oldCategoryStructure
2098
- ? OldCategoryStructureAdapter
2099
- : NewCategoryStructureAdapter,
2100
- },
2101
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2102
- ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2103
- ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
2104
- ...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2105
- ...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2106
- ...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2107
- ],
2108
- };
2109
- }
2110
- }
2111
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2112
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, AngularElasticSeachModule,
2113
- AngularFirebaseAuthModule,
2114
- AngularFirestoreModule,
2115
- AngularHasuraGraphQLModule] });
2116
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, providers: [
2117
- AuthService,
2118
- CartService,
2119
- CatalogService,
2120
- CategoryService,
2121
- CheckoutService,
2122
- CheckoutSubscriptionService,
2123
- CouponService,
2124
- HomeShopService,
2125
- OrderService,
2126
- ShippingService,
2127
- WishlistService,
2128
- ], imports: [provideFirebaseApp((injector) => {
2129
- const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2130
- try {
2131
- return getApp(appName);
2132
- }
2133
- catch (error) {
2134
- return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2135
- }
2136
- }),
2137
- AngularElasticSeachModule,
2138
- AngularFirebaseAuthModule,
2139
- AngularFirestoreModule,
2140
- AngularHasuraGraphQLModule] });
2141
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, decorators: [{
2142
- type: NgModule,
2143
- args: [{
2144
- imports: [
2145
- provideFirebaseApp((injector) => {
2146
- const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2147
- try {
2148
- return getApp(appName);
2149
- }
2150
- catch (error) {
2151
- return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2152
- }
2153
- }),
2154
- AngularElasticSeachModule,
2155
- AngularFirebaseAuthModule,
2156
- AngularFirestoreModule,
2157
- AngularHasuraGraphQLModule,
2158
- ],
2159
- providers: [
2160
- AuthService,
2161
- CartService,
2162
- CatalogService,
2163
- CategoryService,
2164
- CheckoutService,
2165
- CheckoutSubscriptionService,
2166
- CouponService,
2167
- HomeShopService,
2168
- OrderService,
2169
- ShippingService,
2170
- WishlistService,
2171
- ],
2172
- }]
2093
+ class AngularConnectModule {
2094
+ static initializeApp(defaultShop, options, nameOrConfig) {
2095
+ return {
2096
+ ngModule: AngularConnectModule,
2097
+ providers: [
2098
+ {
2099
+ provide: CATEGORY_STRUCTURE,
2100
+ useClass: isNil(options?.oldCategoryStructure) || options?.oldCategoryStructure
2101
+ ? OldCategoryStructureAdapter
2102
+ : NewCategoryStructureAdapter,
2103
+ },
2104
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2105
+ ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2106
+ ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
2107
+ ...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2108
+ ...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2109
+ ...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2110
+ ],
2111
+ };
2112
+ }
2113
+ }
2114
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2115
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, AngularElasticSeachModule,
2116
+ AngularFirebaseAuthModule,
2117
+ AngularFirestoreModule,
2118
+ AngularHasuraGraphQLModule] });
2119
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, providers: [
2120
+ AuthService,
2121
+ CartService,
2122
+ CatalogService,
2123
+ CategoryService,
2124
+ CheckoutService,
2125
+ CheckoutSubscriptionService,
2126
+ CouponService,
2127
+ HomeShopService,
2128
+ OrderService,
2129
+ ShippingService,
2130
+ WishlistService,
2131
+ ], imports: [provideFirebaseApp((injector) => {
2132
+ const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2133
+ try {
2134
+ return getApp(appName);
2135
+ }
2136
+ catch (error) {
2137
+ return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2138
+ }
2139
+ }),
2140
+ AngularElasticSeachModule,
2141
+ AngularFirebaseAuthModule,
2142
+ AngularFirestoreModule,
2143
+ AngularHasuraGraphQLModule] });
2144
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, decorators: [{
2145
+ type: NgModule,
2146
+ args: [{
2147
+ imports: [
2148
+ provideFirebaseApp((injector) => {
2149
+ const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2150
+ try {
2151
+ return getApp(appName);
2152
+ }
2153
+ catch (error) {
2154
+ return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2155
+ }
2156
+ }),
2157
+ AngularElasticSeachModule,
2158
+ AngularFirebaseAuthModule,
2159
+ AngularFirestoreModule,
2160
+ AngularHasuraGraphQLModule,
2161
+ ],
2162
+ providers: [
2163
+ AuthService,
2164
+ CartService,
2165
+ CatalogService,
2166
+ CategoryService,
2167
+ CheckoutService,
2168
+ CheckoutSubscriptionService,
2169
+ CouponService,
2170
+ HomeShopService,
2171
+ OrderService,
2172
+ ShippingService,
2173
+ WishlistService,
2174
+ ],
2175
+ }]
2173
2176
  }] });
2174
2177
 
2175
- /**
2176
- * Generated bundle index. Do not edit.
2178
+ /**
2179
+ * Generated bundle index. Do not edit.
2177
2180
  */
2178
2181
 
2179
2182
  export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };