@infrab4a/connect-angular 4.0.0-beta.41 → 4.0.0-beta.43

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