@infrab4a/connect-angular 4.2.2 → 4.2.3-beta.1

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