@infrab4a/connect-angular 4.3.7-beta.7 → 4.3.7-beta.8

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