@infrab4a/connect-angular 4.0.0-beta.60 → 4.0.0-beta.7

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