@infrab4a/connect-angular 4.6.0-beta.2 → 4.6.1-beta.0

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 -230
  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 +129 -123
  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 +2423 -2417
  68. package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
  69. package/fesm2020/infrab4a-connect-angular.mjs +2364 -2358
  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 +2 -5
  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 +44 -44
  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,2447 +56,2453 @@ 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(product.stock.quantity, item.quantity || 0, quantity || 0))
1359
- throw new Error('Desculpe! Temos apenas ' + ((_c = product.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 = (currentStock, currentItemQtd, quantityToAdd) => {
1401
- const maxStock = currentStock || 0;
1402
- const currentItemAmount = currentItemQtd || 0;
1403
- return currentItemAmount + quantityToAdd > maxStock;
1404
- };
1405
- }
1406
- addItem(item, quantity = 1) {
1407
- 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)));
1408
- }
1409
- decreaseItem(item) {
1410
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1411
- var _a;
1412
- const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
1413
- if (!isNil(checkoutItem))
1414
- checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
1415
- return checkout;
1416
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1417
- }
1418
- getCart(checkout) {
1419
- this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
1420
- return this.cartSubject;
1421
- }
1422
- /**
1423
- * @deprecated The method should not be used
1424
- */
1425
- getVariantPriceDiscount(item) {
1426
- 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)));
1427
- }
1428
- removeItem(item) {
1429
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1430
- const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
1431
- if (index >= 0)
1432
- checkout.lineItems.splice(index, 1);
1433
- return checkout;
1434
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1435
- }
1436
- updateUserCart(user) {
1437
- 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* () {
1438
- var _a, _b;
1439
- return yield this.checkoutService
1440
- .updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
1441
- ? 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; })))
1442
- : [] })))
1443
- .toPromise();
1444
- })), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1445
- }
1446
- clearCart() {
1447
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1448
- this.checkoutService.clearCheckoutFromSession();
1449
- return checkout;
1450
- }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
1451
- }
1452
- buildCartFromCheckout(checkoutData) {
1453
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1454
- }
1455
- roundPrice(productPrice) {
1456
- const { price, fullPrice, subscriberPrice } = productPrice;
1457
- return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
1458
- }
1459
- getProductData(productId) {
1460
- return __awaiter(this, void 0, void 0, function* () {
1461
- let product;
1462
- let variant;
1463
- try {
1464
- product = yield this.productRepository.get({ id: productId });
1465
- }
1466
- catch (error) {
1467
- if (!(error instanceof NotFoundError))
1468
- throw error;
1469
- const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
1470
- variant = variants.shift();
1471
- if (!variant)
1472
- throw error;
1473
- product = yield this.productRepository.get({ id: variant.productId });
1474
- }
1475
- return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
1476
- });
1477
- }
1478
- getGifts() {
1479
- return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
1480
- const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
1481
- if (!notGiftItems.length)
1482
- return Object.assign(Object.assign({}, checkout), { lineItems: [] });
1483
- const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1484
- const campaigns = yield this.buy2WinRepository
1485
- .find({
1486
- filters: {
1487
- active: { operator: Where.EQUALS, value: true },
1488
- shop: { operator: Where.EQUALS, value: this.defaultShop },
1489
- },
1490
- })
1491
- .then((data) => data.data);
1492
- if (!campaigns.length)
1493
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1494
- const elegibleCampaigns = [];
1495
- for (const campaign of campaigns) {
1496
- const today = new Date().getTime();
1497
- if (!(campaign.startDate.getTime() <= today) && !(campaign.endDate.getTime() >= today))
1498
- continue;
1499
- if (campaign.activeCategory) {
1500
- const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
1501
- const categoriesCampaingFullTree = [];
1502
- for (const id of categoriesCampaing) {
1503
- const children = yield this.categoryRepository.getChildren(parseInt(id));
1504
- categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
1505
- }
1506
- const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
1507
- const filterProductsCategories = checkout.lineItems.filter((l) => {
1508
- var _a;
1509
- if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
1510
- return true;
1511
- return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
1512
- });
1513
- if (filterProductsCategories.length) {
1514
- const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1515
- if (cartTotalCategories >= campaign.cartValueMin)
1516
- elegibleCampaigns.push(campaign);
1517
- }
1518
- }
1519
- else {
1520
- if (campaign.cartValue && campaign.cartValue > 0) {
1521
- if (campaign.cartValue <= cartTotal)
1522
- elegibleCampaigns.push(campaign);
1523
- }
1524
- }
1525
- }
1526
- if (!elegibleCampaigns.length)
1527
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1528
- const campaingnProducts = [];
1529
- for (const campaign of elegibleCampaigns) {
1530
- let elegibleProducts = [];
1531
- for (const product of campaign.products) {
1532
- const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
1533
- if (!productData.length)
1534
- continue;
1535
- const gift = productData.shift();
1536
- if (gift.stock.quantity < 1)
1537
- continue;
1538
- elegibleProducts.push(gift);
1539
- }
1540
- campaingnProducts.push(elegibleProducts);
1541
- }
1542
- if (!campaingnProducts.length)
1543
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1544
- const gifts = this.giftToLineItems([].concat(...campaingnProducts));
1545
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
1546
- })), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1547
- }
1548
- giftToLineItems(items) {
1549
- return items.map((item) => {
1550
- var _a;
1551
- const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
1552
- 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];
1553
- return LineItem.toInstance({
1554
- brand,
1555
- categories,
1556
- id: id.toString(),
1557
- name,
1558
- price,
1559
- sku,
1560
- slug,
1561
- stock,
1562
- weight,
1563
- EAN,
1564
- image,
1565
- pricePaid: 0,
1566
- quantity: 1,
1567
- isGift: true,
1568
- });
1569
- });
1570
- }
1571
- }
1572
- 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 });
1573
- CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
1574
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
1575
- type: Injectable
1576
- }], ctorParameters: function () {
1577
- return [{ type: AuthService }, { type: CheckoutService }, { type: i1$2.Shops, decorators: [{
1578
- type: Inject,
1579
- args: [DEFAULT_SHOP]
1580
- }] }, { type: undefined, decorators: [{
1581
- type: Inject,
1582
- args: ['ProductRepository']
1583
- }] }, { type: undefined, decorators: [{
1584
- type: Inject,
1585
- args: ['CategoryRepository']
1586
- }] }, { type: undefined, decorators: [{
1587
- type: Inject,
1588
- args: ['VariantRepository']
1589
- }] }, { type: i1$2.Buy2WinFirestoreRepository, decorators: [{
1590
- type: Inject,
1591
- args: ['Buy2WinRepository']
1592
- }] }];
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(product.stock.quantity, item.quantity || 0, quantity || 0))
1359
+ throw new Error('Desculpe! Temos apenas ' + ((_c = product.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 = (currentStock, currentItemQtd, quantityToAdd) => {
1401
+ const maxStock = currentStock || 0;
1402
+ const currentItemAmount = currentItemQtd || 0;
1403
+ return currentItemAmount + quantityToAdd > maxStock;
1404
+ };
1405
+ }
1406
+ addItem(item, quantity = 1) {
1407
+ 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)));
1408
+ }
1409
+ decreaseItem(item) {
1410
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
1411
+ var _a;
1412
+ const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
1413
+ if (!isNil(checkoutItem))
1414
+ checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
1415
+ return checkout;
1416
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1417
+ }
1418
+ getCart(checkout) {
1419
+ this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
1420
+ return this.cartSubject;
1421
+ }
1422
+ /**
1423
+ * @deprecated The method should not be used
1424
+ */
1425
+ getVariantPriceDiscount(item) {
1426
+ 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)));
1427
+ }
1428
+ removeItem(item) {
1429
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
1430
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
1431
+ if (index >= 0)
1432
+ checkout.lineItems.splice(index, 1);
1433
+ return checkout;
1434
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1435
+ }
1436
+ updateUserCart(user) {
1437
+ 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* () {
1438
+ var _a, _b;
1439
+ return yield this.checkoutService
1440
+ .updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
1441
+ ? 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; })))
1442
+ : [] })))
1443
+ .toPromise();
1444
+ })), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1445
+ }
1446
+ clearCart() {
1447
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
1448
+ this.checkoutService.clearCheckoutFromSession();
1449
+ return checkout;
1450
+ }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
1451
+ }
1452
+ buildCartFromCheckout(checkoutData) {
1453
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1454
+ }
1455
+ roundPrice(productPrice) {
1456
+ const { price, fullPrice, subscriberPrice } = productPrice;
1457
+ return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
1458
+ }
1459
+ getProductData(productId) {
1460
+ return __awaiter(this, void 0, void 0, function* () {
1461
+ let product;
1462
+ let variant;
1463
+ try {
1464
+ product = yield this.productRepository.get({ id: productId });
1465
+ }
1466
+ catch (error) {
1467
+ if (!(error instanceof NotFoundError))
1468
+ throw error;
1469
+ const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
1470
+ variant = variants.shift();
1471
+ if (!variant)
1472
+ throw error;
1473
+ product = yield this.productRepository.get({ id: variant.productId });
1474
+ }
1475
+ return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
1476
+ });
1477
+ }
1478
+ getGifts() {
1479
+ return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
1480
+ const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
1481
+ if (!notGiftItems.length)
1482
+ return Object.assign(Object.assign({}, checkout), { lineItems: [] });
1483
+ const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1484
+ const campaigns = yield this.buy2WinRepository
1485
+ .find({
1486
+ filters: {
1487
+ active: { operator: Where.EQUALS, value: true },
1488
+ shop: { operator: Where.EQUALS, value: this.defaultShop },
1489
+ },
1490
+ })
1491
+ .then((data) => data.data);
1492
+ if (!campaigns.length)
1493
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1494
+ const elegibleCampaigns = [];
1495
+ for (const campaign of campaigns) {
1496
+ const today = new Date().getTime();
1497
+ if (!(campaign.startDate.getTime() <= today) && !(campaign.endDate.getTime() >= today))
1498
+ continue;
1499
+ if (campaign.activeCategory) {
1500
+ const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
1501
+ const categoriesCampaingFullTree = [];
1502
+ for (const id of categoriesCampaing) {
1503
+ const children = yield this.categoryRepository.getChildren(parseInt(id));
1504
+ categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
1505
+ }
1506
+ const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
1507
+ const filterProductsCategories = checkout.lineItems.filter((l) => {
1508
+ var _a;
1509
+ if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
1510
+ return true;
1511
+ return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
1512
+ });
1513
+ if (filterProductsCategories.length) {
1514
+ const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1515
+ if (cartTotalCategories >= campaign.cartValueMin)
1516
+ elegibleCampaigns.push(campaign);
1517
+ }
1518
+ }
1519
+ else {
1520
+ if (campaign.cartValue && campaign.cartValue > 0) {
1521
+ if (campaign.cartValue <= cartTotal)
1522
+ elegibleCampaigns.push(campaign);
1523
+ }
1524
+ }
1525
+ }
1526
+ if (!elegibleCampaigns.length)
1527
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1528
+ const campaingnProducts = [];
1529
+ for (const campaign of elegibleCampaigns) {
1530
+ let elegibleProducts = [];
1531
+ for (const product of campaign.products) {
1532
+ const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
1533
+ if (!productData.length)
1534
+ continue;
1535
+ const gift = productData.shift();
1536
+ if (gift.stock.quantity < 1)
1537
+ continue;
1538
+ elegibleProducts.push(gift);
1539
+ }
1540
+ campaingnProducts.push(elegibleProducts);
1541
+ }
1542
+ if (!campaingnProducts.length)
1543
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1544
+ const gifts = this.giftToLineItems([].concat(...campaingnProducts));
1545
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
1546
+ })), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1547
+ }
1548
+ giftToLineItems(items) {
1549
+ return items.map((item) => {
1550
+ var _a;
1551
+ const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
1552
+ 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];
1553
+ return LineItem.toInstance({
1554
+ brand,
1555
+ categories,
1556
+ id: id.toString(),
1557
+ name,
1558
+ price,
1559
+ sku,
1560
+ slug,
1561
+ stock,
1562
+ weight,
1563
+ EAN,
1564
+ image,
1565
+ pricePaid: 0,
1566
+ quantity: 1,
1567
+ isGift: true,
1568
+ });
1569
+ });
1570
+ }
1571
+ }
1572
+ 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 });
1573
+ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
1574
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
1575
+ type: Injectable
1576
+ }], ctorParameters: function () {
1577
+ return [{ type: AuthService }, { type: CheckoutService }, { type: i1$2.Shops, decorators: [{
1578
+ type: Inject,
1579
+ args: [DEFAULT_SHOP]
1580
+ }] }, { type: undefined, decorators: [{
1581
+ type: Inject,
1582
+ args: ['ProductRepository']
1583
+ }] }, { type: undefined, decorators: [{
1584
+ type: Inject,
1585
+ args: ['CategoryRepository']
1586
+ }] }, { type: undefined, decorators: [{
1587
+ type: Inject,
1588
+ args: ['VariantRepository']
1589
+ }] }, { type: i1$2.Buy2WinFirestoreRepository, decorators: [{
1590
+ type: Inject,
1591
+ args: ['Buy2WinRepository']
1592
+ }] }];
1593
1593
  } });
