@infrab4a/connect-angular 3.10.0-beta.9 → 3.10.2

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