@infrab4a/connect-angular 4.5.4-beta.2 → 4.5.4-beta.4

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