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

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