@infrab4a/connect-angular 4.0.0-beta.45 → 4.0.0-beta.47

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