@infrab4a/connect-angular 4.3.9 → 4.3.10-beta.1

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