1594
1594
 
1595
- class NewCategoryStructureAdapter {
1596
- constructor(categoryRepository) {
1597
- this.categoryRepository = categoryRepository;
1598
- }
1599
- buildProductFilterByCategory(category) {
1600
- return __awaiter(this, void 0, void 0, function* () {
1601
- const loadedCategory = yield this.getCategory(category);
1602
- if (loadedCategory.isCollection)
1603
- return { id: { operator: Where.IN, value: loadedCategory.products } };
1604
- const categoryIds = [...(yield this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1605
- return {
1606
- category: {
1607
- id: {
1608
- operator: Where.IN,
1609
- value: categoryIds,
1610
- },
1611
- },
1612
- };
1613
- });
1614
- }
1615
- getAllCategoriesIdFromCategory(category) {
1616
- return __awaiter(this, void 0, void 0, function* () {
1617
- return this.categoryRepository
1618
- .getChildren(+category.id)
1619
- .then((categories) => categories.map((category) => category.id.toString()));
1620
- });
1621
- }
1622
- getCategory(category) {
1623
- var _a;
1624
- return __awaiter(this, void 0, void 0, function* () {
1625
- const collectionCategory = category.isCollection ||
1626
- (isNil(category.isCollection) && !((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)) ||
1627
- category.isWishlist ||
1628
- category.brandCategory;
1629
- return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
1630
- });
1631
- }
1632
- }
1633
- NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1634
- NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
1635
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1636
- type: Injectable
1637
- }], ctorParameters: function () {
1638
- return [{ type: undefined, decorators: [{
1639
- type: Inject,
1640
- args: ['CategoryRepository']
1641
- }] }];
1595
+ class NewCategoryStructureAdapter {
1596
+ constructor(categoryRepository) {
1597
+ this.categoryRepository = categoryRepository;
1598
+ }
1599
+ buildProductFilterByCategory(category) {
1600
+ return __awaiter(this, void 0, void 0, function* () {
1601
+ const loadedCategory = yield this.getCategory(category);
1602
+ if (loadedCategory.isCollection)
1603
+ return { id: { operator: Where.IN, value: loadedCategory.products } };
1604
+ const categoryIds = [...(yield this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1605
+ return {
1606
+ category: {
1607
+ id: {
1608
+ operator: Where.IN,
1609
+ value: categoryIds,
1610
+ },
1611
+ },
1612
+ };
1613
+ });
1614
+ }
1615
+ getAllCategoriesIdFromCategory(category) {
1616
+ return __awaiter(this, void 0, void 0, function* () {
1617
+ return this.categoryRepository
1618
+ .getChildren(+category.id)
1619
+ .then((categories) => categories.map((category) => category.id.toString()));
1620
+ });
1621
+ }
1622
+ getCategory(category) {
1623
+ var _a;
1624
+ return __awaiter(this, void 0, void 0, function* () {
1625
+ const collectionCategory = category.isCollection ||
1626
+ (isNil(category.isCollection) && !((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)) ||
1627
+ category.isWishlist ||
1628
+ category.brandCategory;
1629
+ return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
1630
+ });
1631
+ }
1632
+ }
1633
+ NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1634
+ NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
1635
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1636
+ type: Injectable
1637
+ }], ctorParameters: function () {
1638
+ return [{ type: undefined, decorators: [{
1639
+ type: Inject,
1640
+ args: ['CategoryRepository']
1641
+ }] }];
1642
1642
  } });
1643
1643
 
1644
- class OldCategoryStructureAdapter {
1645
- constructor(categoryRepository) {
1646
- this.categoryRepository = categoryRepository;
1647
- }
1648
- buildProductFilterByCategory(category) {
1649
- var _a;
1650
- return __awaiter(this, void 0, void 0, function* () {
1651
- const productsIds = ((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)
1652
- ? category.products
1653
- : yield this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1654
- return { id: { operator: Where.IN, value: productsIds } };
1655
- });
1656
- }
1657
- }
1658
- OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1659
- OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
1660
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1661
- type: Injectable
1662
- }], ctorParameters: function () {
1663
- return [{ type: undefined, decorators: [{
1664
- type: Inject,
1665
- args: ['CategoryRepository']
1666
- }] }];
1644
+ class OldCategoryStructureAdapter {
1645
+ constructor(categoryRepository) {
1646
+ this.categoryRepository = categoryRepository;
1647
+ }
1648
+ buildProductFilterByCategory(category) {
1649
+ var _a;
1650
+ return __awaiter(this, void 0, void 0, function* () {
1651
+ const productsIds = ((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)
1652
+ ? category.products
1653
+ : yield this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1654
+ return { id: { operator: Where.IN, value: productsIds } };
1655
+ });
1656
+ }
1657
+ }
1658
+ OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1659
+ OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
1660
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1661
+ type: Injectable
1662
+ }], ctorParameters: function () {
1663
+ return [{ type: undefined, decorators: [{
1664
+ type: Inject,
1665
+ args: ['CategoryRepository']
1666
+ }] }];
1667
1667
  } });
1668
1668
 
