@infrab4a/connect-angular 4.4.0-beta4 → 4.4.1-beta.0

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