@infrab4a/connect-angular 4.5.6 → 4.5.7

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