1669
- class CatalogService {
1670
- constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
1671
- this.productRepository = productRepository;
1672
- this.productStockNotificationRepository = productStockNotificationRepository;
1673
- this.categoryRepository = categoryRepository;
1674
- this.categoryStructureAdapter = categoryStructureAdapter;
1675
- this.shop = shop;
1676
- this.productIndex = productIndex;
1677
- this.productsByTerm = {};
1678
- this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1679
- const filters = {};
1680
- if (clubDiscount === null || clubDiscount === void 0 ? void 0 : clubDiscount.length)
1681
- set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1682
- if (brands === null || brands === void 0 ? void 0 : brands.length)
1683
- filters.brand = { operator: Where.IN, value: brands };
1684
- if (gender === null || gender === void 0 ? void 0 : gender.length)
1685
- filters.gender = { operator: Where.IN, value: gender };
1686
- if ((prices === null || prices === void 0 ? void 0 : prices.min) || (prices === null || prices === void 0 ? void 0 : prices.max))
1687
- set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1688
- ...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
1689
- ...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
1690
- ]);
1691
- if (rate)
1692
- filters.rate = { operator: Where.GTE, value: rate };
1693
- if (tags === null || tags === void 0 ? void 0 : tags.length)
1694
- filters.tags = { operator: Where.LIKE, value: tags };
1695
- if (customOptions === null || customOptions === void 0 ? void 0 : customOptions.length)
1696
- filters.filters = { operator: Where.LIKE, value: customOptions };
1697
- return filters;
1698
- };
1699
- this.buildSortQuery = (sort) => {
1700
- if (!sort || sort === 'most-relevant')
1701
- return {};
1702
- if (sort === 'best-sellers')
1703
- return {
1704
- shoppingCount: 'desc',
1705
- rate: 'desc',
1706
- stock: 'desc',
1707
- name: 'asc',
1708
- };
1709
- if (sort === 'biggest-price')
1710
- return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1711
- if (sort === 'lowest-price')
1712
- return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1713
- if (sort === 'best-rating')
1714
- return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1715
- if (sort === 'news')
1716
- return { createdAt: 'desc' };
1717
- if (sort === 'biggest-discount')
1718
- return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1719
- };
1720
- this.buildLimitQuery = (options) => {
1721
- const limit = (options === null || options === void 0 ? void 0 : options.perPage) || 20;
1722
- return {
1723
- limit,
1724
- offset: (((options === null || options === void 0 ? void 0 : options.page) || 1) - 1) * limit,
1725
- };
1726
- };
1727
- this.hasProfile = (options) => 'profile' in options;
1728
- this.hasTerm = (options) => 'term' in options;
1729
- this.hasCategory = (options) => 'category' in options;
1730
- }
1731
- fetchProducts(options) {
1732
- var _a, _b, _c;
1733
- return __awaiter(this, void 0, void 0, function* () {
1734
- const limits = this.buildLimitQuery(options);
1735
- if (this.hasProfile(options) && ((_a = options.filters) === null || _a === void 0 ? void 0 : _a.customOptions))
1736
- throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
1737
- if (this.hasProfile(options) && ((_b = options.filters) === null || _b === void 0 ? void 0 : _b.tags))
1738
- throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1739
- if (this.hasTerm(options) && ((_c = options.filters) === null || _c === void 0 ? void 0 : _c.customOptions))
1740
- throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1741
- return yield this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => {
1742
- var _a, _b, _c, _d, _e, _f, _g, _h;
1743
- return ({
1744
- products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1745
- pages: Math.ceil(total / limits.limit),
1746
- prices: {
1747
- 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)) },
1748
- subscriberPrice: {
1749
- 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)),
1750
- 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)),
1751
- },
1752
- },
1753
- brands: distinct === null || distinct === void 0 ? void 0 : distinct.brand,
1754
- });
1755
- });
1756
- });
1757
- }
1758
- addCustomerToStockNotification(shop, productId, name, email) {
1759
- return __awaiter(this, void 0, void 0, function* () {
1760
- return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1761
- });
1762
- }
1763
- findCatalog(options, limits) {
1764
- var _a;
1765
- return __awaiter(this, void 0, void 0, function* () {
1766
- if (this.hasTerm(options) && options.sort === 'most-relevant') {
1767
- const productsIds = yield this.findCatalogIdsByElasticSearch(options.term);
1768
- return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1769
- }
1770
- if (this.hasCategory(options) && options.sort === 'most-relevant') {
1771
- const mostRelevant = (_a = options.category.mostRelevant) !== null && _a !== void 0 ? _a : [];
1772
- const productsIds = yield this.productRepository
1773
- .findCatalog({
1774
- fields: ['id'],
1775
- filters: Object.assign(Object.assign({}, (yield this.buildMainFilter(options))), this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1776
- })
1777
- .then((products) => products.data.map((product) => product.id));
1778
- return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
1779
- }
1780
- 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'] } : {})) });
1781
- if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1782
- return this.productRepository.findCatalog(repoParams);
1783
- return this.productRepository.findCatalog(repoParams, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1784
- });
1785
- }
1786
- buildMainFilter({ category, profile, term, }) {
1787
- return __awaiter(this, void 0, void 0, function* () {
1788
- if (category)
1789
- return this.categoryStructureAdapter.buildProductFilterByCategory(category);
1790
- if (profile)
1791
- return { tags: { operator: Where.LIKE, value: profile } };
1792
- if (term)
1793
- return this.productIndex
1794
- .search(term, 999, this.shop)
1795
- .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1796
- });
1797
- }
1798
- findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1799
- return __awaiter(this, void 0, void 0, function* () {
1800
- const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1801
- const totalResult = yield this.productRepository.findCatalog({
1802
- filters: Object.assign({ id: { operator: Where.IN, value: mostRelevantProductsIds } }, this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1803
- orderBy: this.buildSortQuery('news'),
1804
- options: {
1805
- minimal: ['price'],
1806
- maximum: ['price'],
1807
- distinct: ['brand'],
1808
- },
1809
- }, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1810
- const firstProducts = totalResult.data.filter((product) => mostRelevants.includes(product.id));
1811
- const lastProducts = totalResult.data.filter((product) => !mostRelevants.includes(product.id));
1812
- const categoryMostRelevants = firstProducts.concat(lastProducts);
1813
- const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1814
- return {
1815
- data: resultFinal,
1816
- count: totalResult.count,
1817
- maximum: totalResult.maximum,
1818
- minimal: totalResult.minimal,
1819
- distinct: totalResult.distinct,
1820
- };
1821
- });
1822
- }
1823
- findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1824
- return __awaiter(this, void 0, void 0, function* () {
1825
- const totalResult = yield this.productRepository.findCatalog({
1826
- fields: ['id', 'stock'],
1827
- filters: Object.assign({ id: { operator: Where.IN, value: productIds } }, this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1828
- options: {
1829
- minimal: ['price'],
1830
- maximum: ['price'],
1831
- distinct: ['brand'],
1832
- },
1833
- }, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1834
- const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1835
- const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1836
- const productIdsStock = productIds.filter((product) => stockData.some((result) => result.id == product));
1837
- const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id == product));
1838
- const limitedProductId = productIdsStock
1839
- .concat(productIdsStockOut)
1840
- .slice(limits.offset, limits.offset + limits.limit);
1841
- const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1842
- const productResult = yield this.productRepository.findCatalog({
1843
- filters: {
1844
- id: { operator: Where.IN, value: orderedId },
1845
- },
1846
- });
1847
- return {
1848
- data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1849
- count: totalResult.count,
1850
- maximum: totalResult.maximum,
1851
- minimal: totalResult.minimal,
1852
- distinct: totalResult.distinct,
1853
- };
1854
- });
1855
- }
1856
- findCatalogIdsByElasticSearch(term) {
1857
- return __awaiter(this, void 0, void 0, function* () {
1858
- if (this.productsByTerm[term])
1859
- return this.productsByTerm[term];
1860
- return (this.productsByTerm[term] = yield this.productIndex
1861
- .search(term, 999, this.shop)
1862
- .then(({ hits: products }) => {
1863
- const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
1864
- const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
1865
- const sorted = [...withStock, ...withOutStock];
1866
- return [...new Set(sorted.map(({ _source }) => _source.id))];
1867
- }));
1868
- });
1869
- }
1870
- }
1871
- 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 });
1872
- CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1873
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1874
- type: Injectable
1875
- }], ctorParameters: function () {
1876
- return [{ type: undefined, decorators: [{
1877
- type: Inject,
1878
- args: ['ProductRepository']
1879
- }] }, { type: undefined, decorators: [{
1880
- type: Inject,
1881
- args: ['ProductStockNotificationRepository']
1882
- }] }, { type: undefined, decorators: [{
1883
- type: Inject,
1884
- args: ['CategoryRepository']
1885
- }] }, { type: undefined, decorators: [{
1886
- type: Inject,
1887
- args: [CATEGORY_STRUCTURE]
1888
- }] }, { type: i1$2.Shops, decorators: [{
1889
- type: Inject,
1890
- args: [DEFAULT_SHOP]
1891
- }] }, { type: i1$2.ProductsIndex }];
1669
+ class CatalogService {
1670
+ constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
1671
+ this.productRepository = productRepository;
1672
+ this.productStockNotificationRepository = productStockNotificationRepository;
1673
+ this.categoryRepository = categoryRepository;
1674
+ this.categoryStructureAdapter = categoryStructureAdapter;
1675
+ this.shop = shop;
1676
+ this.productIndex = productIndex;
1677
+ this.productsByTerm = {};
1678
+ this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1679
+ const filters = {};
1680
+ if (clubDiscount === null || clubDiscount === void 0 ? void 0 : clubDiscount.length)
1681
+ set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1682
+ if (brands === null || brands === void 0 ? void 0 : brands.length)
1683
+ filters.brand = { operator: Where.IN, value: brands };
1684
+ if (gender === null || gender === void 0 ? void 0 : gender.length)
1685
+ filters.gender = { operator: Where.IN, value: gender };
1686
+ if ((prices === null || prices === void 0 ? void 0 : prices.min) || (prices === null || prices === void 0 ? void 0 : prices.max))
1687
+ set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1688
+ ...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
1689
+ ...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
1690
+ ]);
1691
+ if (rate)
1692
+ filters.rate = { operator: Where.GTE, value: rate };
1693
+ if (tags === null || tags === void 0 ? void 0 : tags.length)
1694
+ filters.tags = { operator: Where.LIKE, value: tags };
1695
+ if (customOptions === null || customOptions === void 0 ? void 0 : customOptions.length)
1696
+ filters.filters = { operator: Where.LIKE, value: customOptions };
1697
+ return filters;
1698
+ };
1699
+ this.buildSortQuery = (sort) => {
1700
+ if (!sort || sort === 'most-relevant')
1701
+ return {};
1702
+ if (sort === 'best-sellers')
1703
+ return {
1704
+ shoppingCount: 'desc',
1705
+ rate: 'desc',
1706
+ stock: 'desc',
1707
+ name: 'asc',
1708
+ };
1709
+ if (sort === 'biggest-price')
1710
+ return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1711
+ if (sort === 'lowest-price')
1712
+ return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1713
+ if (sort === 'best-rating')
1714
+ return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1715
+ if (sort === 'news')
1716
+ return { createdAt: 'desc' };
1717
+ if (sort === 'biggest-discount')
1718
+ return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1719
+ };
1720
+ this.buildLimitQuery = (options) => {
1721
+ const limit = (options === null || options === void 0 ? void 0 : options.perPage) || 20;
1722
+ return {
1723
+ limit,
1724
+ offset: (((options === null || options === void 0 ? void 0 : options.page) || 1) - 1) * limit,
1725
+ };
1726
+ };
1727
+ this.hasProfile = (options) => 'profile' in options;
1728
+ this.hasTerm = (options) => 'term' in options;
1729
+ this.hasCategory = (options) => 'category' in options;
1730
+ }
1731
+ fetchProducts(options) {
1732
+ var _a, _b, _c;
1733
+ return __awaiter(this, void 0, void 0, function* () {
1734
+ const limits = this.buildLimitQuery(options);
1735
+ if (this.hasProfile(options) && ((_a = options.filters) === null || _a === void 0 ? void 0 : _a.customOptions))
1736
+ throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
1737
+ if (this.hasProfile(options) && ((_b = options.filters) === null || _b === void 0 ? void 0 : _b.tags))
1738
+ throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1739
+ if (this.hasTerm(options) && ((_c = options.filters) === null || _c === void 0 ? void 0 : _c.customOptions))
1740
+ throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1741
+ return yield this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => {
1742
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1743
+ return ({
1744
+ products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1745
+ pages: Math.ceil(total / limits.limit),
1746
+ prices: {
1747
+ 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)) },
1748
+ subscriberPrice: {
1749
+ 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)),
1750
+ 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)),
1751
+ },
1752
+ },
1753
+ brands: distinct === null || distinct === void 0 ? void 0 : distinct.brand,
1754
+ });
1755
+ });
1756
+ });
1757
+ }
1758
+ addCustomerToStockNotification(shop, productId, name, email) {
1759
+ return __awaiter(this, void 0, void 0, function* () {
1760
+ return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1761
+ });
1762
+ }
1763
+ findCatalog(options, limits) {
1764
+ var _a;
1765
+ return __awaiter(this, void 0, void 0, function* () {
1766
+ if (this.hasTerm(options) && options.sort === 'most-relevant') {
1767
+ const productsIds = yield this.findCatalogIdsByElasticSearch(options.term);
1768
+ return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1769
+ }
1770
+ if (this.hasCategory(options) && options.sort === 'most-relevant') {
1771
+ const mostRelevant = (_a = options.category.getMostRelevantByShop(this.shop)) !== null && _a !== void 0 ? _a : [];
1772
+ const productsIds = yield this.productRepository
1773
+ .findCatalog({
1774
+ fields: ['id'],
1775
+ filters: Object.assign(Object.assign({}, (yield this.buildMainFilter(options))), this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1776
+ })
1777
+ .then((products) => products.data.map((product) => product.id));
1778
+ return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
1779
+ }
1780
+ 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'] } : {})) });
1781
+ if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1782
+ return this.productRepository.findCatalog(repoParams);
1783
+ return this.productRepository.findCatalog(repoParams, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1784
+ });
1785
+ }
1786
+ buildMainFilter({ category, profile, term, }) {
1787
+ return __awaiter(this, void 0, void 0, function* () {
1788
+ if (category)
1789
+ return this.categoryStructureAdapter.buildProductFilterByCategory(category);
1790
+ if (profile)
1791
+ return { tags: { operator: Where.LIKE, value: profile } };
1792
+ if (term)
1793
+ return this.productIndex
1794
+ .search(term, 999, this.shop)
1795
+ .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1796
+ });
1797
+ }
1798
+ findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1799
+ return __awaiter(this, void 0, void 0, function* () {
1800
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1801
+ const totalResult = yield this.productRepository.findCatalog({
1802
+ filters: Object.assign({ id: { operator: Where.IN, value: mostRelevantProductsIds } }, this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1803
+ orderBy: this.buildSortQuery('news'),
1804
+ options: {
1805
+ minimal: ['price'],
1806
+ maximum: ['price'],
1807
+ distinct: ['brand'],
1808
+ },
1809
+ }, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1810
+ const firstProducts = totalResult.data.filter((product) => mostRelevants.includes(product.id));
1811
+ const lastProducts = totalResult.data.filter((product) => !mostRelevants.includes(product.id));
1812
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
1813
+ const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1814
+ return {
1815
+ data: resultFinal,
1816
+ count: totalResult.count,
1817
+ maximum: totalResult.maximum,
1818
+ minimal: totalResult.minimal,
1819
+ distinct: totalResult.distinct,
1820
+ };
1821
+ });
1822
+ }
1823
+ findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1824
+ return __awaiter(this, void 0, void 0, function* () {
1825
+ const totalResult = yield this.productRepository.findCatalog({
1826
+ fields: ['id', 'stock'],
1827
+ filters: Object.assign({ id: { operator: Where.IN, value: productIds } }, this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1828
+ options: {
1829
+ minimal: ['price'],
1830
+ maximum: ['price'],
1831
+ distinct: ['brand'],
1832
+ },
1833
+ }, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1834
+ const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1835
+ const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1836
+ const productIdsStock = productIds.filter((product) => stockData.some((result) => result.id == product));
1837
+ const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id == product));
1838
+ const limitedProductId = productIdsStock
1839
+ .concat(productIdsStockOut)
1840
+ .slice(limits.offset, limits.offset + limits.limit);
1841
+ const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1842
+ const productResult = yield this.productRepository.findCatalog({
1843
+ filters: {
1844
+ id: { operator: Where.IN, value: orderedId },
1845
+ },
1846
+ });
1847
+ return {
1848
+ data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1849
+ count: totalResult.count,
1850
+ maximum: totalResult.maximum,
1851
+ minimal: totalResult.minimal,
1852
+ distinct: totalResult.distinct,
1853
+ };
1854
+ });
1855
+ }
1856
+ findCatalogIdsByElasticSearch(term) {
1857
+ return __awaiter(this, void 0, void 0, function* () {
1858
+ if (this.productsByTerm[term])
1859
+ return this.productsByTerm[term];
1860
+ return (this.productsByTerm[term] = yield this.productIndex
1861
+ .search(term, 999, this.shop)
1862
+ .then(({ hits: products }) => {
1863
+ const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
1864
+ const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
1865
+ const sorted = [...withStock, ...withOutStock];
1866
+ return [...new Set(sorted.map(({ _source }) => _source.id))];
1867
+ }));
1868
+ });
1869
+ }
1870
+ }
1871
+ 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 });
1872
+ CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1873
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1874
+ type: Injectable
1875
+ }], ctorParameters: function () {
1876
+ return [{ type: undefined, decorators: [{
1877
+ type: Inject,
1878
+ args: ['ProductRepository']
1879
+ }] }, { type: undefined, decorators: [{
1880
+ type: Inject,
1881
+ args: ['ProductStockNotificationRepository']
1882
+ }] }, { type: undefined, decorators: [{
1883
+ type: Inject,
1884
+ args: ['CategoryRepository']
1885
+ }] }, { type: undefined, decorators: [{
1886
+ type: Inject,
1887
+ args: [CATEGORY_STRUCTURE]
1888
+ }] }, { type: i1$2.Shops, decorators: [{
1889
+ type: Inject,
1890
+ args: [DEFAULT_SHOP]
1891
+ }] }, { type: i1$2.ProductsIndex }];
1892
1892
  } });
