@infrab4a/connect-angular 4.1.1-beta.0 → 4.1.1

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