@infrab4a/connect-angular 4.1.0-beta.0 → 4.1.0-beta.10

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