1893
1893
 
1894
- class CategoryService {
1895
- constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1896
- this.productRepository = productRepository;
1897
- this.categoryRepository = categoryRepository;
1898
- this.categoryFilterRepository = categoryFilterRepository;
1899
- this.categoryStructureAdapter = categoryStructureAdapter;
1900
- this.shop = shop;
1901
- }
1902
- fetchBrands(category, options) {
1903
- return __awaiter(this, void 0, void 0, function* () {
1904
- const brands = yield this.productRepository
1905
- .findCatalog({
1906
- filters: yield this.categoryStructureAdapter.buildProductFilterByCategory(category),
1907
- fields: ['brand'],
1908
- }, (options === null || options === void 0 ? void 0 : options.mainGender) ? options === null || options === void 0 ? void 0 : options.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female')
1909
- .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => (Object.assign(Object.assign({}, brands), { [brand]: true })), {})));
1910
- return this.categoryRepository
1911
- .find({ filters: { brandCategory: true, shop: (options === null || options === void 0 ? void 0 : options.shop) || this.shop }, orderBy: { name: 'asc' } })
1912
- .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1913
- });
1914
- }
1915
- fetchFilterOptions(category) {
1916
- return __awaiter(this, void 0, void 0, function* () {
1917
- return yield this.categoryFilterRepository
1918
- .find({ filters: { categoryId: +category.id } })
1919
- .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1920
- });
1921
- }
1922
- }
1923
- 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 });
1924
- CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1925
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1926
- type: Injectable
1927
- }], ctorParameters: function () {
1928
- return [{ type: undefined, decorators: [{
1929
- type: Inject,
1930
- args: ['ProductRepository']
1931
- }] }, { type: undefined, decorators: [{
1932
- type: Inject,
1933
- args: ['CategoryRepository']
1934
- }] }, { type: undefined, decorators: [{
1935
- type: Inject,
1936
- args: ['CategoryFilterRepository']
1937
- }] }, { type: undefined, decorators: [{
1938
- type: Inject,
1939
- args: [CATEGORY_STRUCTURE]
1940
- }] }, { type: i1$2.Shops, decorators: [{
1941
- type: Inject,
1942
- args: [DEFAULT_SHOP]
1943
- }] }];
1894
+ class CategoryService {
1895
+ constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1896
+ this.productRepository = productRepository;
1897
+ this.categoryRepository = categoryRepository;
1898
+ this.categoryFilterRepository = categoryFilterRepository;
1899
+ this.categoryStructureAdapter = categoryStructureAdapter;
1900
+ this.shop = shop;
1901
+ }
1902
+ fetchBrands(category, options) {
1903
+ return __awaiter(this, void 0, void 0, function* () {
1904
+ const brands = yield this.productRepository
1905
+ .findCatalog({
1906
+ filters: yield this.categoryStructureAdapter.buildProductFilterByCategory(category),
1907
+ fields: ['brand'],
1908
+ }, (options === null || options === void 0 ? void 0 : options.mainGender) ? options === null || options === void 0 ? void 0 : options.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female')
1909
+ .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => (Object.assign(Object.assign({}, brands), { [brand]: true })), {})));
1910
+ return this.categoryRepository
1911
+ .find({ filters: { brandCategory: true, shop: (options === null || options === void 0 ? void 0 : options.shop) || this.shop }, orderBy: { name: 'asc' } })
1912
+ .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1913
+ });
1914
+ }
1915
+ fetchFilterOptions(category) {
1916
+ return __awaiter(this, void 0, void 0, function* () {
1917
+ return yield this.categoryFilterRepository
1918
+ .find({ filters: { categoryId: +category.id } })
1919
+ .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1920
+ });
1921
+ }
1922
+ }
1923
+ 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 });
1924
+ CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1925
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1926
+ type: Injectable
1927
+ }], ctorParameters: function () {
1928
+ return [{ type: undefined, decorators: [{
1929
+ type: Inject,
1930
+ args: ['ProductRepository']
1931
+ }] }, { type: undefined, decorators: [{
1932
+ type: Inject,
1933
+ args: ['CategoryRepository']
1934
+ }] }, { type: undefined, decorators: [{
1935
+ type: Inject,
1936
+ args: ['CategoryFilterRepository']
1937
+ }] }, { type: undefined, decorators: [{
1938
+ type: Inject,
1939
+ args: [CATEGORY_STRUCTURE]
1940
+ }] }, { type: i1$2.Shops, decorators: [{
1941
+ type: Inject,
1942
+ args: [DEFAULT_SHOP]
1943
+ }] }];
1944
1944
  } });
