@infrab4a/connect-angular 4.0.0-beta.39 → 4.0.0-beta.40

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