@infrab4a/connect-angular 4.1.6-beta.4 → 4.1.7-beta.0

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