1945
1945
 
1946
- var ProductSorts;
1947
- (function (ProductSorts) {
1948
- ProductSorts["MOST_RELEVANT"] = "most-relevant";
1949
- ProductSorts["BEST_SELLER"] = "best-sellers";
1950
- ProductSorts["BIGGEST_PRICE"] = "biggest-price";
1951
- ProductSorts["LOWEST_PRICE"] = "lowest-price";
1952
- ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1953
- ProductSorts["BEST_RATING"] = "best-rating";
1954
- ProductSorts["NEWS"] = "news";
1946
+ var ProductSorts;
1947
+ (function (ProductSorts) {
1948
+ ProductSorts["MOST_RELEVANT"] = "most-relevant";
1949
+ ProductSorts["BEST_SELLER"] = "best-sellers";
1950
+ ProductSorts["BIGGEST_PRICE"] = "biggest-price";
1951
+ ProductSorts["LOWEST_PRICE"] = "lowest-price";
1952
+ ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1953
+ ProductSorts["BEST_RATING"] = "best-rating";
1954
+ ProductSorts["NEWS"] = "news";
1955
1955
  })(ProductSorts || (ProductSorts = {}));
1956
1956
 
1957
- class CategoryWithTree extends Category {
1958
- }
1959
- __decorate([
1960
- Type(() => CategoryWithTree),
1961
- __metadata("design:type", Array)
1957
+ class CategoryWithTree extends Category {
1958
+ }
1959
+ __decorate([
1960
+ Type(() => CategoryWithTree),
1961
+ __metadata("design:type", Array)
1962
1962
  ], CategoryWithTree.prototype, "children", void 0);
1963
1963
 
1964
- class WishlistService {
1965
- constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productIndex) {
1966
- this.wishlistRepository = wishlistRepository;
1967
- this.shop = shop;
1968
- const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1969
- this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
1970
- this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1971
- }
1972
- getCatalogService() {
1973
- return this.catalogService;
1974
- }
1975
- getCategoryService() {
1976
- return this.categoryService;
1977
- }
1978
- create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1979
- return __awaiter(this, void 0, void 0, function* () {
1980
- const data = {
1981
- slug: '',
1982
- name: title,
1983
- description,
1984
- metadata: {
1985
- title: `${userFullName} - ${title}`,
1986
- description: `${userFullName} - ${description}`,
1987
- },
1988
- shop: this.shop,
1989
- shops: [this.shop],
1990
- personId,
1991
- personName: userFullName,
1992
- personPhoto: userPhoto,
1993
- brandCategory: false,
1994
- published,
1995
- theme,
1996
- bannerUrl,
1997
- personType: personType !== null && personType !== void 0 ? personType : PersonTypes.NONE,
1998
- personIsSubscriber: personIsSubscriber !== null && personIsSubscriber !== void 0 ? personIsSubscriber : false,
1999
- };
2000
- const newWishlist = yield this.wishlistRepository.create(data);
2001
- yield this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
2002
- return Wishlist.toInstance(Object.assign(Object.assign({}, newWishlist.toPlain()), { slug: newWishlist.id }));
2003
- });
2004
- }
2005
- update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
2006
- const data = {
2007
- id,
2008
- name: title,
2009
- description,
2010
- published,
2011
- metadata: {
2012
- title: `${userFullName} - ${title}`,
2013
- description: `${userFullName} - ${description}`,
2014
- },
2015
- personName: userFullName,
2016
- personPhoto: userPhoto,
2017
- theme,
2018
- bannerUrl,
2019
- personType: personType !== null && personType !== void 0 ? personType : PersonTypes.NONE,
2020
- personIsSubscriber: personIsSubscriber !== null && personIsSubscriber !== void 0 ? personIsSubscriber : false,
2021
- };
2022
- return this.wishlistRepository.update(data);
2023
- }
2024
- delete(wishlistId) {
2025
- return this.wishlistRepository.delete({ id: wishlistId });
2026
- }
2027
- getWishlistBySlug(slug) {
2028
- const [id] = slug.split('-');
2029
- if (+id)
2030
- return this.wishlistRepository.get({ id });
2031
- return this.wishlistRepository.getWishlistBySlug(slug);
2032
- }
2033
- getWishlistsByPerson(personId) {
2034
- return this.wishlistRepository.getWishlistByPerson(personId);
2035
- }
2036
- addProduct(wishlistId, productId) {
2037
- return __awaiter(this, void 0, void 0, function* () {
2038
- const wishlist = yield this.wishlistRepository.get({ id: wishlistId });
2039
- const hasProduct = wishlist.products.some((p) => p == productId);
2040
- if (!hasProduct) {
2041
- wishlist.products = [...wishlist.products, productId];
2042
- return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
2043
- }
2044
- return wishlist;
2045
- });
2046
- }
2047
- removeProduct(wishlistId, productId) {
2048
- return __awaiter(this, void 0, void 0, function* () {
2049
- const wishlist = yield this.wishlistRepository.get({ id: wishlistId });
2050
- const productIndex = wishlist.products.findIndex((p) => p == productId);
2051
- if (productIndex != -1) {
2052
- wishlist.products.splice(productIndex, 1);
2053
- if (!wishlist.products.length)
2054
- return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
2055
- return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
2056
- }
2057
- return wishlist;
2058
- });
2059
- }
2060
- }
2061
- 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 });
2062
- WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
2063
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
2064
- type: Injectable
2065
- }], ctorParameters: function () {
2066
- return [{ type: undefined, decorators: [{
2067
- type: Inject,
2068
- args: ['WishlistRepository']
2069
- }] }, { type: i1$2.Shops, decorators: [{
2070
- type: Inject,
2071
- args: [DEFAULT_SHOP]
2072
- }] }, { type: undefined, decorators: [{
2073
- type: Inject,
2074
- args: ['ProductRepository']
2075
- }] }, { type: undefined, decorators: [{
2076
- type: Inject,
2077
- args: ['CategoryFilterRepository']
2078
- }] }, { type: undefined, decorators: [{
2079
- type: Inject,
2080
- args: ['CategoryRepository']
2081
- }] }, { type: undefined, decorators: [{
2082
- type: Inject,
2083
- args: ['ProductStockNotificationRepository']
2084
- }] }, { type: i1$2.ProductsIndex }];
1964
+ class WishlistService {
1965
+ constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productIndex) {
1966
+ this.wishlistRepository = wishlistRepository;
1967
+ this.shop = shop;
1968
+ const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1969
+ this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
1970
+ this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1971
+ }
1972
+ getCatalogService() {
1973
+ return this.catalogService;
1974
+ }
1975
+ getCategoryService() {
1976
+ return this.categoryService;
1977
+ }
1978
+ create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1979
+ return __awaiter(this, void 0, void 0, function* () {
1980
+ const data = {
1981
+ slug: '',
1982
+ name: title,
1983
+ description,
1984
+ metadata: [
1985
+ {
1986
+ shop: this.shop,
1987
+ title: `${userFullName} - ${title}`,
1988
+ description: `${userFullName} - ${description}`,
1989
+ },
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
+ personType: personType !== null && personType !== void 0 ? personType : PersonTypes.NONE,
2001
+ personIsSubscriber: personIsSubscriber !== null && personIsSubscriber !== void 0 ? personIsSubscriber : false,
2002
+ };
2003
+ const newWishlist = yield this.wishlistRepository.create(data);
2004
+ yield this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
2005
+ return Wishlist.toInstance(Object.assign(Object.assign({}, newWishlist.toPlain()), { slug: newWishlist.id }));
2006
+ });
2007
+ }
2008
+ update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
2009
+ const data = {
2010
+ id,
2011
+ name: title,
2012
+ description,
2013
+ published,
2014
+ metadata: [
2015
+ {
2016
+ shop: this.shop,
2017
+ title: `${userFullName} - ${title}`,
2018
+ description: `${userFullName} - ${description}`,
2019
+ },
2020
+ ],
2021
+ personName: userFullName,
2022
+ personPhoto: userPhoto,
2023
+ theme,
2024
+ bannerUrl,
2025
+ personType: personType !== null && personType !== void 0 ? personType : PersonTypes.NONE,
2026
+ personIsSubscriber: personIsSubscriber !== null && personIsSubscriber !== void 0 ? personIsSubscriber : false,
2027
+ };
2028
+ return this.wishlistRepository.update(data);
2029
+ }
2030
+ delete(wishlistId) {
2031
+ return this.wishlistRepository.delete({ id: wishlistId });
2032
+ }
2033
+ getWishlistBySlug(slug) {
2034
+ const [id] = slug.split('-');
2035
+ if (+id)
2036
+ return this.wishlistRepository.get({ id });
2037
+ return this.wishlistRepository.getWishlistBySlug(slug);
2038
+ }
2039
+ getWishlistsByPerson(personId) {
2040
+ return this.wishlistRepository.getWishlistByPerson(personId);
2041
+ }
2042
+ addProduct(wishlistId, productId) {
2043
+ return __awaiter(this, void 0, void 0, function* () {
2044
+ const wishlist = yield this.wishlistRepository.get({ id: wishlistId });
2045
+ const hasProduct = wishlist.products.some((p) => p == productId);
2046
+ if (!hasProduct) {
2047
+ wishlist.products = [...wishlist.products, productId];
2048
+ return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
2049
+ }
2050
+ return wishlist;
2051
+ });
2052
+ }
2053
+ removeProduct(wishlistId, productId) {
2054
+ return __awaiter(this, void 0, void 0, function* () {
2055
+ const wishlist = yield this.wishlistRepository.get({ id: wishlistId });
2056
+ const productIndex = wishlist.products.findIndex((p) => p == productId);
2057
+ if (productIndex != -1) {
2058
+ wishlist.products.splice(productIndex, 1);
2059
+ if (!wishlist.products.length)
2060
+ return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
2061
+ return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
2062
+ }
2063
+ return wishlist;
2064
+ });
2065
+ }
2066
+ }
2067
+ 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 });
2068
+ WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
2069
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
2070
+ type: Injectable
2071
+ }], ctorParameters: function () {
2072
+ return [{ type: undefined, decorators: [{
2073
+ type: Inject,
2074
+ args: ['WishlistRepository']
2075
+ }] }, { type: i1$2.Shops, decorators: [{
2076
+ type: Inject,
2077
+ args: [DEFAULT_SHOP]
2078
+ }] }, { type: undefined, decorators: [{
2079
+ type: Inject,
2080
+ args: ['ProductRepository']
2081
+ }] }, { type: undefined, decorators: [{
2082
+ type: Inject,
2083
+ args: ['CategoryFilterRepository']
2084
+ }] }, { type: undefined, decorators: [{
2085
+ type: Inject,
2086
+ args: ['CategoryRepository']
2087
+ }] }, { type: undefined, decorators: [{
2088
+ type: Inject,
2089
+ args: ['ProductStockNotificationRepository']
2090
+ }] }, { type: i1$2.ProductsIndex }];
2085
2091
  } });
