@infrab4a/connect-angular 4.5.6 → 4.5.7

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