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

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