2086
2092
 
2087
- class CheckoutSubscriptionService {
2088
- constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
2089
- this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
2090
- this.dataPersistence = dataPersistence;
2091
- this.couponService = couponService;
2092
- }
2093
- getCheckoutSubscription(checkoutData) {
2094
- return this.dataPersistence
2095
- .get('checkoutSubscriptionId')
2096
- .pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
2097
- }
2098
- clearCheckoutSubscriptionFromSession() {
2099
- return this.dataPersistence.remove('checkoutSubscriptionId');
2100
- }
2101
- checkCoupon(nickname, userEmail) {
2102
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
2103
- .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
2104
- .pipe()));
2105
- }
2106
- calcDiscountSubscription(coupon) {
2107
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
2108
- }
2109
- createCheckoutSubscription(checkoutData) {
2110
- return __awaiter(this, void 0, void 0, function* () {
2111
- const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
2112
- yield this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
2113
- return checkout;
2114
- });
2115
- }
2116
- }
2117
- 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 });
2118
- CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
2119
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
2120
- type: Injectable
2121
- }], ctorParameters: function () {
2122
- return [{ type: undefined, decorators: [{
2123
- type: Inject,
2124
- args: ['CheckoutSubscriptionRepository']
2125
- }] }, { type: undefined, decorators: [{
2126
- type: Inject,
2127
- args: [PERSISTENCE_PROVIDER]
2128
- }] }, { type: CouponService }];
2093
+ class CheckoutSubscriptionService {
2094
+ constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
2095
+ this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
2096
+ this.dataPersistence = dataPersistence;
2097
+ this.couponService = couponService;
2098
+ }
2099
+ getCheckoutSubscription(checkoutData) {
2100
+ return this.dataPersistence
2101
+ .get('checkoutSubscriptionId')
2102
+ .pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
2103
+ }
2104
+ clearCheckoutSubscriptionFromSession() {
2105
+ return this.dataPersistence.remove('checkoutSubscriptionId');
2106
+ }
2107
+ checkCoupon(nickname, userEmail) {
2108
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
2109
+ .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
2110
+ .pipe()));
2111
+ }
2112
+ calcDiscountSubscription(coupon) {
2113
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
2114
+ }
2115
+ createCheckoutSubscription(checkoutData) {
2116
+ return __awaiter(this, void 0, void 0, function* () {
2117
+ const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
2118
+ yield this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
2119
+ return checkout;
2120
+ });
2121
+ }
2122
+ }
2123
+ 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 });
2124
+ CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
2125
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
2126
+ type: Injectable
2127
+ }], ctorParameters: function () {
2128
+ return [{ type: undefined, decorators: [{
2129
+ type: Inject,
2130
+ args: ['CheckoutSubscriptionRepository']
2131
+ }] }, { type: undefined, decorators: [{
2132
+ type: Inject,
2133
+ args: [PERSISTENCE_PROVIDER]
2134
+ }] }, { type: CouponService }];
2129
2135
  } });
2130
2136
 
2131
- class UtilHelper {
2132
- static createSlug(name) {
2133
- return name
2134
- .toLowerCase()
2135
- .replace(/\s+/g, '-') // Replace spaces with -
2136
- .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
2137
- .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
2138
- .replace(/[ìíïî]/g, 'i') // Replace spaces with -
2139
- .replace(/[õòóöô]/g, 'o') // Replace spaces with -
2140
- .replace(/[ùúüû]/g, 'u') // Replace spaces with -
2141
- .replace(/[ñ]/g, 'n') // Replace spaces with -
2142
- .replace(/[ç]/g, 'c') // Replace spaces with -
2143
- .replace(/[&]/g, 'and') // Replace spaces with -
2144
- .replace(/[^\w\-]+/g, '') // Remove all non-word chars
2145
- .replace(/\-\-+/g, '-'); // Replace multiple - with single -
2146
- }
2137
+ class UtilHelper {
2138
+ static createSlug(name) {
2139
+ return name
2140
+ .toLowerCase()
2141
+ .replace(/\s+/g, '-') // Replace spaces with -
2142
+ .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
2143
+ .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
2144
+ .replace(/[ìíïî]/g, 'i') // Replace spaces with -
2145
+ .replace(/[õòóöô]/g, 'o') // Replace spaces with -
2146
+ .replace(/[ùúüû]/g, 'u') // Replace spaces with -
2147
+ .replace(/[ñ]/g, 'n') // Replace spaces with -
2148
+ .replace(/[ç]/g, 'c') // Replace spaces with -
2149
+ .replace(/[&]/g, 'and') // Replace spaces with -
2150
+ .replace(/[^\w\-]+/g, '') // Remove all non-word chars
2151
+ .replace(/\-\-+/g, '-'); // Replace multiple - with single -
2152
+ }
2147
2153
  }
2148
2154
 
2149
- class HomeShopService {
2150
- get homeId() {
2151
- if (this.defaultShop === Shops.GLAMSHOP)
2152
- return 'glamshop';
2153
- if (this.defaultShop === Shops.MENSMARKET)
2154
- return 'mens_market';
2155
- return null;
2156
- }
2157
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
2158
- this.categoryRepository = categoryRepository;
2159
- this.homeRepository = homeRepository;
2160
- this.productRepository = productRepository;
2161
- this.defaultShop = defaultShop;
2162
- this.buildCategoryGroupWithRequiredData = (group) => {
2163
- var _a, _b;
2164
- return ({
2165
- 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'])),
2166
- 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()) || {}, [
2167
- 'id',
2168
- 'price',
2169
- 'reviews',
2170
- 'hasVariants',
2171
- 'slug',
2172
- 'sku',
2173
- 'stock',
2174
- 'costPrice',
2175
- 'images',
2176
- 'miniatures',
2177
- 'name',
2178
- 'weight',
2179
- 'rate',
2180
- 'type',
2181
- 'brand',
2182
- ])))) || [],
2183
- });
2184
- };
2185
- }
2186
- getHomeData() {
2187
- 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
2188
- ? of(home)
2189
- : forkJoin([
2190
- this.getDiscoverProducts(this.gender),
2191
- this.getFeaturedProducts(this.gender),
2192
- this.getVerticalProducts(this.gender),
2193
- ]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
2194
- discoverProducts,
2195
- featuredProducts,
2196
- verticalProducts,
2197
- })), concatMap((data) => this.saveHomeData(data)))));
2198
- }
2199
- getBanners(type) {
2200
- return this.getHomeConfiguration().pipe(map((home) => {
2201
- if (type === 'brand')
2202
- return home.brandsCarousel;
2203
- if (type === 'buyToWin')
2204
- return [home.buyToWinBanner];
2205
- if (type === 'block')
2206
- return home.blockBanners;
2207
- if (type === 'blog')
2208
- return [home.blogBanner];
2209
- return [];
2210
- }));
2211
- }
2212
- getMinValueForFreeShipping() {
2213
- return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
2214
- }
2215
- getDiscoverProducts(gender) {
2216
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2217
- }
2218
- getFeaturedProducts(gender) {
2219
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2220
- }
2221
- getVerticalProducts(gender) {
2222
- 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({
2223
- filters: Object.assign({ categories: { operator: Where.IN, value: [category.id] } }, (gender ? { tags: { operator: Where.IN, value: [gender] } } : {})),
2224
- limits: { limit: 12 },
2225
- })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
2226
- }
2227
- getHomeConfiguration() {
2228
- return of(this.homeConfiguration).pipe(concatMap((home) => home
2229
- ? of(home)
2230
- : !this.homeId
2231
- ? throwError(new RequiredArgumentError(['homeId']))
2232
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
2233
- }
2234
- saveHomeData(homeData) {
2235
- const data = {
2236
- createdAt: new Date(),
2237
- expiresAt: add(new Date(), { hours: 1 }),
2238
- data: homeData,
2239
- };
2240
- return from(this.homeRepository.update({
2241
- id: this.homeId,
2242
- data,
2243
- })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
2244
- }
2245
- get gender() {
2246
- return this.homeId === 'mens_market' ? 'masculino' : undefined;
2247
- }
2248
- }
2249
- 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 });
2250
- HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
2251
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
2252
- type: Injectable
2253
- }], ctorParameters: function () {
2254
- return [{ type: undefined, decorators: [{
2255
- type: Inject,
2256
- args: ['CategoryRepository']
2257
- }] }, { type: undefined, decorators: [{
2258
- type: Inject,
2259
- args: ['HomeRepository']
2260
- }] }, { type: undefined, decorators: [{
2261
- type: Inject,
2262
- args: ['ProductRepository']
2263
- }] }, { type: i1$2.Shops, decorators: [{
2264
- type: Inject,
2265
- args: [DEFAULT_SHOP]
2266
- }] }];
2155
+ class HomeShopService {
2156
+ get homeId() {
2157
+ if (this.defaultShop === Shops.GLAMSHOP)
2158
+ return 'glamshop';
2159
+ if (this.defaultShop === Shops.MENSMARKET)
2160
+ return 'mens_market';
2161
+ return null;
2162
+ }
2163
+ constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
2164
+ this.categoryRepository = categoryRepository;
2165
+ this.homeRepository = homeRepository;
2166
+ this.productRepository = productRepository;
2167
+ this.defaultShop = defaultShop;
2168
+ this.buildCategoryGroupWithRequiredData = (group) => {
2169
+ var _a, _b;
2170
+ return ({
2171
+ 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'])),
2172
+ 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()) || {}, [
2173
+ 'id',
2174
+ 'price',
2175
+ 'reviews',
2176
+ 'hasVariants',
2177
+ 'slug',
2178
+ 'sku',
2179
+ 'stock',
2180
+ 'costPrice',
2181
+ 'images',
2182
+ 'miniatures',
2183
+ 'name',
2184
+ 'weight',
2185
+ 'rate',
2186
+ 'type',
2187
+ 'brand',
2188
+ ])))) || [],
2189
+ });
2190
+ };
2191
+ }
2192
+ getHomeData() {
2193
+ 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
2194
+ ? of(home)
2195
+ : forkJoin([
2196
+ this.getDiscoverProducts(this.gender),
2197
+ this.getFeaturedProducts(this.gender),
2198
+ this.getVerticalProducts(this.gender),
2199
+ ]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
2200
+ discoverProducts,
2201
+ featuredProducts,
2202
+ verticalProducts,
2203
+ })), concatMap((data) => this.saveHomeData(data)))));
2204
+ }
2205
+ getBanners(type) {
2206
+ return this.getHomeConfiguration().pipe(map((home) => {
2207
+ if (type === 'brand')
2208
+ return home.brandsCarousel;
2209
+ if (type === 'buyToWin')
2210
+ return [home.buyToWinBanner];
2211
+ if (type === 'block')
2212
+ return home.blockBanners;
2213
+ if (type === 'blog')
2214
+ return [home.blogBanner];
2215
+ return [];
2216
+ }));
2217
+ }
2218
+ getMinValueForFreeShipping() {
2219
+ return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
2220
+ }
2221
+ getDiscoverProducts(gender) {
2222
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2223
+ }
2224
+ getFeaturedProducts(gender) {
2225
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2226
+ }
2227
+ getVerticalProducts(gender) {
2228
+ 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({
2229
+ filters: Object.assign({ categories: { operator: Where.IN, value: [category.id] } }, (gender ? { tags: { operator: Where.IN, value: [gender] } } : {})),
2230
+ limits: { limit: 12 },
2231
+ })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
2232
+ }
2233
+ getHomeConfiguration() {
2234
+ return of(this.homeConfiguration).pipe(concatMap((home) => home
2235
+ ? of(home)
2236
+ : !this.homeId
2237
+ ? throwError(new RequiredArgumentError(['homeId']))
2238
+ : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
2239
+ }
2240
+ saveHomeData(homeData) {
2241
+ const data = {
2242
+ createdAt: new Date(),
2243
+ expiresAt: add(new Date(), { hours: 1 }),
2244
+ data: homeData,
2245
+ };
2246
+ return from(this.homeRepository.update({
2247
+ id: this.homeId,
2248
+ data,
2249
+ })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
2250
+ }
2251
+ get gender() {
2252
+ return this.homeId === 'mens_market' ? 'masculino' : undefined;
2253
+ }
2254
+ }
2255
+ 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 });
2256
+ HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
2257
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
2258
+ type: Injectable
2259
+ }], ctorParameters: function () {
2260
+ return [{ type: undefined, decorators: [{
2261
+ type: Inject,
2262
+ args: ['CategoryRepository']
2263
+ }] }, { type: undefined, decorators: [{
2264
+ type: Inject,
2265
+ args: ['HomeRepository']
2266
+ }] }, { type: undefined, decorators: [{
2267
+ type: Inject,
2268
+ args: ['ProductRepository']
2269
+ }] }, { type: i1$2.Shops, decorators: [{
2270
+ type: Inject,
2271
+ args: [DEFAULT_SHOP]
2272
+ }] }];
2267
2273
  } });
