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