@infrab4a/connect-angular 4.0.0-beta.47 → 4.0.0-beta.49

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