2268
2274
 
2269
- class OrderService {
2270
- constructor(angularFirestore, orderRepository) {
2271
- this.angularFirestore = angularFirestore;
2272
- this.orderRepository = orderRepository;
2273
- this.orderSubject = new Subject();
2274
- }
2275
- getOrder(id) {
2276
- docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
2277
- .pipe(map((doc) => Order.toInstance(doc.data())))
2278
- .subscribe((doc) => this.orderSubject.next(doc));
2279
- return this.orderSubject;
2280
- }
2281
- }
2282
- 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 });
2283
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
2284
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
2285
- type: Injectable
2286
- }], ctorParameters: function () {
2287
- return [{ type: i1$1.Firestore }, { type: i1$2.OrderFirestoreRepository, decorators: [{
2288
- type: Inject,
2289
- args: ['OrderRepository']
2290
- }] }];
2275
+ class OrderService {
2276
+ constructor(angularFirestore, orderRepository) {
2277
+ this.angularFirestore = angularFirestore;
2278
+ this.orderRepository = orderRepository;
2279
+ this.orderSubject = new Subject();
2280
+ }
2281
+ getOrder(id) {
2282
+ docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
2283
+ .pipe(map((doc) => Order.toInstance(doc.data())))
2284
+ .subscribe((doc) => this.orderSubject.next(doc));
2285
+ return this.orderSubject;
2286
+ }
2287
+ }
2288
+ 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 });
2289
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
2290
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
2291
+ type: Injectable
2292
+ }], ctorParameters: function () {
2293
+ return [{ type: i1$1.Firestore }, { type: i1$2.OrderFirestoreRepository, decorators: [{
2294
+ type: Inject,
2295
+ args: ['OrderRepository']
2296
+ }] }];
2291
2297
  } });
2292
2298
 
2293
- class ShippingService {
2294
- constructor(http, apiUrl, homeService) {
2295
- this.http = http;
2296
- this.apiUrl = apiUrl;
2297
- this.homeService = homeService;
2298
- }
2299
- getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
2300
- return combineLatest([
2301
- this.homeService.getHomeData(),
2302
- this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
2303
- ]).pipe(map(([datas, shippingMethodsResponse]) => {
2304
- let shippingMethods = shippingMethodsResponse.result;
2305
- if (!shippingMethods.length)
2306
- return [];
2307
- shippingMethods = shippingMethods.map((shippingMethod) => {
2308
- if (shippingMethod.ShippingCompanyName == 'Same Day EG')
2309
- shippingMethod.ShippingCompanyName = 'Same Day';
2310
- return shippingMethod;
2311
- });
2312
- const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
2313
- if (this.isHolidays(datasSameDayNotAvaliable)) {
2314
- shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
2315
- }
2316
- if (totalPrice >= 200) {
2317
- shippingMethods = shippingMethods.map((s) => {
2318
- if (s.serviceName !== 'Same Day')
2319
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
2320
- else
2321
- return s;
2322
- });
2323
- }
2324
- if (shop == Shops.GLAMSHOP)
2325
- return shippingMethods;
2326
- if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
2327
- shippingMethods = shippingMethods.map((s) => {
2328
- if (s.serviceName == 'Same Day')
2329
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
2330
- else
2331
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
2332
- });
2333
- }
2334
- if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
2335
- shippingMethods = shippingMethods.map((s) => {
2336
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
2337
- });
2338
- }
2339
- return shippingMethods;
2340
- }));
2341
- }
2342
- isFreeShippingBySubscription(shop, subscriptionPlan) {
2343
- if (!subscriptionPlan)
2344
- return false;
2345
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
2346
- return true;
2347
- return false;
2348
- }
2349
- isHalfShippingBySubscription(shop, subscriptionPlan) {
2350
- if (!subscriptionPlan)
2351
- return false;
2352
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
2353
- return true;
2354
- }
2355
- return false;
2356
- }
2357
- isHolidays(datas) {
2358
- const today = new Date();
2359
- for (const key in datas) {
2360
- let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
2361
- let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
2362
- if (start > end)
2363
- end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
2364
- if (today >= start && today <= end)
2365
- return true;
2366
- }
2367
- return false;
2368
- }
2369
- }
2370
- 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 });
2371
- ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
2372
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
2373
- type: Injectable
2374
- }], ctorParameters: function () {
2375
- return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
2376
- type: Inject,
2377
- args: [BACKEND_URL]
2378
- }] }, { type: HomeShopService }];
2299
+ class ShippingService {
2300
+ constructor(http, apiUrl, homeService) {
2301
+ this.http = http;
2302
+ this.apiUrl = apiUrl;
2303
+ this.homeService = homeService;
2304
+ }
2305
+ getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
2306
+ return combineLatest([
2307
+ this.homeService.getHomeData(),
2308
+ this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
2309
+ ]).pipe(map(([datas, shippingMethodsResponse]) => {
2310
+ let shippingMethods = shippingMethodsResponse.result;
2311
+ if (!shippingMethods.length)
2312
+ return [];
2313
+ shippingMethods = shippingMethods.map((shippingMethod) => {
2314
+ if (shippingMethod.ShippingCompanyName == 'Same Day EG')
2315
+ shippingMethod.ShippingCompanyName = 'Same Day';
2316
+ return shippingMethod;
2317
+ });
2318
+ const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
2319
+ if (this.isHolidays(datasSameDayNotAvaliable)) {
2320
+ shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
2321
+ }
2322
+ if (totalPrice >= 200) {
2323
+ shippingMethods = shippingMethods.map((s) => {
2324
+ if (s.serviceName !== 'Same Day')
2325
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
2326
+ else
2327
+ return s;
2328
+ });
2329
+ }
2330
+ if (shop == Shops.GLAMSHOP)
2331
+ return shippingMethods;
2332
+ if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
2333
+ shippingMethods = shippingMethods.map((s) => {
2334
+ if (s.serviceName == 'Same Day')
2335
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
2336
+ else
2337
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
2338
+ });
2339
+ }
2340
+ if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
2341
+ shippingMethods = shippingMethods.map((s) => {
2342
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
2343
+ });
2344
+ }
2345
+ return shippingMethods;
2346
+ }));
2347
+ }
2348
+ isFreeShippingBySubscription(shop, subscriptionPlan) {
2349
+ if (!subscriptionPlan)
2350
+ return false;
2351
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
2352
+ return true;
2353
+ return false;
2354
+ }
2355
+ isHalfShippingBySubscription(shop, subscriptionPlan) {
2356
+ if (!subscriptionPlan)
2357
+ return false;
2358
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
2359
+ return true;
2360
+ }
2361
+ return false;
2362
+ }
2363
+ isHolidays(datas) {
2364
+ const today = new Date();
2365
+ for (const key in datas) {
2366
+ let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
2367
+ let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
2368
+ if (start > end)
2369
+ end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
2370
+ if (today >= start && today <= end)
2371
+ return true;
2372
+ }
2373
+ return false;
2374
+ }
2375
+ }
2376
+ 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 });
2377
+ ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
2378
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
2379
+ type: Injectable
2380
+ }], ctorParameters: function () {
2381
+ return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
2382
+ type: Inject,
2383
+ args: [BACKEND_URL]
2384
+ }] }, { type: HomeShopService }];
2379
2385
  } });
2380
2386
 
2381
- class AngularConnectModule {
2382
- static initializeApp(defaultShop, options, nameOrConfig) {
2383
- return {
2384
- ngModule: AngularConnectModule,
2385
- providers: [
2386
- {
2387
- provide: CATEGORY_STRUCTURE,
2388
- useClass: isNil(options === null || options === void 0 ? void 0 : options.oldCategoryStructure) || (options === null || options === void 0 ? void 0 : options.oldCategoryStructure)
2389
- ? OldCategoryStructureAdapter
2390
- : NewCategoryStructureAdapter,
2391
- },
2392
- { provide: PERSISTENCE_PROVIDER, useClass: (options === null || options === void 0 ? void 0 : options.persistenceProvider) || CookieDataPersistence },
2393
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2394
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
2395
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
2396
- ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2397
- ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2398
- ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2399
- ...(isNil(options === null || options === void 0 ? void 0 : options.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
2400
- ],
2401
- };
2402
- }
2403
- }
2404
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2405
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
2406
- AngularFirebaseAuthModule,
2407
- AngularFirestoreModule,
2408
- AngularHasuraGraphQLModule] });
2409
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, providers: [
2410
- AuthService,
2411
- CartService,
2412
- CatalogService,
2413
- CategoryService,
2414
- CheckoutService,
2415
- CheckoutSubscriptionService,
2416
- CouponService,
2417
- HomeShopService,
2418
- OrderService,
2419
- ShippingService,
2420
- WishlistService,
2421
- {
2422
- provide: UpdateUserImage,
2423
- useFactory: (userRepository, fileUploader) => {
2424
- return new UpdateUserImage(userRepository, fileUploader);
2425
- },
2426
- deps: ['UserRepository', 'FileUploaderService'],
2427
- },
2428
- {
2429
- provide: 'FileUploaderService',
2430
- useFactory: (storage, baseUrl) => {
2431
- return new FirebaseFileUploaderService(storage, baseUrl);
2432
- },
2433
- deps: [Storage, STORAGE_BASE_URL],
2434
- },
2435
- ], imports: [provideFirebaseApp((injector) => {
2436
- const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2437
- try {
2438
- return getApp(appName);
2439
- }
2440
- catch (error) {
2441
- return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2442
- }
2443
- }),
2444
- provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2445
- AngularElasticSeachModule,
2446
- AngularFirebaseAuthModule,
2447
- AngularFirestoreModule,
2448
- AngularHasuraGraphQLModule] });
2449
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, decorators: [{
2450
- type: NgModule,
2451
- args: [{
2452
- imports: [
2453
- provideFirebaseApp((injector) => {
2454
- const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2455
- try {
2456
- return getApp(appName);
2457
- }
2458
- catch (error) {
2459
- return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2460
- }
2461
- }),
2462
- provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2463
- AngularElasticSeachModule,
2464
- AngularFirebaseAuthModule,
2465
- AngularFirestoreModule,
2466
- AngularHasuraGraphQLModule,
2467
- ],
2468
- providers: [
2469
- AuthService,
2470
- CartService,
2471
- CatalogService,
2472
- CategoryService,
2473
- CheckoutService,
2474
- CheckoutSubscriptionService,
2475
- CouponService,
2476
- HomeShopService,
2477
- OrderService,
2478
- ShippingService,
2479
- WishlistService,
2480
- {
2481
- provide: UpdateUserImage,
2482
- useFactory: (userRepository, fileUploader) => {
2483
- return new UpdateUserImage(userRepository, fileUploader);
2484
- },
2485
- deps: ['UserRepository', 'FileUploaderService'],
2486
- },
2487
- {
2488
- provide: 'FileUploaderService',
2489
- useFactory: (storage, baseUrl) => {
2490
- return new FirebaseFileUploaderService(storage, baseUrl);
2491
- },
2492
- deps: [Storage, STORAGE_BASE_URL],
2493
- },
2494
- ],
2495
- }]
2387
+ class AngularConnectModule {
2388
+ static initializeApp(defaultShop, options, nameOrConfig) {
2389
+ return {
2390
+ ngModule: AngularConnectModule,
2391
+ providers: [
2392
+ {
2393
+ provide: CATEGORY_STRUCTURE,
2394
+ useClass: isNil(options === null || options === void 0 ? void 0 : options.oldCategoryStructure) || (options === null || options === void 0 ? void 0 : options.oldCategoryStructure)
2395
+ ? OldCategoryStructureAdapter
2396
+ : NewCategoryStructureAdapter,
2397
+ },
2398
+ { provide: PERSISTENCE_PROVIDER, useClass: (options === null || options === void 0 ? void 0 : options.persistenceProvider) || CookieDataPersistence },
2399
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2400
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
2401
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
2402
+ ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2403
+ ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2404
+ ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2405
+ ...(isNil(options === null || options === void 0 ? void 0 : options.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
2406
+ ],
2407
+ };
2408
+ }
2409
+ }
2410
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2411
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
2412
+ AngularFirebaseAuthModule,
2413
+ AngularFirestoreModule,
2414
+ AngularHasuraGraphQLModule] });
2415
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, providers: [
2416
+ AuthService,
2417
+ CartService,
2418
+ CatalogService,
2419
+ CategoryService,
2420
+ CheckoutService,
2421
+ CheckoutSubscriptionService,
2422
+ CouponService,
2423
+ HomeShopService,
2424
+ OrderService,
2425
+ ShippingService,
2426
+ WishlistService,
2427
+ {
2428
+ provide: UpdateUserImage,
2429
+ useFactory: (userRepository, fileUploader) => {
2430
+ return new UpdateUserImage(userRepository, fileUploader);
2431
+ },
2432
+ deps: ['UserRepository', 'FileUploaderService'],
2433
+ },
2434
+ {
2435
+ provide: 'FileUploaderService',
2436
+ useFactory: (storage, baseUrl) => {
2437
+ return new FirebaseFileUploaderService(storage, baseUrl);
2438
+ },
2439
+ deps: [Storage, STORAGE_BASE_URL],
2440
+ },
2441
+ ], imports: [provideFirebaseApp((injector) => {
2442
+ const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2443
+ try {
2444
+ return getApp(appName);
2445
+ }
2446
+ catch (error) {
2447
+ return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2448
+ }
2449
+ }),
2450
+ provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2451
+ AngularElasticSeachModule,
2452
+ AngularFirebaseAuthModule,
2453
+ AngularFirestoreModule,
2454
+ AngularHasuraGraphQLModule] });
2455
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, decorators: [{
2456
+ type: NgModule,
2457
+ args: [{
2458
+ imports: [
2459
+ provideFirebaseApp((injector) => {
2460
+ const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2461
+ try {
2462
+ return getApp(appName);
2463
+ }
2464
+ catch (error) {
2465
+ return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2466
+ }
2467
+ }),
2468
+ provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2469
+ AngularElasticSeachModule,
2470
+ AngularFirebaseAuthModule,
2471
+ AngularFirestoreModule,
2472
+ AngularHasuraGraphQLModule,
2473
+ ],
2474
+ providers: [
2475
+ AuthService,
2476
+ CartService,
2477
+ CatalogService,
2478
+ CategoryService,
2479
+ CheckoutService,
2480
+ CheckoutSubscriptionService,
2481
+ CouponService,
2482
+ HomeShopService,
2483
+ OrderService,
2484
+ ShippingService,
2485
+ WishlistService,
2486
+ {
2487
+ provide: UpdateUserImage,
2488
+ useFactory: (userRepository, fileUploader) => {
2489
+ return new UpdateUserImage(userRepository, fileUploader);
2490
+ },
2491
+ deps: ['UserRepository', 'FileUploaderService'],
2492
+ },
2493
+ {
2494
+ provide: 'FileUploaderService',
2495
+ useFactory: (storage, baseUrl) => {
2496
+ return new FirebaseFileUploaderService(storage, baseUrl);
2497
+ },
2498
+ deps: [Storage, STORAGE_BASE_URL],
2499
+ },
2500
+ ],
2501
+ }]
2496
2502
  }] });
2497
2503
 
2498
- /**
2499
- * Generated bundle index. Do not edit.
2504
+ /**
2505
+ * Generated bundle index. Do not edit.
2500
2506
  */
2501
2507
 
2502
2508
  export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };