@infrab4a/connect-angular 4.21.0 → 4.21.1-alpha.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 (114) hide show
  1. package/angular-connect.module.d.ts +4 -0
  2. package/esm2020/angular-connect.module.mjs +119 -17
  3. package/esm2020/angular-hasura-graphql.module.mjs +1 -1
  4. package/esm2020/consts/backend-url.const.mjs +1 -1
  5. package/esm2020/interfaces/catalog-strategies.interface.mjs +2 -0
  6. package/esm2020/interfaces/category-facades.interface.mjs +2 -0
  7. package/esm2020/interfaces/index.mjs +3 -0
  8. package/esm2020/persistence/cookie-data-persistence.mjs +1 -1
  9. package/esm2020/services/cart/cart-services.facade.mjs +21 -0
  10. package/esm2020/services/cart/index.mjs +2 -0
  11. package/esm2020/services/cart.service.mjs +25 -38
  12. package/esm2020/services/catalog/adapters/new-category-structure.adapter.mjs +1 -1
  13. package/esm2020/services/catalog/adapters/old-category-structure.adapter.mjs +1 -1
  14. package/esm2020/services/catalog/catalog.service.mjs +80 -294
  15. package/esm2020/services/catalog/category.service.mjs +15 -27
  16. package/esm2020/services/catalog/context/catalog-search.context.mjs +40 -0
  17. package/esm2020/services/catalog/facades/catalog-service.facade.mjs +32 -0
  18. package/esm2020/services/catalog/facades/catalog-strategies.facade.mjs +17 -0
  19. package/esm2020/services/catalog/facades/category-repository.facade.mjs +20 -0
  20. package/esm2020/services/catalog/facades/category-service.facade.mjs +30 -0
  21. package/esm2020/services/catalog/facades/index.mjs +6 -0
  22. package/esm2020/services/catalog/facades/product-catalog.facade.mjs +21 -0
  23. package/esm2020/services/catalog/helpers/brand-manager.helper.mjs +57 -0
  24. package/esm2020/services/catalog/helpers/catalog-filter.helper.mjs +44 -0
  25. package/esm2020/services/catalog/helpers/catalog-sort.helper.mjs +52 -0
  26. package/esm2020/services/catalog/helpers/index.mjs +5 -0
  27. package/esm2020/services/catalog/helpers/product-fields.helper.mjs +39 -0
  28. package/esm2020/services/catalog/models/category-with-tree.model.mjs +1 -1
  29. package/esm2020/services/catalog/services/catalog-helpers.service.mjs +33 -0
  30. package/esm2020/services/catalog/services/catalog-operations.facade.mjs +26 -0
  31. package/esm2020/services/catalog/services/catalog-repository.service.mjs +25 -0
  32. package/esm2020/services/catalog/services/index.mjs +5 -0
  33. package/esm2020/services/catalog/services/product-management.facade.mjs +25 -0
  34. package/esm2020/services/catalog/strategies/category-search.strategy.mjs +133 -0
  35. package/esm2020/services/catalog/strategies/index.mjs +4 -0
  36. package/esm2020/services/catalog/strategies/profile-search.strategy.mjs +42 -0
  37. package/esm2020/services/catalog/strategies/term-search.strategy.mjs +126 -0
  38. package/esm2020/services/catalog/strategies/types/strategy-params.type.mjs +2 -0
  39. package/esm2020/services/catalog/types/fetch-products-options.type.mjs +2 -0
  40. package/esm2020/services/catalog/types/fetch-products-params.type.mjs +2 -0
  41. package/esm2020/services/catalog/types/fetch-products-response.type.mjs +2 -0
  42. package/esm2020/services/catalog/types/index.mjs +5 -1
  43. package/esm2020/services/catalog/types/method-params.type.mjs +2 -0
  44. package/esm2020/services/catalog/wishlist.service.mjs +92 -72
  45. package/esm2020/services/checkout/checkout-dependencies.facade.mjs +20 -0
  46. package/esm2020/services/checkout/checkout-repositories.facade.mjs +20 -0
  47. package/esm2020/services/checkout/index.mjs +3 -0
  48. package/esm2020/services/checkout-subscription.service.mjs +8 -3
  49. package/esm2020/services/checkout.service.mjs +34 -50
  50. package/esm2020/services/coupon/coupon-repositories.facade.mjs +24 -0
  51. package/esm2020/services/coupon/index.mjs +2 -0
  52. package/esm2020/services/coupon/types/coupon-params.type.mjs +2 -0
  53. package/esm2020/services/coupon.service.mjs +79 -59
  54. package/esm2020/services/helpers/util.helper.mjs +12 -12
  55. package/esm2020/services/home-shop/home-shop-repositories.facade.mjs +24 -0
  56. package/esm2020/services/home-shop/index.mjs +2 -0
  57. package/esm2020/services/home-shop.service.mjs +27 -33
  58. package/esm2020/services/shared/configuration.facade.mjs +29 -0
  59. package/esm2020/services/shared/index.mjs +2 -0
  60. package/fesm2015/infrab4a-connect-angular.mjs +1287 -566
  61. package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
  62. package/fesm2020/infrab4a-connect-angular.mjs +1207 -533
  63. package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
  64. package/interfaces/catalog-strategies.interface.d.ts +31 -0
  65. package/interfaces/category-facades.interface.d.ts +6 -0
  66. package/interfaces/index.d.ts +2 -0
  67. package/package.json +5 -3
  68. package/services/cart/cart-services.facade.d.ts +12 -0
  69. package/services/cart/index.d.ts +1 -0
  70. package/services/cart.service.d.ts +6 -11
  71. package/services/catalog/catalog.service.d.ts +11 -83
  72. package/services/catalog/category.service.d.ts +5 -7
  73. package/services/catalog/context/catalog-search.context.d.ts +14 -0
  74. package/services/catalog/facades/catalog-service.facade.d.ts +15 -0
  75. package/services/catalog/facades/catalog-strategies.facade.d.ts +10 -0
  76. package/services/catalog/facades/category-repository.facade.d.ts +9 -0
  77. package/services/catalog/facades/category-service.facade.d.ts +15 -0
  78. package/services/catalog/facades/index.d.ts +5 -0
  79. package/services/catalog/facades/product-catalog.facade.d.ts +10 -0
  80. package/services/catalog/helpers/brand-manager.helper.d.ts +14 -0
  81. package/services/catalog/helpers/catalog-filter.helper.d.ts +8 -0
  82. package/services/catalog/helpers/catalog-sort.helper.d.ts +7 -0
  83. package/services/catalog/helpers/index.d.ts +4 -0
  84. package/services/catalog/helpers/product-fields.helper.d.ts +7 -0
  85. package/services/catalog/services/catalog-helpers.service.d.ts +17 -0
  86. package/services/catalog/services/catalog-operations.facade.d.ts +13 -0
  87. package/services/catalog/services/catalog-repository.service.d.ts +12 -0
  88. package/services/catalog/services/index.d.ts +4 -0
  89. package/services/catalog/services/product-management.facade.d.ts +12 -0
  90. package/services/catalog/strategies/category-search.strategy.d.ts +19 -0
  91. package/services/catalog/strategies/index.d.ts +3 -0
  92. package/services/catalog/strategies/profile-search.strategy.d.ts +14 -0
  93. package/services/catalog/strategies/term-search.strategy.d.ts +20 -0
  94. package/services/catalog/strategies/types/strategy-params.type.d.ts +58 -0
  95. package/services/catalog/types/fetch-products-options.type.d.ts +8 -0
  96. package/services/catalog/types/fetch-products-params.type.d.ts +25 -0
  97. package/services/catalog/types/fetch-products-response.type.d.ts +19 -0
  98. package/services/catalog/types/index.d.ts +4 -0
  99. package/services/catalog/types/method-params.type.d.ts +17 -0
  100. package/services/catalog/wishlist.service.d.ts +12 -4
  101. package/services/checkout/checkout-dependencies.facade.d.ts +10 -0
  102. package/services/checkout/checkout-repositories.facade.d.ts +9 -0
  103. package/services/checkout/index.d.ts +2 -0
  104. package/services/checkout-subscription.service.d.ts +2 -2
  105. package/services/checkout.service.d.ts +7 -11
  106. package/services/coupon/coupon-repositories.facade.d.ts +10 -0
  107. package/services/coupon/index.d.ts +1 -0
  108. package/services/coupon/types/coupon-params.type.d.ts +13 -0
  109. package/services/coupon.service.d.ts +16 -7
  110. package/services/home-shop/home-shop-repositories.facade.d.ts +10 -0
  111. package/services/home-shop/index.d.ts +1 -0
  112. package/services/home-shop.service.d.ts +6 -6
  113. package/services/shared/configuration.facade.d.ts +12 -0
  114. package/services/shared/index.d.ts +1 -0
@@ -1,13 +1,13 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angular/core';
3
- import * as i1$4 from '@angular/fire/app';
3
+ import * as i1$3 from '@angular/fire/app';
4
4
  import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
5
5
  import * as i2 from '@angular/fire/app-check';
6
6
  import { provideAppCheck, initializeAppCheck } from '@angular/fire/app-check';
7
- import * as i3 from '@angular/fire/storage';
7
+ import * as i3$1 from '@angular/fire/storage';
8
8
  import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
9
- import * as i1$3 from '@infrab4a/connect';
10
- import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, GroupFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductErrorsHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, isNil, NotFoundError, Checkout, pick, LineItem, Where, set, InvalidArgumentError, RoundProductPricesHelper, isEmpty, Shops, Category, PersonTypes, WishlistLogType, Wishlist, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
9
+ import * as i3 from '@infrab4a/connect';
10
+ import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, GroupFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductErrorsHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, isNil, NotFoundError, Checkout, pick, LineItem, Where, Shops, isEmpty, set, InvalidArgumentError, RoundProductPricesHelper, Category, WishlistLogType, PersonTypes, Wishlist, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
11
11
  import * as i1 from '@angular/fire/auth';
12
12
  import { Auth, provideAuth, initializeAuth, indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence, getAuth, getIdToken, authState } from '@angular/fire/auth';
13
13
  import { isPlatformBrowser, isPlatformServer } from '@angular/common';
@@ -1151,157 +1151,215 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1151
1151
  }] }];
1152
1152
  } });
1153
1153
 
1154
- class CheckoutService {
1155
- constructor(checkoutRepository, userRepository, defaultShop, dataPersistence, firebaseOptions, http) {
1154
+ class CheckoutRepositoriesFacade {
1155
+ constructor(checkoutRepository, userRepository) {
1156
1156
  this.checkoutRepository = checkoutRepository;
1157
1157
  this.userRepository = userRepository;
1158
- this.defaultShop = defaultShop;
1158
+ }
1159
+ }
1160
+ CheckoutRepositoriesFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutRepositoriesFacade, deps: [{ token: 'CheckoutRepository' }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1161
+ CheckoutRepositoriesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutRepositoriesFacade });
1162
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutRepositoriesFacade, decorators: [{
1163
+ type: Injectable
1164
+ }], ctorParameters: function () {
1165
+ return [{ type: undefined, decorators: [{
1166
+ type: Inject,
1167
+ args: ['CheckoutRepository']
1168
+ }] }, { type: undefined, decorators: [{
1169
+ type: Inject,
1170
+ args: ['UserRepository']
1171
+ }] }];
1172
+ } });
1173
+
1174
+ class CheckoutDependenciesFacade {
1175
+ constructor(dataPersistence, httpClient) {
1159
1176
  this.dataPersistence = dataPersistence;
1177
+ this.httpClient = httpClient;
1178
+ }
1179
+ }
1180
+ CheckoutDependenciesFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutDependenciesFacade, deps: [{ token: PERSISTENCE_PROVIDER }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1181
+ CheckoutDependenciesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutDependenciesFacade });
1182
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutDependenciesFacade, decorators: [{
1183
+ type: Injectable
1184
+ }], ctorParameters: function () {
1185
+ return [{ type: undefined, decorators: [{
1186
+ type: Inject,
1187
+ args: [PERSISTENCE_PROVIDER]
1188
+ }] }, { type: i1$2.HttpClient }];
1189
+ } });
1190
+
1191
+ class ConfigurationFacade {
1192
+ constructor(defaultShop, firebaseOptions) {
1193
+ this.defaultShop = defaultShop;
1160
1194
  this.firebaseOptions = firebaseOptions;
1161
- this.http = http;
1195
+ }
1196
+ getCheckoutUrl() {
1197
+ return `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
1198
+ }
1199
+ getProjectId() {
1200
+ return this.firebaseOptions.projectId;
1201
+ }
1202
+ }
1203
+ ConfigurationFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ConfigurationFacade, deps: [{ token: DEFAULT_SHOP }, { token: FIREBASE_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable });
1204
+ ConfigurationFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ConfigurationFacade });
1205
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ConfigurationFacade, decorators: [{
1206
+ type: Injectable
1207
+ }], ctorParameters: function () {
1208
+ return [{ type: i3.Shops, decorators: [{
1209
+ type: Inject,
1210
+ args: [DEFAULT_SHOP]
1211
+ }] }, { type: undefined, decorators: [{
1212
+ type: Inject,
1213
+ args: [FIREBASE_OPTIONS]
1214
+ }] }];
1215
+ } });
1216
+
1217
+ class CheckoutService {
1218
+ constructor(repositoriesFacade, dependenciesFacade, configurationFacade) {
1219
+ this.repositoriesFacade = repositoriesFacade;
1220
+ this.dependenciesFacade = dependenciesFacade;
1221
+ this.configurationFacade = configurationFacade;
1162
1222
  this.checkoutUrl = null;
1163
- this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
1223
+ this.checkoutUrl = this.configurationFacade.getCheckoutUrl();
1164
1224
  }
1165
1225
  getCheckout(checkoutData) {
1166
- return this.dataPersistence
1226
+ return this.dependenciesFacade.dataPersistence
1167
1227
  .get('checkoutId')
1168
- .pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
1228
+ .pipe(concatMap((id) => !isNil(id) ? this.repositoriesFacade.checkoutRepository.get({ id }) : this.createCheckout(checkoutData)));
1169
1229
  }
1170
1230
  getUserByCheckout(checkoutId) {
1171
- return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => { var _a; return ((_a = checkout === null || checkout === void 0 ? void 0 : checkout.user) === null || _a === void 0 ? void 0 : _a.id) ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id })); }), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
1231
+ return from(this.repositoriesFacade.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => {
1232
+ var _a;
1233
+ return ((_a = checkout === null || checkout === void 0 ? void 0 : checkout.user) === null || _a === void 0 ? void 0 : _a.id)
1234
+ ? of(checkout.user)
1235
+ : from(this.repositoriesFacade.userRepository.get({ id: checkout.user.id }));
1236
+ }), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
1172
1237
  }
1173
1238
  updateCheckoutLineItems(checkout) {
1174
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
1239
+ return from(this.repositoriesFacade.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
1175
1240
  }
1176
1241
  updateCheckoutUser(checkout) {
1177
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1242
+ return from(this.repositoriesFacade.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1178
1243
  }
1179
1244
  clearCheckoutFromSession() {
1180
- return this.dataPersistence.remove('checkoutId');
1245
+ return this.dependenciesFacade.dataPersistence.remove('checkoutId');
1181
1246
  }
1182
1247
  resetCheckoutValues() {
1183
- return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutResetValues`, {
1248
+ return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutResetValues`, {
1184
1249
  checkoutId: checkout.id,
1185
1250
  })), concatMap(() => this.getCheckout()));
1186
1251
  }
1187
1252
  applyCouponDiscount(nickname, checkoutType) {
1188
- return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutApplyDiscount`, {
1253
+ return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutApplyDiscount`, {
1189
1254
  checkoutId: checkout.id,
1190
1255
  coupon: nickname,
1191
1256
  checkoutType,
1192
1257
  })), concatMap(() => this.getCheckout()), map((checkout) => checkout.coupon));
1193
1258
  }
1194
1259
  removeCouponDiscount() {
1195
- return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutRemoveDiscount`, {
1260
+ return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutRemoveDiscount`, {
1196
1261
  checkoutId: checkout.id,
1197
1262
  })), concatMap(() => this.getCheckout()));
1198
1263
  }
1199
1264
  validateStockProducts() {
1200
- return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutValidateProductStock`, {
1265
+ return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutValidateProductStock`, {
1201
1266
  checkoutId: checkout.id,
1202
1267
  })));
1203
1268
  }
1204
1269
  selectShippingAddress(address) {
1205
1270
  return this.getCheckout().pipe(concatMap((checkout) => {
1206
- return this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, shippingAddress: address, billingAddress: address }));
1271
+ return this.repositoriesFacade.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, shippingAddress: address, billingAddress: address }));
1207
1272
  }));
1208
1273
  }
1209
1274
  getAvailableShippingForProduct(productShipping) {
1210
- return this.http.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
1275
+ return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
1211
1276
  checkoutId: null,
1212
1277
  productShipping,
1213
1278
  });
1214
1279
  }
1215
1280
  getAvailableShippingForCheckout() {
1216
- return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
1281
+ return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
1217
1282
  checkoutId: checkout.id,
1218
1283
  productShipping: null,
1219
1284
  })));
1220
1285
  }
1221
1286
  selectShipping(option) {
1222
- return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutSelectShipping`, {
1287
+ return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutSelectShipping`, {
1223
1288
  checkoutId: checkout.id,
1224
1289
  shippingOption: option,
1225
1290
  })), concatMap(() => this.getCheckout()));
1226
1291
  }
1227
1292
  createOrder(checkoutPayload, paymentProvider, applicationVersion) {
1228
- return this.http.post(`${this.checkoutUrl}/checkout`, {
1293
+ return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkout`, {
1229
1294
  data: Object.assign(Object.assign({}, checkoutPayload), { applicationVersion,
1230
1295
  paymentProvider }),
1231
1296
  });
1232
1297
  }
1233
1298
  createCheckout(checkoutData) {
1234
1299
  return __awaiter(this, void 0, void 0, function* () {
1235
- const checkout = yield this.checkoutRepository.create(Object.assign(Object.assign({ createdAt: new Date() }, Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()), { shop: (checkoutData === null || checkoutData === void 0 ? void 0 : checkoutData.shop) || this.defaultShop }));
1236
- yield this.dataPersistence.set('checkoutId', checkout.id).toPromise();
1300
+ const checkout = yield this.repositoriesFacade.checkoutRepository.create(Object.assign(Object.assign({ createdAt: new Date() }, Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()), { shop: (checkoutData === null || checkoutData === void 0 ? void 0 : checkoutData.shop) || this.configurationFacade.defaultShop }));
1301
+ yield this.dependenciesFacade.dataPersistence.set('checkoutId', checkout.id).toPromise();
1237
1302
  return checkout;
1238
1303
  });
1239
1304
  }
1240
1305
  }
1241
- CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }, { token: PERSISTENCE_PROVIDER }, { token: FIREBASE_OPTIONS }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1306
+ CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: CheckoutRepositoriesFacade }, { token: CheckoutDependenciesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable });
1242
1307
  CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
1243
1308
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
1244
1309
  type: Injectable
1245
- }], ctorParameters: function () {
1246
- return [{ type: undefined, decorators: [{
1247
- type: Inject,
1248
- args: ['CheckoutRepository']
1249
- }] }, { type: undefined, decorators: [{
1250
- type: Inject,
1251
- args: ['UserRepository']
1252
- }] }, { type: i1$3.Shops, decorators: [{
1253
- type: Inject,
1254
- args: [DEFAULT_SHOP]
1255
- }] }, { type: undefined, decorators: [{
1256
- type: Inject,
1257
- args: [PERSISTENCE_PROVIDER]
1258
- }] }, { type: undefined, decorators: [{
1259
- type: Inject,
1260
- args: [FIREBASE_OPTIONS]
1261
- }] }, { type: i1$2.HttpClient }];
1262
- } });
1310
+ }], ctorParameters: function () { return [{ type: CheckoutRepositoriesFacade }, { type: CheckoutDependenciesFacade }, { type: ConfigurationFacade }]; } });
1263
1311
 
1264
- class CartService {
1265
- constructor(authService, checkoutService, defaultShop, firebaseOptions, http) {
1312
+ class CartServicesFacade {
1313
+ constructor(authService, checkoutService, httpClient) {
1266
1314
  this.authService = authService;
1267
1315
  this.checkoutService = checkoutService;
1268
- this.defaultShop = defaultShop;
1269
- this.firebaseOptions = firebaseOptions;
1270
- this.http = http;
1316
+ this.httpClient = httpClient;
1317
+ }
1318
+ }
1319
+ CartServicesFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartServicesFacade, deps: [{ token: AuthService }, { token: CheckoutService }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1320
+ CartServicesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartServicesFacade });
1321
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartServicesFacade, decorators: [{
1322
+ type: Injectable
1323
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$2.HttpClient }]; } });
1324
+
1325
+ class CartService {
1326
+ constructor(servicesFacade, configurationFacade) {
1327
+ this.servicesFacade = servicesFacade;
1328
+ this.configurationFacade = configurationFacade;
1271
1329
  this.cartSubject = new Subject();
1272
1330
  this.checkoutUrl = null;
1273
1331
  this.generateCartObject = (items) => (items === null || items === void 0 ? void 0 : items.reduce((cart, item) => {
1274
1332
  var _a;
1275
1333
  return (Object.assign(Object.assign({}, cart), { [item.id]: LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })) }));
1276
1334
  }, {})) || {};
1277
- this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
1335
+ this.checkoutUrl = this.configurationFacade.getCheckoutUrl();
1278
1336
  }
1279
1337
  addItem(item, quantity = 1) {
1280
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutAddItemToCart`, {
1338
+ return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutAddItemToCart`, {
1281
1339
  checkoutId: checkout.id,
1282
1340
  productId: item.id,
1283
1341
  quantity,
1284
- })), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1342
+ })), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1285
1343
  }
1286
1344
  decreaseItem(item) {
1287
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutDecreaseProductFromCart`, {
1345
+ return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutDecreaseProductFromCart`, {
1288
1346
  checkoutId: checkout.id,
1289
1347
  productId: item.id,
1290
1348
  quantity: 1,
1291
- })), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1349
+ })), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1292
1350
  }
1293
1351
  removeItem(item) {
1294
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutRemoveProductFromCart`, {
1352
+ return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutRemoveProductFromCart`, {
1295
1353
  checkoutId: checkout.id,
1296
1354
  productId: item.id,
1297
- })), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1355
+ })), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1298
1356
  }
1299
1357
  updateUserCart(user) {
1300
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => {
1301
- return this.http.post(`${this.checkoutUrl}/checkoutUpdateUserCart`, {
1358
+ return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => {
1359
+ return this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutUpdateUserCart`, {
1302
1360
  checkoutId: checkout.id,
1303
1361
  });
1304
- }), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => {
1362
+ }), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => {
1305
1363
  return this.generateCartObject(updatedCheckout.lineItems);
1306
1364
  }), tap((cart) => this.cartSubject.next(cart)));
1307
1365
  }
@@ -1310,28 +1368,20 @@ class CartService {
1310
1368
  return this.cartSubject;
1311
1369
  }
1312
1370
  clearCart() {
1313
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1314
- this.checkoutService.clearCheckoutFromSession();
1371
+ return this.servicesFacade.checkoutService.getCheckout().pipe(map((checkout) => {
1372
+ this.servicesFacade.checkoutService.clearCheckoutFromSession();
1315
1373
  return checkout;
1316
1374
  }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
1317
1375
  }
1318
1376
  buildCartFromCheckout(checkoutData) {
1319
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1377
+ return this.servicesFacade.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1320
1378
  }
1321
1379
  }
1322
- 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: FIREBASE_OPTIONS }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1380
+ CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: CartServicesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable });
1323
1381
  CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
1324
1382
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
1325
1383
  type: Injectable
1326
- }], ctorParameters: function () {
1327
- return [{ type: AuthService }, { type: CheckoutService }, { type: i1$3.Shops, decorators: [{
1328
- type: Inject,
1329
- args: [DEFAULT_SHOP]
1330
- }] }, { type: undefined, decorators: [{
1331
- type: Inject,
1332
- args: [FIREBASE_OPTIONS]
1333
- }] }, { type: i1$2.HttpClient }];
1334
- } });
1384
+ }], ctorParameters: function () { return [{ type: CartServicesFacade }, { type: ConfigurationFacade }]; } });
1335
1385
 
1336
1386
  class NewCategoryStructureAdapter {
1337
1387
  constructor(categoryRepository) {
@@ -1407,355 +1457,837 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1407
1457
  }] }];
1408
1458
  } });
1409
1459
 
1410
- class CatalogService {
1411
- constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch) {
1412
- this.productRepository = productRepository;
1413
- this.productStockNotificationRepository = productStockNotificationRepository;
1414
- this.categoryRepository = categoryRepository;
1415
- this.categoryStructureAdapter = categoryStructureAdapter;
1416
- this.shop = shop;
1417
- this.productSearch = productSearch;
1418
- this.productsByTerm = {};
1419
- this.brandsList = {};
1420
- this.fields = [
1421
- 'id',
1422
- 'name',
1423
- 'slug',
1424
- 'images',
1425
- 'miniatures',
1426
- 'price',
1427
- 'stock',
1428
- 'published',
1429
- 'CEST',
1430
- 'EAN',
1431
- 'NCM',
1432
- 'brand',
1433
- 'costPrice',
1434
- 'hasVariants',
1435
- 'isKit',
1436
- 'sku',
1437
- 'rate',
1438
- 'tags',
1439
- 'type',
1440
- 'shoppingCount',
1441
- 'gender',
1442
- 'createdAt',
1443
- 'label',
1444
- 'outlet',
1445
- 'group',
1446
- ];
1447
- this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1448
- const filters = {};
1449
- if (clubDiscount === null || clubDiscount === void 0 ? void 0 : clubDiscount.length)
1450
- set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1451
- if (brands === null || brands === void 0 ? void 0 : brands.length)
1452
- filters.brand = { operator: Where.IN, value: brands };
1453
- if (gender === null || gender === void 0 ? void 0 : gender.length)
1454
- filters.gender = { operator: Where.IN, value: gender };
1455
- if ((prices === null || prices === void 0 ? void 0 : prices.min) || (prices === null || prices === void 0 ? void 0 : prices.max))
1456
- set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1457
- ...(prices.min ? [{ operator: Where.GTE, value: Math.floor(prices.min) }] : []),
1458
- ...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
1459
- ]);
1460
- if (rate)
1461
- filters.rate = { operator: Where.GTE, value: rate };
1462
- if (tags === null || tags === void 0 ? void 0 : tags.length)
1463
- filters.tags = { operator: Where.LIKE, value: tags };
1464
- if (customOptions === null || customOptions === void 0 ? void 0 : customOptions.length)
1465
- filters.filters = { operator: Where.LIKE, value: customOptions };
1466
- return filters;
1467
- };
1468
- this.buildSortQuery = (sort) => {
1469
- if (!sort || sort === 'most-relevant')
1470
- return {};
1471
- if (sort === 'best-sellers')
1472
- return {
1473
- shoppingCount: 'desc',
1474
- rate: 'desc',
1475
- stock: 'desc',
1476
- name: 'asc',
1477
- };
1478
- if (sort === 'biggest-price')
1479
- return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1480
- if (sort === 'lowest-price')
1481
- return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1482
- if (sort === 'best-rating')
1483
- return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1484
- if (sort === 'news')
1485
- return { createdAt: 'desc' };
1486
- if (sort === 'biggest-discount')
1487
- return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1488
- };
1489
- this.buildLimitQuery = (options) => {
1490
- const limit = (options === null || options === void 0 ? void 0 : options.perPage) || 20;
1491
- return {
1492
- limit,
1493
- offset: (((options === null || options === void 0 ? void 0 : options.page) || 1) - 1) * limit,
1494
- };
1495
- };
1496
- this.hasProfile = (options) => 'profile' in options;
1497
- this.hasTerm = (options) => 'term' in options;
1498
- this.hasCategory = (options) => 'category' in options;
1499
- this.buildIndexBrands = (options) => {
1500
- if (this.hasCategory(options))
1501
- return `category-${options.category.id}`;
1502
- if (this.hasTerm(options))
1503
- return `term-${options.term}`;
1504
- if (this.hasProfile(options))
1505
- return `profile-${options.profile.join(',')}`;
1506
- return '';
1507
- };
1508
- }
1509
- fetchProducts(options, optionsCache) {
1510
- var _a, _b, _c;
1460
+ class CatalogSearchContext {
1461
+ constructor(categoryStrategy, termStrategy, profileStrategy) {
1462
+ this.categoryStrategy = categoryStrategy;
1463
+ this.termStrategy = termStrategy;
1464
+ this.profileStrategy = profileStrategy;
1465
+ this.strategies = new Map();
1466
+ this.initializeStrategies();
1467
+ }
1468
+ executeSearch(params, shop, optionsCache) {
1511
1469
  return __awaiter(this, void 0, void 0, function* () {
1512
- const limits = this.buildLimitQuery(options);
1513
- if (this.hasProfile(options) && ((_a = options.filters) === null || _a === void 0 ? void 0 : _a.customOptions))
1514
- throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
1515
- if (this.hasProfile(options) && ((_b = options.filters) === null || _b === void 0 ? void 0 : _b.tags))
1516
- throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1517
- if (this.hasTerm(options) && ((_c = options.filters) === null || _c === void 0 ? void 0 : _c.customOptions))
1518
- throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1519
- return yield this.findCatalog(options, limits, optionsCache).then(({ data, count: total, maximum, minimal, distinct }) => __awaiter(this, void 0, void 0, function* () {
1520
- var _d, _e, _f, _g, _h, _j, _k, _l;
1521
- yield this.setBrandsList(options, distinct === null || distinct === void 0 ? void 0 : distinct.brand);
1522
- return {
1523
- products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1524
- pages: Math.ceil(total / limits.limit),
1525
- prices: {
1526
- price: { min: +((_e = (_d = minimal === null || minimal === void 0 ? void 0 : minimal.price) === null || _d === void 0 ? void 0 : _d.price) === null || _e === void 0 ? void 0 : _e.toFixed(2)), max: +((_g = (_f = maximum === null || maximum === void 0 ? void 0 : maximum.price) === null || _f === void 0 ? void 0 : _f.price) === null || _g === void 0 ? void 0 : _g.toFixed(2)) },
1527
- subscriberPrice: {
1528
- min: +((_j = (_h = minimal === null || minimal === void 0 ? void 0 : minimal.price) === null || _h === void 0 ? void 0 : _h.subscriberPrice) === null || _j === void 0 ? void 0 : _j.toFixed(2)),
1529
- max: +((_l = (_k = maximum === null || maximum === void 0 ? void 0 : maximum.price) === null || _k === void 0 ? void 0 : _k.subscriberPrice) === null || _l === void 0 ? void 0 : _l.toFixed(2)),
1530
- },
1531
- },
1532
- brands: this.brandsList[this.buildIndexBrands(options)],
1533
- };
1534
- }));
1470
+ const strategy = this.selectStrategy(params);
1471
+ return strategy.search(params, shop, optionsCache);
1535
1472
  });
1536
1473
  }
1537
- addCustomerToStockNotification(shop, productId, name, email) {
1538
- return __awaiter(this, void 0, void 0, function* () {
1539
- return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1540
- });
1474
+ initializeStrategies() {
1475
+ this.strategies.set('category', this.categoryStrategy);
1476
+ this.strategies.set('term', this.termStrategy);
1477
+ this.strategies.set('profile', this.profileStrategy);
1541
1478
  }
1542
- findCatalog(options, limits, optionsCache) {
1479
+ selectStrategy(params) {
1543
1480
  var _a;
1481
+ if (params.category) {
1482
+ const strategy = this.strategies.get('category');
1483
+ if (!strategy)
1484
+ throw new Error('Category strategy not found');
1485
+ return strategy;
1486
+ }
1487
+ if (params.term) {
1488
+ const strategy = this.strategies.get('term');
1489
+ if (!strategy)
1490
+ throw new Error('Term strategy not found');
1491
+ return strategy;
1492
+ }
1493
+ if ((_a = params.profile) === null || _a === void 0 ? void 0 : _a.length) {
1494
+ const strategy = this.strategies.get('profile');
1495
+ if (!strategy)
1496
+ throw new Error('Profile strategy not found');
1497
+ return strategy;
1498
+ }
1499
+ throw new Error('No valid search strategy found for the given parameters');
1500
+ }
1501
+ }
1502
+
1503
+ class CategorySearchStrategy {
1504
+ constructor(repositoryService, helpersService) {
1505
+ this.repositoryService = repositoryService;
1506
+ this.helpersService = helpersService;
1507
+ }
1508
+ search(params, shop, optionsCache) {
1544
1509
  return __awaiter(this, void 0, void 0, function* () {
1545
- if (this.hasTerm(options) && options.sort === 'most-relevant') {
1546
- const productsIds = yield this.findCatalogIdsBySearch(options.term);
1547
- return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1510
+ const { category, filters, limits, sort, mainGender } = params;
1511
+ if (!category) {
1512
+ throw new Error('Category is required for CategorySearchStrategy');
1548
1513
  }
1549
- if (this.hasCategory(options) && options.sort === 'most-relevant') {
1550
- const mostRelevant = options.category.isWishlist ? [] : options.category.getMostRelevantByShop(this.shop);
1551
- const productsIds = yield this.productRepository
1552
- .findCatalog({
1553
- fields: ['id'],
1554
- filters: Object.assign(Object.assign({}, (yield this.buildMainFilter(options))), this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1555
- }, undefined, optionsCache)
1556
- .then((products) => products.data.map((product) => product.id));
1557
- return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits, optionsCache);
1514
+ const fields = this.helpersService.getFieldsHelper().getStandardFields();
1515
+ if (sort === 'most-relevant') {
1516
+ return this.searchWithMostRelevant({
1517
+ category,
1518
+ filters,
1519
+ limits,
1520
+ shop,
1521
+ mainGender,
1522
+ optionsCache,
1523
+ fields,
1524
+ });
1558
1525
  }
1559
- const repoParams = Object.assign(Object.assign({ fields: this.fields, filters: Object.assign(Object.assign({}, (yield this.buildMainFilter(options))), this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})) }, ((options === null || options === void 0 ? void 0 : options.sort) ? { orderBy: this.buildSortQuery(options === null || options === void 0 ? void 0 : options.sort) } : {})), { limits, options: Object.assign({ minimal: ['price'], maximum: ['price'] }, (!this.brandsList[this.buildIndexBrands(options)] && isEmpty((_a = options.filters) === null || _a === void 0 ? void 0 : _a.brands)
1560
- ? { distinct: ['brand'] }
1561
- : {})) });
1562
- if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1563
- return this.productRepository.findCatalog(repoParams, undefined, optionsCache);
1564
- return this.productRepository.findCatalog(repoParams, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
1526
+ return this.searchDefault({
1527
+ category,
1528
+ filters,
1529
+ limits,
1530
+ shop,
1531
+ mainGender,
1532
+ sort,
1533
+ optionsCache,
1534
+ fields,
1535
+ });
1565
1536
  });
1566
1537
  }
1567
- buildMainFilter({ category, profile, term, }) {
1538
+ searchWithMostRelevant(params) {
1568
1539
  return __awaiter(this, void 0, void 0, function* () {
1569
- if (category)
1570
- return this.categoryStructureAdapter.buildProductFilterByCategory(category);
1571
- if (profile)
1572
- return { tags: { operator: Where.LIKE, value: profile } };
1573
- if (term)
1574
- return this.productSearch
1575
- .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1576
- .then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
1540
+ const { category, filters, shop, optionsCache } = params;
1541
+ const mostRelevant = category.isWishlist ? [] : category.getMostRelevantByShop(shop);
1542
+ const productsIds = yield this.getProductIds(category, filters, optionsCache);
1543
+ return this.findAndSortByMostRelevant({
1544
+ mostRelevants: mostRelevant,
1545
+ productIds: productsIds,
1546
+ filters: params.filters,
1547
+ limits: params.limits,
1548
+ shop: params.shop,
1549
+ mainGender: params.mainGender,
1550
+ optionsCache: params.optionsCache,
1551
+ fields: params.fields,
1552
+ });
1577
1553
  });
1578
1554
  }
1579
- findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits, optionsCache) {
1580
- var _a, _b;
1555
+ searchDefault(params) {
1556
+ return __awaiter(this, void 0, void 0, function* () {
1557
+ const { category, filters, limits, shop, mainGender, sort, optionsCache, fields } = params;
1558
+ const productCatalog = this.repositoryService.getProductCatalog();
1559
+ const filterHelper = this.helpersService.getFilterHelper();
1560
+ const sortHelper = this.helpersService.getSortHelper();
1561
+ const repoParams = Object.assign(Object.assign({ fields, filters: Object.assign(Object.assign({}, (yield productCatalog.categoryStructureAdapter.buildProductFilterByCategory(category))), filterHelper.buildFilterQuery(filters || {})) }, (sort ? { orderBy: sortHelper.buildSortQuery(sort) } : {})), { limits, options: {
1562
+ minimal: ['price'],
1563
+ maximum: ['price'],
1564
+ distinct: ['brand'],
1565
+ } });
1566
+ return productCatalog.productRepository.findCatalog(repoParams, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'), optionsCache);
1567
+ });
1568
+ }
1569
+ getProductIds(category, filters, optionsCache) {
1581
1570
  return __awaiter(this, void 0, void 0, function* () {
1582
- const brandsList = this.brandsList[this.buildIndexBrands(options)];
1571
+ const productCatalog = this.repositoryService.getProductCatalog();
1572
+ const filterHelper = this.helpersService.getFilterHelper();
1573
+ return productCatalog.productRepository
1574
+ .findCatalog({
1575
+ fields: ['id'],
1576
+ filters: Object.assign(Object.assign({}, (yield productCatalog.categoryStructureAdapter.buildProductFilterByCategory(category))), filterHelper.buildFilterQuery(filters || {})),
1577
+ }, undefined, optionsCache)
1578
+ .then((products) => products.data.map((product) => product.id));
1579
+ });
1580
+ }
1581
+ findAndSortByMostRelevant(params) {
1582
+ return __awaiter(this, void 0, void 0, function* () {
1583
+ const { mostRelevants, productIds, filters, shop, mainGender, optionsCache, fields, limits } = params;
1584
+ const productCatalog = this.repositoryService.getProductCatalog();
1585
+ const filterHelper = this.helpersService.getFilterHelper();
1586
+ const sortHelper = this.helpersService.getSortHelper();
1583
1587
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1584
- const totalResult = yield this.productRepository.findCatalog({
1585
- fields: this.fields,
1586
- filters: Object.assign({ id: { operator: Where.IN, value: mostRelevantProductsIds } }, this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1587
- orderBy: this.buildSortQuery('best-sellers'),
1588
- options: Object.assign({ minimal: ['price'], maximum: ['price'] }, (!brandsList && isEmpty((_a = options.filters) === null || _a === void 0 ? void 0 : _a.brands) ? { distinct: ['brand'] } : {})),
1589
- }, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
1590
- const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
1591
- const firstProducts = totalResult.data
1592
- .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
1593
- .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
1594
- const lastProducts = totalResult.data
1595
- .filter((product) => !mostRelevants.includes(product.id))
1596
- .concat(mostRelevantWithouyStock);
1597
- const categoryMostRelevants = firstProducts.concat(lastProducts);
1598
- const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1599
- yield this.setBrandsList(options, (_b = totalResult.distinct) === null || _b === void 0 ? void 0 : _b.brand);
1600
- return {
1601
- data: resultFinal,
1602
- count: totalResult.count,
1603
- maximum: totalResult.maximum,
1604
- minimal: totalResult.minimal,
1605
- distinct: Object.assign(Object.assign({}, totalResult.distinct), { brand: this.brandsList[this.buildIndexBrands(options)] }),
1606
- };
1588
+ const totalResult = yield productCatalog.productRepository.findCatalog({
1589
+ fields,
1590
+ filters: Object.assign({ id: { operator: Where.IN, value: mostRelevantProductsIds } }, filterHelper.buildFilterQuery(filters || {})),
1591
+ orderBy: sortHelper.buildSortQuery('best-sellers'),
1592
+ options: Object.assign({ minimal: ['price'], maximum: ['price'] }, (isEmpty(filters === null || filters === void 0 ? void 0 : filters.brands) ? { distinct: ['brand'] } : {})),
1593
+ }, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'), optionsCache);
1594
+ return this.sortProductsByRelevance(totalResult, mostRelevants, limits);
1595
+ });
1596
+ }
1597
+ sortProductsByRelevance(totalResult, mostRelevants, limits) {
1598
+ const mostRelevantWithoutStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
1599
+ const firstProducts = totalResult.data
1600
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
1601
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
1602
+ const lastProducts = totalResult.data
1603
+ .filter((product) => !mostRelevants.includes(product.id))
1604
+ .concat(mostRelevantWithoutStock);
1605
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
1606
+ const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1607
+ return {
1608
+ data: resultFinal,
1609
+ count: totalResult.count,
1610
+ maximum: totalResult.maximum,
1611
+ minimal: totalResult.minimal,
1612
+ distinct: totalResult.distinct,
1613
+ };
1614
+ }
1615
+ }
1616
+ CategorySearchStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategorySearchStrategy, deps: [{ token: CatalogRepositoryService }, { token: CatalogHelpersService }], target: i0.ɵɵFactoryTarget.Injectable });
1617
+ CategorySearchStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategorySearchStrategy });
1618
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategorySearchStrategy, decorators: [{
1619
+ type: Injectable
1620
+ }], ctorParameters: function () { return [{ type: CatalogRepositoryService }, { type: CatalogHelpersService }]; } });
1621
+
1622
+ class ProfileSearchStrategy {
1623
+ constructor(repositoryService, helpersService) {
1624
+ this.repositoryService = repositoryService;
1625
+ this.helpersService = helpersService;
1626
+ }
1627
+ search(params, shop, optionsCache) {
1628
+ return __awaiter(this, void 0, void 0, function* () {
1629
+ const { profile, filters, limits, sort, mainGender } = params;
1630
+ if (!profile) {
1631
+ throw new Error('Profile is required for ProfileSearchStrategy');
1632
+ }
1633
+ const productCatalog = this.repositoryService.getProductCatalog();
1634
+ const filterHelper = this.helpersService.getFilterHelper();
1635
+ const sortHelper = this.helpersService.getSortHelper();
1636
+ const fieldsHelper = this.helpersService.getFieldsHelper();
1637
+ const repoParams = Object.assign(Object.assign({ fields: fieldsHelper.getStandardFields(), filters: Object.assign({ tags: { operator: Where.LIKE, value: profile } }, filterHelper.buildFilterQuery(filters || {})) }, (sort ? { orderBy: sortHelper.buildSortQuery(sort) } : {})), { limits, options: {
1638
+ minimal: ['price'],
1639
+ maximum: ['price'],
1640
+ distinct: ['brand'],
1641
+ } });
1642
+ return productCatalog.productRepository.findCatalog(repoParams, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'), optionsCache);
1643
+ });
1644
+ }
1645
+ }
1646
+ ProfileSearchStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProfileSearchStrategy, deps: [{ token: CatalogRepositoryService }, { token: CatalogHelpersService }], target: i0.ɵɵFactoryTarget.Injectable });
1647
+ ProfileSearchStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProfileSearchStrategy });
1648
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProfileSearchStrategy, decorators: [{
1649
+ type: Injectable
1650
+ }], ctorParameters: function () { return [{ type: CatalogRepositoryService }, { type: CatalogHelpersService }]; } });
1651
+
1652
+ class TermSearchStrategy {
1653
+ constructor(repositoryService, helpersService) {
1654
+ this.repositoryService = repositoryService;
1655
+ this.helpersService = helpersService;
1656
+ this.productsByTerm = {};
1657
+ }
1658
+ search(params, shop, _optionsCache) {
1659
+ return __awaiter(this, void 0, void 0, function* () {
1660
+ const { term, filters, limits, sort, mainGender } = params;
1661
+ if (!term) {
1662
+ throw new Error('Term is required for TermSearchStrategy');
1663
+ }
1664
+ const productIds = yield this.findCatalogIdsBySearch(term, shop);
1665
+ if (sort === 'most-relevant') {
1666
+ return this.searchWithMostRelevant({
1667
+ productIds,
1668
+ filters,
1669
+ limits,
1670
+ shop,
1671
+ mainGender,
1672
+ });
1673
+ }
1674
+ return this.searchDefault({
1675
+ productIds,
1676
+ filters,
1677
+ limits,
1678
+ shop,
1679
+ mainGender,
1680
+ fields: this.helpersService.getFieldsHelper().getStandardFields(),
1681
+ });
1607
1682
  });
1608
1683
  }
1609
- findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1610
- var _a, _b, _c, _d;
1684
+ searchWithMostRelevant(params) {
1611
1685
  return __awaiter(this, void 0, void 0, function* () {
1612
- const brandsList = this.brandsList[this.buildIndexBrands(options)];
1613
- const totalResult = yield this.productRepository.findCatalog({
1686
+ const { productIds, filters, shop, mainGender } = params;
1687
+ const productCatalog = this.repositoryService.getProductCatalog();
1688
+ const filterHelper = this.helpersService.getFilterHelper();
1689
+ const totalResult = yield productCatalog.productRepository.findCatalog({
1614
1690
  fields: ['id', 'stock', 'gender'],
1615
- filters: Object.assign({ id: { operator: Where.IN, value: productIds }, published: { operator: Where.EQUALS, value: true } }, this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1616
- options: Object.assign({ minimal: ['price'], maximum: ['price'] }, (!brandsList && isEmpty((_a = options.filters) === null || _a === void 0 ? void 0 : _a.brands) ? { distinct: ['brand'] } : {})),
1617
- }, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1618
- const defaultGender = ((_b = options === null || options === void 0 ? void 0 : options.filters) === null || _b === void 0 ? void 0 : _b.gender)
1619
- ? (_c = options === null || options === void 0 ? void 0 : options.filters) === null || _c === void 0 ? void 0 : _c.gender.at(0)
1620
- : this.shop === Shops.GLAMSHOP
1621
- ? 'female'
1622
- : 'male';
1623
- const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1624
- const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1625
- const productIdsStockGender = productIds.filter((product) => stockData.some((result) => { var _a, _b; return result.id === product && (((_a = result.gender) === null || _a === void 0 ? void 0 : _a.includes(defaultGender)) || ((_b = result.gender) === null || _b === void 0 ? void 0 : _b.includes('unisex'))); }));
1626
- const productIdsStockNotGender = productIds.filter((product) => stockData.some((result) => { var _a, _b; return result.id === product && !((_a = result.gender) === null || _a === void 0 ? void 0 : _a.includes(defaultGender)) && !((_b = result.gender) === null || _b === void 0 ? void 0 : _b.includes('unisex')); }));
1627
- const productIdsStock = productIdsStockGender.concat(productIdsStockNotGender);
1628
- const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id === product));
1629
- const limitedProductId = productIdsStock
1630
- .concat(productIdsStockOut)
1631
- .slice(limits.offset, limits.offset + limits.limit);
1632
- const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1633
- const productResult = yield this.productRepository.findCatalog({
1691
+ filters: Object.assign({ id: { operator: Where.IN, value: productIds }, published: { operator: Where.EQUALS, value: true } }, filterHelper.buildFilterQuery(filters || {})),
1692
+ options: Object.assign({ minimal: ['price'], maximum: ['price'] }, (isEmpty(filters === null || filters === void 0 ? void 0 : filters.brands) ? { distinct: ['brand'] } : {})),
1693
+ }, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'));
1694
+ return this.sortByTermRelevance({
1695
+ productIds,
1696
+ totalResult,
1697
+ limits: params.limits,
1698
+ filters,
1699
+ fieldsHelper: this.helpersService.getFieldsHelper(),
1700
+ });
1701
+ });
1702
+ }
1703
+ searchDefault(params) {
1704
+ return __awaiter(this, void 0, void 0, function* () {
1705
+ const { productIds, filters, limits, shop, mainGender, fields } = params;
1706
+ const productCatalog = this.repositoryService.getProductCatalog();
1707
+ const filterHelper = this.helpersService.getFilterHelper();
1708
+ return productCatalog.productRepository.findCatalog({
1709
+ fields,
1710
+ filters: Object.assign({ id: { operator: Where.IN, value: productIds }, published: { operator: Where.EQUALS, value: true } }, filterHelper.buildFilterQuery(filters || {})),
1711
+ limits,
1712
+ options: {
1713
+ minimal: ['price'],
1714
+ maximum: ['price'],
1715
+ distinct: ['brand'],
1716
+ },
1717
+ }, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'));
1718
+ });
1719
+ }
1720
+ sortByTermRelevance(params) {
1721
+ var _a;
1722
+ const { productIds, totalResult, limits, filters, fieldsHelper } = params;
1723
+ const defaultGender = ((_a = filters === null || filters === void 0 ? void 0 : filters.gender) === null || _a === void 0 ? void 0 : _a.at(0)) || 'male';
1724
+ const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1725
+ const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1726
+ const productIdsStockGender = productIds.filter((product) => stockData.some((result) => { var _a, _b; return result.id === product && (((_a = result.gender) === null || _a === void 0 ? void 0 : _a.includes(defaultGender)) || ((_b = result.gender) === null || _b === void 0 ? void 0 : _b.includes('unisex'))); }));
1727
+ const productIdsStockNotGender = productIds.filter((product) => stockData.some((result) => { var _a, _b; return result.id === product && !((_a = result.gender) === null || _a === void 0 ? void 0 : _a.includes(defaultGender)) && !((_b = result.gender) === null || _b === void 0 ? void 0 : _b.includes('unisex')); }));
1728
+ const productIdsStock = productIdsStockGender.concat(productIdsStockNotGender);
1729
+ const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id === product));
1730
+ const limitedProductId = productIdsStock
1731
+ .concat(productIdsStockOut)
1732
+ .slice(limits.offset, limits.offset + limits.limit);
1733
+ const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1734
+ return this.getDetailedProducts(orderedId, totalResult, fieldsHelper);
1735
+ }
1736
+ getDetailedProducts(orderedId, totalResult, fieldsHelper) {
1737
+ return __awaiter(this, void 0, void 0, function* () {
1738
+ const productCatalog = this.repositoryService.getProductCatalog();
1739
+ const fields = fieldsHelper.getStandardFields();
1740
+ const productResult = yield productCatalog.productRepository.findCatalog({
1634
1741
  filters: {
1635
1742
  id: { operator: Where.IN, value: orderedId },
1636
1743
  },
1637
- fields: this.fields,
1744
+ fields,
1638
1745
  });
1639
- yield this.setBrandsList(options, (_d = totalResult.distinct) === null || _d === void 0 ? void 0 : _d.brand);
1640
1746
  return {
1641
- data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1747
+ data: orderedId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1642
1748
  count: totalResult.count,
1643
1749
  maximum: totalResult.maximum,
1644
1750
  minimal: totalResult.minimal,
1645
- distinct: Object.assign(Object.assign({}, totalResult.distinct), { brand: this.brandsList[this.buildIndexBrands(options)] }),
1751
+ distinct: totalResult.distinct,
1646
1752
  };
1647
1753
  });
1648
1754
  }
1649
- findCatalogIdsBySearch(term, preview = false) {
1755
+ findCatalogIdsBySearch(term, shop) {
1650
1756
  return __awaiter(this, void 0, void 0, function* () {
1651
1757
  if (this.productsByTerm[term])
1652
1758
  return this.productsByTerm[term];
1653
- return (this.productsByTerm[term] = yield this.productSearch
1654
- .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1759
+ const productServices = this.repositoryService.getProductServices();
1760
+ return (this.productsByTerm[term] = yield productServices.productSearch
1761
+ .search(term, 999, shop === Shops.GLAMSHOP ? 'female' : 'male')
1655
1762
  .then((products) => [...new Set(products.map((product) => product.id))]));
1656
1763
  });
1657
1764
  }
1658
- fetchBrandsOnly(options, productIds = []) {
1765
+ }
1766
+ TermSearchStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: TermSearchStrategy, deps: [{ token: CatalogRepositoryService }, { token: CatalogHelpersService }], target: i0.ɵɵFactoryTarget.Injectable });
1767
+ TermSearchStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: TermSearchStrategy });
1768
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: TermSearchStrategy, decorators: [{
1769
+ type: Injectable
1770
+ }], ctorParameters: function () { return [{ type: CatalogRepositoryService }, { type: CatalogHelpersService }]; } });
1771
+
1772
+ class CatalogStrategiesFacade {
1773
+ constructor(categoryStrategy, termStrategy, profileStrategy) {
1774
+ this.categoryStrategy = categoryStrategy;
1775
+ this.termStrategy = termStrategy;
1776
+ this.profileStrategy = profileStrategy;
1777
+ }
1778
+ }
1779
+ CatalogStrategiesFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogStrategiesFacade, deps: [{ token: CategorySearchStrategy }, { token: TermSearchStrategy }, { token: ProfileSearchStrategy }], target: i0.ɵɵFactoryTarget.Injectable });
1780
+ CatalogStrategiesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogStrategiesFacade });
1781
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogStrategiesFacade, decorators: [{
1782
+ type: Injectable
1783
+ }], ctorParameters: function () { return [{ type: CategorySearchStrategy }, { type: TermSearchStrategy }, { type: ProfileSearchStrategy }]; } });
1784
+
1785
+ class CatalogServiceFacade {
1786
+ constructor(helpersService, strategiesFacade, shop) {
1787
+ this.helpersService = helpersService;
1788
+ this.strategiesFacade = strategiesFacade;
1789
+ this.shop = shop;
1790
+ const searchContext = new CatalogSearchContext(this.strategiesFacade.categoryStrategy, this.strategiesFacade.termStrategy, this.strategiesFacade.profileStrategy);
1791
+ this.catalogService = new CatalogService(searchContext, this.helpersService, this.shop);
1792
+ }
1793
+ getCatalogService() {
1794
+ return this.catalogService;
1795
+ }
1796
+ }
1797
+ CatalogServiceFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogServiceFacade, deps: [{ token: CatalogHelpersService }, { token: CatalogStrategiesFacade }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1798
+ CatalogServiceFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogServiceFacade });
1799
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogServiceFacade, decorators: [{
1800
+ type: Injectable
1801
+ }], ctorParameters: function () {
1802
+ return [{ type: CatalogHelpersService }, { type: CatalogStrategiesFacade }, { type: i3.Shops, decorators: [{
1803
+ type: Inject,
1804
+ args: [DEFAULT_SHOP]
1805
+ }] }];
1806
+ } });
1807
+
1808
+ class CategoryRepositoryFacade {
1809
+ constructor(categoryRepository, categoryFilterRepository) {
1810
+ this.categoryRepository = categoryRepository;
1811
+ this.categoryFilterRepository = categoryFilterRepository;
1812
+ }
1813
+ }
1814
+ CategoryRepositoryFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryRepositoryFacade, deps: [{ token: 'CategoryRepository' }, { token: 'CategoryFilterRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1815
+ CategoryRepositoryFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryRepositoryFacade });
1816
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryRepositoryFacade, decorators: [{
1817
+ type: Injectable
1818
+ }], ctorParameters: function () {
1819
+ return [{ type: undefined, decorators: [{
1820
+ type: Inject,
1821
+ args: ['CategoryRepository']
1822
+ }] }, { type: undefined, decorators: [{
1823
+ type: Inject,
1824
+ args: ['CategoryFilterRepository']
1825
+ }] }];
1826
+ } });
1827
+
1828
+ class CategoryService {
1829
+ constructor(categoryFacade, productCatalog, shop) {
1830
+ this.categoryFacade = categoryFacade;
1831
+ this.productCatalog = productCatalog;
1832
+ this.shop = shop;
1833
+ }
1834
+ fetchBrands(category, options, optionsCache) {
1659
1835
  return __awaiter(this, void 0, void 0, function* () {
1660
- return this.productRepository
1836
+ const brands = yield this.productCatalog.productRepository
1837
+ .findCatalog({
1838
+ filters: yield this.productCatalog.categoryStructureAdapter.buildProductFilterByCategory(category),
1839
+ fields: ['brand'],
1840
+ }, (options === null || options === void 0 ? void 0 : options.mainGender) ? options === null || options === void 0 ? void 0 : options.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache)
1841
+ .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => (Object.assign(Object.assign({}, brands), { [brand]: true })), {})));
1842
+ return this.categoryFacade.categoryRepository
1843
+ .find({ filters: { brandCategory: true, shop: (options === null || options === void 0 ? void 0 : options.shop) || this.shop }, orderBy: { name: 'asc' } }, optionsCache)
1844
+ .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1845
+ });
1846
+ }
1847
+ fetchFilterOptions(category, optionsCache) {
1848
+ return __awaiter(this, void 0, void 0, function* () {
1849
+ return yield this.categoryFacade.categoryFilterRepository
1850
+ .find({ filters: { categoryId: +category.id } }, optionsCache)
1851
+ .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1852
+ });
1853
+ }
1854
+ }
1855
+ CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token: CategoryRepositoryFacade }, { token: ProductCatalogFacade }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1856
+ CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1857
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1858
+ type: Injectable
1859
+ }], ctorParameters: function () {
1860
+ return [{ type: CategoryRepositoryFacade }, { type: ProductCatalogFacade }, { type: i3.Shops, decorators: [{
1861
+ type: Inject,
1862
+ args: [DEFAULT_SHOP]
1863
+ }] }];
1864
+ } });
1865
+
1866
+ class ProductCatalogFacade {
1867
+ constructor(productRepository, categoryStructureAdapter) {
1868
+ this.productRepository = productRepository;
1869
+ this.categoryStructureAdapter = categoryStructureAdapter;
1870
+ }
1871
+ }
1872
+ ProductCatalogFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductCatalogFacade, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }], target: i0.ɵɵFactoryTarget.Injectable });
1873
+ ProductCatalogFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductCatalogFacade });
1874
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductCatalogFacade, decorators: [{
1875
+ type: Injectable
1876
+ }], ctorParameters: function () {
1877
+ return [{ type: undefined, decorators: [{
1878
+ type: Inject,
1879
+ args: ['ProductRepository']
1880
+ }] }, { type: undefined, decorators: [{
1881
+ type: Inject,
1882
+ args: [CATEGORY_STRUCTURE]
1883
+ }] }];
1884
+ } });
1885
+
1886
+ class CategoryServiceFacade {
1887
+ constructor(categoryRepositoryFacade, productCatalogFacade, shop) {
1888
+ this.categoryRepositoryFacade = categoryRepositoryFacade;
1889
+ this.productCatalogFacade = productCatalogFacade;
1890
+ this.shop = shop;
1891
+ this.categoryService = new CategoryService(this.categoryRepositoryFacade, this.productCatalogFacade, this.shop);
1892
+ }
1893
+ getCategoryService() {
1894
+ return this.categoryService;
1895
+ }
1896
+ }
1897
+ CategoryServiceFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryServiceFacade, deps: [{ token: CategoryRepositoryFacade }, { token: ProductCatalogFacade }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1898
+ CategoryServiceFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryServiceFacade });
1899
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryServiceFacade, decorators: [{
1900
+ type: Injectable
1901
+ }], ctorParameters: function () {
1902
+ return [{ type: CategoryRepositoryFacade }, { type: ProductCatalogFacade }, { type: i3.Shops, decorators: [{
1903
+ type: Inject,
1904
+ args: [DEFAULT_SHOP]
1905
+ }] }];
1906
+ } });
1907
+
1908
+ class BrandManagerHelper {
1909
+ constructor(productCatalog) {
1910
+ this.productCatalog = productCatalog;
1911
+ this.brandsList = {};
1912
+ }
1913
+ setBrandsList(options, brands) {
1914
+ var _a;
1915
+ return __awaiter(this, void 0, void 0, function* () {
1916
+ const filterBrands = (_a = options.filters) === null || _a === void 0 ? void 0 : _a.brands;
1917
+ const indexKey = this.buildIndexBrands(options);
1918
+ if (isEmpty(brands) && options.filters) {
1919
+ delete options.filters.brands;
1920
+ }
1921
+ this.brandsList[indexKey] = this.brandsList[indexKey] || brands || (yield this.fetchBrandsOnly(options));
1922
+ this.brandsList[indexKey] = this.brandsList[indexKey].filter(Boolean);
1923
+ if (options.filters) {
1924
+ options.filters = Object.assign(Object.assign({}, options.filters), { brands: filterBrands });
1925
+ }
1926
+ });
1927
+ }
1928
+ getBrandsList(indexKey) {
1929
+ return this.brandsList[indexKey];
1930
+ }
1931
+ buildIndexBrands(options) {
1932
+ if (options.category)
1933
+ return `category-${options.category.id}`;
1934
+ if (options.term)
1935
+ return `term-${options.term}`;
1936
+ if (options.profile)
1937
+ return `profile-${options.profile.join(',')}`;
1938
+ return '';
1939
+ }
1940
+ fetchBrandsOnly(options) {
1941
+ return __awaiter(this, void 0, void 0, function* () {
1942
+ return this.productCatalog.productRepository
1661
1943
  .findCatalog({
1662
1944
  fields: ['id'],
1663
- filters: Object.assign(Object.assign(Object.assign({}, (!isEmpty(productIds) ? { id: { operator: Where.IN, value: productIds } } : {})), { published: { operator: Where.EQUALS, value: true } }), this.buildFilterQuery((options === null || options === void 0 ? void 0 : options.filters) || {})),
1945
+ filters: {
1946
+ published: { operator: Where.EQUALS, value: true },
1947
+ },
1664
1948
  options: {
1665
1949
  distinct: ['brand'],
1666
1950
  },
1667
- }, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1668
- .then((result) => {
1669
- return result.distinct.brand;
1670
- });
1951
+ }, options.mainGender)
1952
+ .then((result) => result.distinct.brand);
1671
1953
  });
1672
1954
  }
1673
- setBrandsList(options, brands) {
1674
- var _a, _b;
1675
- return __awaiter(this, void 0, void 0, function* () {
1676
- const filterBrands = (_a = options.filters) === null || _a === void 0 ? void 0 : _a.brands;
1677
- if (isEmpty(brands))
1678
- (_b = options.filters) === null || _b === void 0 ? true : delete _b.brands;
1679
- this.brandsList[this.buildIndexBrands(options)] =
1680
- this.brandsList[this.buildIndexBrands(options)] || brands || (yield this.fetchBrandsOnly(options));
1681
- this.brandsList[this.buildIndexBrands(options)] = this.brandsList[this.buildIndexBrands(options)].filter(Boolean);
1682
- options.filters = Object.assign(Object.assign({}, options.filters), { brands: filterBrands });
1683
- });
1955
+ }
1956
+ BrandManagerHelper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: BrandManagerHelper, deps: [{ token: ProductCatalogFacade }], target: i0.ɵɵFactoryTarget.Injectable });
1957
+ BrandManagerHelper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: BrandManagerHelper });
1958
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: BrandManagerHelper, decorators: [{
1959
+ type: Injectable
1960
+ }], ctorParameters: function () { return [{ type: ProductCatalogFacade }]; } });
1961
+
1962
+ class CatalogFilterHelper {
1963
+ buildFilterQuery(filters) {
1964
+ var _a, _b, _c, _d, _e, _f, _g;
1965
+ const filterQuery = {};
1966
+ if ((_a = filters.clubDiscount) === null || _a === void 0 ? void 0 : _a.length) {
1967
+ set(filterQuery, 'price.subscriberDiscountPercentage', {
1968
+ operator: Where.IN,
1969
+ value: filters.clubDiscount,
1970
+ });
1971
+ }
1972
+ if ((_b = filters.brands) === null || _b === void 0 ? void 0 : _b.length) {
1973
+ filterQuery.brand = { operator: Where.IN, value: filters.brands };
1974
+ }
1975
+ if ((_c = filters.gender) === null || _c === void 0 ? void 0 : _c.length) {
1976
+ filterQuery.gender = { operator: Where.IN, value: filters.gender };
1977
+ }
1978
+ if (((_d = filters.prices) === null || _d === void 0 ? void 0 : _d.min) || ((_e = filters.prices) === null || _e === void 0 ? void 0 : _e.max)) {
1979
+ const priceField = filters.prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price';
1980
+ const priceFilters = [
1981
+ ...(filters.prices.min ? [{ operator: Where.GTE, value: Math.floor(filters.prices.min) }] : []),
1982
+ ...(filters.prices.max ? [{ operator: Where.LTE, value: Math.ceil(filters.prices.max) }] : []),
1983
+ ];
1984
+ set(filterQuery, priceField, priceFilters);
1985
+ }
1986
+ if (filters.rate) {
1987
+ filterQuery.rate = { operator: Where.GTE, value: filters.rate };
1988
+ }
1989
+ if ((_f = filters.tags) === null || _f === void 0 ? void 0 : _f.length) {
1990
+ filterQuery.tags = { operator: Where.LIKE, value: filters.tags };
1991
+ }
1992
+ if ((_g = filters.customOptions) === null || _g === void 0 ? void 0 : _g.length) {
1993
+ filterQuery.filters = { operator: Where.LIKE, value: filters.customOptions };
1994
+ }
1995
+ return filterQuery;
1996
+ }
1997
+ }
1998
+ CatalogFilterHelper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogFilterHelper, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1999
+ CatalogFilterHelper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogFilterHelper });
2000
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogFilterHelper, decorators: [{
2001
+ type: Injectable
2002
+ }] });
2003
+
2004
+ class CatalogSortHelper {
2005
+ buildSortQuery(sort) {
2006
+ if (!sort || sort === 'most-relevant')
2007
+ return {};
2008
+ switch (sort) {
2009
+ case 'best-sellers':
2010
+ return {
2011
+ shoppingCount: 'desc',
2012
+ rate: 'desc',
2013
+ stock: 'desc',
2014
+ name: 'asc',
2015
+ };
2016
+ case 'biggest-price':
2017
+ return {
2018
+ subscriberPrice: 'desc',
2019
+ rate: 'desc',
2020
+ shoppingCount: 'desc',
2021
+ };
2022
+ case 'lowest-price':
2023
+ return {
2024
+ subscriberPrice: 'asc',
2025
+ rate: 'desc',
2026
+ shoppingCount: 'desc',
2027
+ };
2028
+ case 'best-rating':
2029
+ return {
2030
+ rate: 'desc',
2031
+ shoppingCount: 'desc',
2032
+ stock: 'desc',
2033
+ name: 'asc',
2034
+ };
2035
+ case 'news':
2036
+ return { createdAt: 'desc' };
2037
+ case 'biggest-discount':
2038
+ return {
2039
+ subscriberDiscountPercentage: 'desc',
2040
+ rate: 'desc',
2041
+ shoppingCount: 'desc',
2042
+ };
2043
+ default:
2044
+ return {};
2045
+ }
2046
+ }
2047
+ }
2048
+ CatalogSortHelper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogSortHelper, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2049
+ CatalogSortHelper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogSortHelper });
2050
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogSortHelper, decorators: [{
2051
+ type: Injectable
2052
+ }] });
2053
+
2054
+ class ProductFieldsHelper {
2055
+ getStandardFields() {
2056
+ return [
2057
+ 'id',
2058
+ 'name',
2059
+ 'slug',
2060
+ 'images',
2061
+ 'miniatures',
2062
+ 'price',
2063
+ 'stock',
2064
+ 'published',
2065
+ 'CEST',
2066
+ 'EAN',
2067
+ 'NCM',
2068
+ 'brand',
2069
+ 'costPrice',
2070
+ 'hasVariants',
2071
+ 'isKit',
2072
+ 'sku',
2073
+ 'rate',
2074
+ 'tags',
2075
+ 'type',
2076
+ 'shoppingCount',
2077
+ 'gender',
2078
+ 'createdAt',
2079
+ 'label',
2080
+ 'outlet',
2081
+ 'group',
2082
+ ];
2083
+ }
2084
+ }
2085
+ ProductFieldsHelper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductFieldsHelper, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2086
+ ProductFieldsHelper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductFieldsHelper });
2087
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductFieldsHelper, decorators: [{
2088
+ type: Injectable
2089
+ }] });
2090
+
2091
+ class CatalogOperationsFacade {
2092
+ constructor(filterHelper, sortHelper, fieldsHelper) {
2093
+ this.filterHelper = filterHelper;
2094
+ this.sortHelper = sortHelper;
2095
+ this.fieldsHelper = fieldsHelper;
2096
+ }
2097
+ getFilterHelper() {
2098
+ return this.filterHelper;
2099
+ }
2100
+ getSortHelper() {
2101
+ return this.sortHelper;
2102
+ }
2103
+ getFieldsHelper() {
2104
+ return this.fieldsHelper;
2105
+ }
2106
+ }
2107
+ CatalogOperationsFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogOperationsFacade, deps: [{ token: CatalogFilterHelper }, { token: CatalogSortHelper }, { token: ProductFieldsHelper }], target: i0.ɵɵFactoryTarget.Injectable });
2108
+ CatalogOperationsFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogOperationsFacade });
2109
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogOperationsFacade, decorators: [{
2110
+ type: Injectable
2111
+ }], ctorParameters: function () { return [{ type: CatalogFilterHelper }, { type: CatalogSortHelper }, { type: ProductFieldsHelper }]; } });
2112
+
2113
+ class ProductManagementFacade {
2114
+ constructor(brandManager, productServices) {
2115
+ this.brandManager = brandManager;
2116
+ this.productServices = productServices;
2117
+ }
2118
+ getBrandManager() {
2119
+ return this.brandManager;
2120
+ }
2121
+ getProductServices() {
2122
+ return this.productServices;
2123
+ }
2124
+ }
2125
+ ProductManagementFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductManagementFacade, deps: [{ token: BrandManagerHelper }, { token: 'ProductServicesFacade' }], target: i0.ɵɵFactoryTarget.Injectable });
2126
+ ProductManagementFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductManagementFacade });
2127
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductManagementFacade, decorators: [{
2128
+ type: Injectable
2129
+ }], ctorParameters: function () {
2130
+ return [{ type: BrandManagerHelper }, { type: undefined, decorators: [{
2131
+ type: Inject,
2132
+ args: ['ProductServicesFacade']
2133
+ }] }];
2134
+ } });
2135
+
2136
+ class CatalogHelpersService {
2137
+ constructor(catalogOperations, productManagement) {
2138
+ this.catalogOperations = catalogOperations;
2139
+ this.productManagement = productManagement;
2140
+ }
2141
+ getFilterHelper() {
2142
+ return this.catalogOperations.getFilterHelper();
2143
+ }
2144
+ getSortHelper() {
2145
+ return this.catalogOperations.getSortHelper();
2146
+ }
2147
+ getFieldsHelper() {
2148
+ return this.catalogOperations.getFieldsHelper();
2149
+ }
2150
+ getBrandManager() {
2151
+ return this.productManagement.getBrandManager();
2152
+ }
2153
+ getProductServices() {
2154
+ return this.productManagement.getProductServices();
2155
+ }
2156
+ }
2157
+ CatalogHelpersService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogHelpersService, deps: [{ token: CatalogOperationsFacade }, { token: ProductManagementFacade }], target: i0.ɵɵFactoryTarget.Injectable });
2158
+ CatalogHelpersService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogHelpersService });
2159
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogHelpersService, decorators: [{
2160
+ type: Injectable
2161
+ }], ctorParameters: function () { return [{ type: CatalogOperationsFacade }, { type: ProductManagementFacade }]; } });
2162
+
2163
+ class CatalogRepositoryService {
2164
+ constructor(productCatalog, productServices) {
2165
+ this.productCatalog = productCatalog;
2166
+ this.productServices = productServices;
2167
+ }
2168
+ getProductCatalog() {
2169
+ return this.productCatalog;
2170
+ }
2171
+ getProductServices() {
2172
+ return this.productServices;
1684
2173
  }
1685
2174
  }
1686
- CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable });
1687
- CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1688
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
2175
+ CatalogRepositoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogRepositoryService, deps: [{ token: ProductCatalogFacade }, { token: 'ProductServicesFacade' }], target: i0.ɵɵFactoryTarget.Injectable });
2176
+ CatalogRepositoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogRepositoryService });
2177
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogRepositoryService, decorators: [{
1689
2178
  type: Injectable
1690
2179
  }], ctorParameters: function () {
1691
- return [{ type: undefined, decorators: [{
1692
- type: Inject,
1693
- args: ['ProductRepository']
1694
- }] }, { type: undefined, decorators: [{
1695
- type: Inject,
1696
- args: ['ProductStockNotificationRepository']
1697
- }] }, { type: undefined, decorators: [{
1698
- type: Inject,
1699
- args: ['CategoryRepository']
1700
- }] }, { type: undefined, decorators: [{
1701
- type: Inject,
1702
- args: [CATEGORY_STRUCTURE]
1703
- }] }, { type: i1$3.Shops, decorators: [{
1704
- type: Inject,
1705
- args: [DEFAULT_SHOP]
1706
- }] }, { type: undefined, decorators: [{
2180
+ return [{ type: ProductCatalogFacade }, { type: undefined, decorators: [{
1707
2181
  type: Inject,
1708
- args: ['ProductSearch']
2182
+ args: ['ProductServicesFacade']
1709
2183
  }] }];
1710
2184
  } });
1711
2185
 
1712
- class CategoryService {
1713
- constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1714
- this.productRepository = productRepository;
1715
- this.categoryRepository = categoryRepository;
1716
- this.categoryFilterRepository = categoryFilterRepository;
1717
- this.categoryStructureAdapter = categoryStructureAdapter;
2186
+ class CatalogService {
2187
+ constructor(searchContext, helpersService, shop) {
2188
+ this.searchContext = searchContext;
2189
+ this.helpersService = helpersService;
1718
2190
  this.shop = shop;
1719
2191
  }
1720
- fetchBrands(category, options, optionsCache) {
2192
+ fetchProducts(options, optionsCache) {
1721
2193
  return __awaiter(this, void 0, void 0, function* () {
1722
- const brands = yield this.productRepository
1723
- .findCatalog({
1724
- filters: yield this.categoryStructureAdapter.buildProductFilterByCategory(category),
1725
- fields: ['brand'],
1726
- }, (options === null || options === void 0 ? void 0 : options.mainGender) ? options === null || options === void 0 ? void 0 : options.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache)
1727
- .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => (Object.assign(Object.assign({}, brands), { [brand]: true })), {})));
1728
- return this.categoryRepository
1729
- .find({ filters: { brandCategory: true, shop: (options === null || options === void 0 ? void 0 : options.shop) || this.shop }, orderBy: { name: 'asc' } }, optionsCache)
1730
- .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
2194
+ this.validateRequest(options);
2195
+ const searchParams = this.buildSearchParams(options);
2196
+ const { data, count: total, maximum, minimal, distinct, } = yield this.searchContext.executeSearch(searchParams, this.shop, optionsCache);
2197
+ yield this.helpersService.getBrandManager().setBrandsList(searchParams, distinct === null || distinct === void 0 ? void 0 : distinct.brand);
2198
+ return this.buildResponse({
2199
+ data,
2200
+ total,
2201
+ maximum,
2202
+ minimal,
2203
+ searchParams,
2204
+ options,
2205
+ });
1731
2206
  });
1732
2207
  }
1733
- fetchFilterOptions(category, optionsCache) {
2208
+ addCustomerToStockNotification(params) {
1734
2209
  return __awaiter(this, void 0, void 0, function* () {
1735
- return yield this.categoryFilterRepository
1736
- .find({ filters: { categoryId: +category.id } }, optionsCache)
1737
- .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
2210
+ const { shop, productId, name, email } = params;
2211
+ const productServices = this.helpersService.getProductServices();
2212
+ return productServices.productStockNotificationRepository.addCustomerEmail({
2213
+ shop,
2214
+ productId,
2215
+ name,
2216
+ email,
2217
+ });
1738
2218
  });
1739
2219
  }
2220
+ validateRequest(options) {
2221
+ var _a, _b, _c;
2222
+ if (this.hasProfile(options) && ((_a = options.filters) === null || _a === void 0 ? void 0 : _a.customOptions)) {
2223
+ throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
2224
+ }
2225
+ if (this.hasProfile(options) && ((_b = options.filters) === null || _b === void 0 ? void 0 : _b.tags)) {
2226
+ throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
2227
+ }
2228
+ if (this.hasTerm(options) && ((_c = options.filters) === null || _c === void 0 ? void 0 : _c.customOptions)) {
2229
+ throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
2230
+ }
2231
+ }
2232
+ buildSearchParams(options) {
2233
+ const limits = this.buildLimitQuery(options);
2234
+ return {
2235
+ category: this.hasCategory(options) ? options.category : undefined,
2236
+ profile: this.hasProfile(options) ? options.profile : undefined,
2237
+ term: this.hasTerm(options) ? options.term : undefined,
2238
+ filters: options.filters,
2239
+ mainGender: options.mainGender,
2240
+ sort: options.sort,
2241
+ limits,
2242
+ };
2243
+ }
2244
+ buildResponse(params) {
2245
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2246
+ const { data, total, maximum, minimal, searchParams } = params;
2247
+ const limits = searchParams.limits;
2248
+ const indexKey = this.helpersService.getBrandManager().buildIndexBrands(searchParams);
2249
+ return {
2250
+ products: {
2251
+ data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)),
2252
+ total,
2253
+ },
2254
+ pages: Math.ceil(total / limits.limit),
2255
+ prices: {
2256
+ price: {
2257
+ min: +(((_b = (_a = minimal === null || minimal === void 0 ? void 0 : minimal.price) === null || _a === void 0 ? void 0 : _a.price) === null || _b === void 0 ? void 0 : _b.toFixed(2)) || 0),
2258
+ max: +(((_d = (_c = maximum === null || maximum === void 0 ? void 0 : maximum.price) === null || _c === void 0 ? void 0 : _c.price) === null || _d === void 0 ? void 0 : _d.toFixed(2)) || 0),
2259
+ },
2260
+ subscriberPrice: {
2261
+ min: +(((_f = (_e = minimal === null || minimal === void 0 ? void 0 : minimal.price) === null || _e === void 0 ? void 0 : _e.subscriberPrice) === null || _f === void 0 ? void 0 : _f.toFixed(2)) || 0),
2262
+ max: +(((_h = (_g = maximum === null || maximum === void 0 ? void 0 : maximum.price) === null || _g === void 0 ? void 0 : _g.subscriberPrice) === null || _h === void 0 ? void 0 : _h.toFixed(2)) || 0),
2263
+ },
2264
+ },
2265
+ brands: this.helpersService.getBrandManager().getBrandsList(indexKey),
2266
+ };
2267
+ }
2268
+ buildLimitQuery(options) {
2269
+ const limit = (options === null || options === void 0 ? void 0 : options.perPage) || 20;
2270
+ return {
2271
+ limit,
2272
+ offset: (((options === null || options === void 0 ? void 0 : options.page) || 1) - 1) * limit,
2273
+ };
2274
+ }
2275
+ hasProfile(options) {
2276
+ return 'profile' in options;
2277
+ }
2278
+ hasTerm(options) {
2279
+ return 'term' in options;
2280
+ }
2281
+ hasCategory(options) {
2282
+ return 'category' in options;
2283
+ }
1740
2284
  }
1741
- 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 });
1742
- CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1743
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
2285
+ CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: CatalogSearchContext }, { token: CatalogHelpersService }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
2286
+ CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
2287
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1744
2288
  type: Injectable
1745
2289
  }], ctorParameters: function () {
1746
- return [{ type: undefined, decorators: [{
1747
- type: Inject,
1748
- args: ['ProductRepository']
1749
- }] }, { type: undefined, decorators: [{
1750
- type: Inject,
1751
- args: ['CategoryRepository']
1752
- }] }, { type: undefined, decorators: [{
1753
- type: Inject,
1754
- args: ['CategoryFilterRepository']
1755
- }] }, { type: undefined, decorators: [{
1756
- type: Inject,
1757
- args: [CATEGORY_STRUCTURE]
1758
- }] }, { type: i1$3.Shops, decorators: [{
2290
+ return [{ type: CatalogSearchContext }, { type: CatalogHelpersService }, { type: i3.Shops, decorators: [{
1759
2291
  type: Inject,
1760
2292
  args: [DEFAULT_SHOP]
1761
2293
  }] }];
@@ -1780,15 +2312,14 @@ __decorate([
1780
2312
  ], CategoryWithTree.prototype, "children", void 0);
1781
2313
 
1782
2314
  class WishlistService {
1783
- constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productSearch, logRepository) {
2315
+ constructor(wishlistRepository, shop, logRepository) {
1784
2316
  this.wishlistRepository = wishlistRepository;
1785
2317
  this.shop = shop;
1786
- this.productRepository = productRepository;
1787
- this.productSearch = productSearch;
1788
2318
  this.logRepository = logRepository;
1789
- const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1790
- this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch);
1791
- this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
2319
+ }
2320
+ initializeServices(catalogServiceFacade, categoryServiceFacade) {
2321
+ this.catalogService = catalogServiceFacade.getCatalogService();
2322
+ this.categoryService = categoryServiceFacade.getCategoryService();
1792
2323
  }
1793
2324
  getCatalogService() {
1794
2325
  return this.catalogService;
@@ -1798,29 +2329,52 @@ class WishlistService {
1798
2329
  }
1799
2330
  create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1800
2331
  return __awaiter(this, void 0, void 0, function* () {
1801
- const data = {
1802
- slug: '',
1803
- name: title,
2332
+ const wishlistData = this.buildWishlistData({
2333
+ title,
1804
2334
  description,
1805
- metadatas: [
1806
- {
1807
- shop: this.shop,
1808
- title: `${userFullName} - ${title}`,
1809
- description: `${userFullName} - ${description}`,
1810
- },
1811
- ],
1812
- shop: this.shop,
1813
- shops: [this.shop],
1814
- personId,
1815
- personName: userFullName,
1816
- personPhoto: userPhoto,
1817
- brandCategory: false,
1818
2335
  published,
2336
+ userFullName,
2337
+ userPhoto,
1819
2338
  theme,
1820
2339
  bannerUrl,
1821
- personType: personType !== null && personType !== void 0 ? personType : PersonTypes.NONE,
1822
- personIsSubscriber: personIsSubscriber !== null && personIsSubscriber !== void 0 ? personIsSubscriber : false,
1823
- };
2340
+ personType,
2341
+ personIsSubscriber,
2342
+ personId,
2343
+ });
2344
+ const existingWishlist = yield this.findExistingWishlistByPersonId(personId);
2345
+ yield this.createWishlistLog(WishlistLogType.CREATE, wishlistData);
2346
+ if (existingWishlist)
2347
+ return existingWishlist;
2348
+ return this.createNewWishlist(wishlistData);
2349
+ });
2350
+ }
2351
+ buildWishlistData({ title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, personId, }) {
2352
+ return {
2353
+ slug: '',
2354
+ name: title,
2355
+ description,
2356
+ metadatas: [
2357
+ {
2358
+ shop: this.shop,
2359
+ title: `${userFullName} - ${title}`,
2360
+ description: `${userFullName} - ${description}`,
2361
+ },
2362
+ ],
2363
+ shop: this.shop,
2364
+ shops: [this.shop],
2365
+ personId,
2366
+ personName: userFullName,
2367
+ personPhoto: userPhoto,
2368
+ brandCategory: false,
2369
+ published,
2370
+ theme,
2371
+ bannerUrl,
2372
+ personType: personType !== null && personType !== void 0 ? personType : PersonTypes.NONE,
2373
+ personIsSubscriber: personIsSubscriber !== null && personIsSubscriber !== void 0 ? personIsSubscriber : false,
2374
+ };
2375
+ }
2376
+ findExistingWishlistByPersonId(personId) {
2377
+ return __awaiter(this, void 0, void 0, function* () {
1824
2378
  const hasWishlist = yield this.wishlistRepository
1825
2379
  .find({
1826
2380
  filters: {
@@ -1834,9 +2388,11 @@ class WishlistService {
1834
2388
  },
1835
2389
  })
1836
2390
  .then((res) => res.data);
1837
- yield this.createWishlistLog(WishlistLogType.CREATE, data);
1838
- if (hasWishlist.length)
1839
- return hasWishlist.at(0);
2391
+ return hasWishlist.length ? hasWishlist.at(0) : null;
2392
+ });
2393
+ }
2394
+ createNewWishlist(data) {
2395
+ return __awaiter(this, void 0, void 0, function* () {
1840
2396
  const newWishlist = yield this.wishlistRepository.create(data);
1841
2397
  yield this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
1842
2398
  return Wishlist.toInstance(Object.assign(Object.assign({}, newWishlist.toPlain()), { slug: newWishlist.id }));
@@ -1925,7 +2481,12 @@ class WishlistService {
1925
2481
  }
1926
2482
  findProductById(id) {
1927
2483
  return __awaiter(this, void 0, void 0, function* () {
1928
- return this.productRepository
2484
+ if (!this.catalogService) {
2485
+ throw new Error('CatalogService not initialized. Call initializeServices first.');
2486
+ }
2487
+ const helpersService = this.catalogService['helpersService'];
2488
+ const productServices = helpersService.getProductServices();
2489
+ return productServices.productRepository
1929
2490
  .find({
1930
2491
  fields: ['id', 'sku', 'EAN', 'name', 'brand'],
1931
2492
  filters: {
@@ -1941,58 +2502,72 @@ class WishlistService {
1941
2502
  case WishlistLogType.CREATE:
1942
2503
  case WishlistLogType.UPDATE:
1943
2504
  case WishlistLogType.DELETE:
1944
- yield this.logRepository.create({
1945
- collection: 'wishlist',
1946
- date: new Date(),
1947
- operation: WishlistLogType.CREATE ? 'CREATE' : WishlistLogType.UPDATE ? 'UPDATE' : 'DELETE',
1948
- documentId: wishlist.id,
1949
- document: {
1950
- id: wishlist.id,
1951
- shop: this.shop,
1952
- name: wishlist.name,
1953
- description: wishlist.description,
1954
- published: wishlist.published,
1955
- type: type,
1956
- personType: wishlist.personType,
1957
- personId: wishlist.personId,
1958
- personName: wishlist.personName,
1959
- personIsSubscriber: wishlist.personIsSubscriber,
1960
- },
1961
- });
2505
+ yield this.createWishlistOperationLog(type, wishlist);
1962
2506
  break;
1963
2507
  case WishlistLogType.ADD_PRODUCT:
1964
2508
  case WishlistLogType.REMOVE_PRODUCT:
1965
- yield this.logRepository.create({
1966
- collection: 'wishlist',
1967
- date: new Date(),
1968
- operation: 'UPDATE',
1969
- documentId: wishlist.id,
1970
- document: {
1971
- id: wishlist.id,
1972
- shop: this.shop,
1973
- name: wishlist.name,
1974
- description: wishlist.description,
1975
- published: wishlist.published,
1976
- type: type,
1977
- personType: wishlist.personType,
1978
- personId: wishlist.personId,
1979
- personName: wishlist.personName,
1980
- personIsSubscriber: wishlist.personIsSubscriber,
1981
- productId: product.id,
1982
- productEAN: product.EAN,
1983
- productSKU: product.sku,
1984
- productName: product.name,
1985
- productBrand: product.brand,
1986
- },
1987
- });
2509
+ yield this.createWishlistProductLog(type, wishlist, product);
1988
2510
  break;
1989
2511
  default:
1990
2512
  break;
1991
2513
  }
1992
2514
  });
1993
2515
  }
2516
+ createWishlistOperationLog(type, wishlist) {
2517
+ return __awaiter(this, void 0, void 0, function* () {
2518
+ const operation = this.getOperationTypeFromWishlistLogType(type);
2519
+ yield this.logRepository.create({
2520
+ collection: 'wishlist',
2521
+ date: new Date(),
2522
+ operation,
2523
+ documentId: wishlist.id,
2524
+ document: this.buildWishlistLogDocument(wishlist, type),
2525
+ });
2526
+ });
2527
+ }
2528
+ createWishlistProductLog(type, wishlist, product) {
2529
+ return __awaiter(this, void 0, void 0, function* () {
2530
+ yield this.logRepository.create({
2531
+ collection: 'wishlist',
2532
+ date: new Date(),
2533
+ operation: 'UPDATE',
2534
+ documentId: wishlist.id,
2535
+ document: Object.assign(Object.assign({}, this.buildWishlistLogDocument(wishlist, type)), this.buildProductLogData(product)),
2536
+ });
2537
+ });
2538
+ }
2539
+ getOperationTypeFromWishlistLogType(type) {
2540
+ if (type === WishlistLogType.CREATE)
2541
+ return 'CREATE';
2542
+ if (type === WishlistLogType.UPDATE)
2543
+ return 'UPDATE';
2544
+ return 'DELETE';
2545
+ }
2546
+ buildWishlistLogDocument(wishlist, type) {
2547
+ return {
2548
+ id: wishlist.id,
2549
+ shop: this.shop,
2550
+ name: wishlist.name,
2551
+ description: wishlist.description,
2552
+ published: wishlist.published,
2553
+ type: type,
2554
+ personType: wishlist.personType,
2555
+ personId: wishlist.personId,
2556
+ personName: wishlist.personName,
2557
+ personIsSubscriber: wishlist.personIsSubscriber,
2558
+ };
2559
+ }
2560
+ buildProductLogData(product) {
2561
+ return {
2562
+ productId: product.id,
2563
+ productEAN: product.EAN,
2564
+ productSKU: product.sku,
2565
+ productName: product.name,
2566
+ productBrand: product.brand,
2567
+ };
2568
+ }
1994
2569
  }
1995
- WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'ProductSearch' }, { token: 'LogRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
2570
+ WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'LogRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1996
2571
  WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
1997
2572
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
1998
2573
  type: Injectable
@@ -2000,47 +2575,55 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
2000
2575
  return [{ type: undefined, decorators: [{
2001
2576
  type: Inject,
2002
2577
  args: ['WishlistRepository']
2003
- }] }, { type: i1$3.Shops, decorators: [{
2578
+ }] }, { type: i3.Shops, decorators: [{
2004
2579
  type: Inject,
2005
2580
  args: [DEFAULT_SHOP]
2006
2581
  }] }, { type: undefined, decorators: [{
2007
2582
  type: Inject,
2008
- args: ['ProductRepository']
2009
- }] }, { type: undefined, decorators: [{
2010
- type: Inject,
2011
- args: ['CategoryFilterRepository']
2012
- }] }, { type: undefined, decorators: [{
2013
- type: Inject,
2014
- args: ['CategoryRepository']
2015
- }] }, { type: undefined, decorators: [{
2583
+ args: ['LogRepository']
2584
+ }] }];
2585
+ } });
2586
+
2587
+ class CouponRepositoriesFacade {
2588
+ constructor(couponRepository, orderRepository, categoryRepository) {
2589
+ this.couponRepository = couponRepository;
2590
+ this.orderRepository = orderRepository;
2591
+ this.categoryRepository = categoryRepository;
2592
+ }
2593
+ }
2594
+ CouponRepositoriesFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade, deps: [{ token: 'CouponRepository' }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
2595
+ CouponRepositoriesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade });
2596
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
2597
+ type: Injectable
2598
+ }], ctorParameters: function () {
2599
+ return [{ type: undefined, decorators: [{
2016
2600
  type: Inject,
2017
- args: ['ProductStockNotificationRepository']
2601
+ args: ['CouponRepository']
2018
2602
  }] }, { type: undefined, decorators: [{
2019
2603
  type: Inject,
2020
- args: ['ProductSearch']
2604
+ args: ['OrderRepository']
2021
2605
  }] }, { type: undefined, decorators: [{
2022
2606
  type: Inject,
2023
- args: ['LogRepository']
2607
+ args: ['CategoryRepository']
2024
2608
  }] }];
2025
2609
  } });
2026
2610
 
2027
2611
  class CouponService {
2028
- constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
2029
- this.couponRepository = couponRepository;
2030
- this.defaultShop = defaultShop;
2031
- this.orderRepository = orderRepository;
2032
- this.categoryRepository = categoryRepository;
2612
+ constructor(repositoriesFacade, configurationFacade) {
2613
+ this.repositoriesFacade = repositoriesFacade;
2614
+ this.configurationFacade = configurationFacade;
2033
2615
  this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
2034
2616
  }
2035
- checkCoupon(nickname, checkoutType, checkout, plan) {
2036
- return from(this.couponRepository
2617
+ checkCoupon(params) {
2618
+ const { nickname, checkoutType, checkout, plan } = params;
2619
+ return from(this.repositoriesFacade.couponRepository
2037
2620
  .find({
2038
2621
  filters: {
2039
2622
  nickname: { operator: Where.EQUALS, value: nickname },
2040
2623
  active: { operator: Where.EQUALS, value: true },
2041
2624
  },
2042
2625
  })
2043
- .then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
2626
+ .then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation({ coupon: couponValid, checkoutType, checkout, plan })), map((couponValidated) => couponValidated));
2044
2627
  }
2045
2628
  couponValidation(coupon, checkoutType) {
2046
2629
  return __awaiter(this, void 0, void 0, function* () {
@@ -2050,7 +2633,7 @@ class CouponService {
2050
2633
  throw 'Cupom inválido.';
2051
2634
  if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn).getTime() < new Date().getTime())
2052
2635
  throw 'Cupom expirado.';
2053
- const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
2636
+ const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.configurationFacade.defaultShop;
2054
2637
  if (!isInShop)
2055
2638
  throw 'Cupom inválido para loja.';
2056
2639
  const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
@@ -2059,46 +2642,87 @@ class CouponService {
2059
2642
  return coupon;
2060
2643
  });
2061
2644
  }
2062
- couponRulesValidation(coupon, checkoutType, checkout, plan) {
2063
- var _a;
2645
+ couponRulesValidation(params) {
2064
2646
  return __awaiter(this, void 0, void 0, function* () {
2647
+ const { coupon, checkoutType, checkout, plan } = params;
2065
2648
  if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
2066
- if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
2067
- throw 'Cupom inválido para sua assinatura.';
2068
- return coupon;
2649
+ return this.validateSubscriptionCoupon(coupon, plan);
2069
2650
  }
2070
- const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
2071
- if (!validUser)
2072
- throw 'Usuário não elegível.';
2651
+ return this.validateEcommerceCoupon(coupon, checkoutType, checkout);
2652
+ });
2653
+ }
2654
+ validateSubscriptionCoupon(coupon, plan) {
2655
+ if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase()) {
2656
+ throw 'Cupom inválido para sua assinatura.';
2657
+ }
2658
+ return coupon;
2659
+ }
2660
+ validateEcommerceCoupon(coupon, checkoutType, checkout) {
2661
+ return __awaiter(this, void 0, void 0, function* () {
2662
+ this.validateUserEligibility(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
2663
+ yield this.validateUsageLimits(coupon, checkoutType, checkout);
2664
+ yield this.validateProductEligibility(coupon, checkout);
2665
+ return coupon;
2666
+ });
2667
+ }
2668
+ validateUserEligibility(coupon, user) {
2669
+ const validUser = this.coupomUserValidation(coupon, user);
2670
+ if (!validUser)
2671
+ throw 'Usuário não elegível.';
2672
+ }
2673
+ validateUsageLimits(coupon, checkoutType, checkout) {
2674
+ return __awaiter(this, void 0, void 0, function* () {
2073
2675
  const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
2074
2676
  if (couponUseLimits.firstOrder) {
2075
- const ordersUser = yield this.getOrdersFromUser(checkout.user.email.toLocaleLowerCase());
2076
- if (couponUseLimits.firstOrder && ordersUser.length >= 1)
2077
- throw 'Limite de uso atingido';
2677
+ yield this.validateFirstOrderLimit(checkout.user.email);
2078
2678
  }
2079
2679
  if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
2080
- const ordersCoupon = yield this.getOrdersWithCoupon(coupon);
2081
- if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total)
2082
- throw 'Limite de uso atingido.';
2083
- if (couponUseLimits.limitedPerUser) {
2084
- const ordersWithUser = this.countOrdersWithUser(ordersCoupon, checkout.user.email);
2085
- if (ordersWithUser > 0)
2086
- throw 'Limite de uso por usuário atingido.';
2087
- }
2680
+ yield this.validateCouponUsageLimits(coupon, couponUseLimits, checkout.user.email);
2681
+ }
2682
+ });
2683
+ }
2684
+ validateFirstOrderLimit(userEmail) {
2685
+ return __awaiter(this, void 0, void 0, function* () {
2686
+ const ordersUser = yield this.getOrdersFromUser(userEmail.toLocaleLowerCase());
2687
+ if (ordersUser.length >= 1)
2688
+ throw 'Limite de uso atingido';
2689
+ });
2690
+ }
2691
+ validateCouponUsageLimits(coupon, couponUseLimits, userEmail) {
2692
+ return __awaiter(this, void 0, void 0, function* () {
2693
+ const ordersCoupon = yield this.getOrdersWithCoupon(coupon);
2694
+ if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total) {
2695
+ throw 'Limite de uso atingido.';
2696
+ }
2697
+ if (couponUseLimits.limitedPerUser) {
2698
+ const ordersWithUser = this.countOrdersWithUser(ordersCoupon, userEmail);
2699
+ if (ordersWithUser > 0)
2700
+ throw 'Limite de uso por usuário atingido.';
2088
2701
  }
2702
+ });
2703
+ }
2704
+ validateProductEligibility(coupon, checkout) {
2705
+ return __awaiter(this, void 0, void 0, function* () {
2089
2706
  const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
2090
2707
  if (!hasProductCategories)
2091
2708
  throw 'Seu carrinho não possui produtos elegíveis para desconto.';
2092
2709
  const hasMinSubTotal = yield this.hasMinSubTotal(coupon, checkout);
2093
2710
  if (!hasMinSubTotal) {
2094
- if ((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length) {
2095
- throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido na(s) categoria(s) elegíveis para o desconto.`;
2096
- }
2097
- throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido.`;
2711
+ this.throwMinSubTotalError(coupon);
2098
2712
  }
2099
- return coupon;
2100
2713
  });
2101
2714
  }
2715
+ throwMinSubTotalError(coupon) {
2716
+ var _a;
2717
+ const formattedValue = Intl.NumberFormat('pt-BR', {
2718
+ style: 'currency',
2719
+ currency: 'BRL',
2720
+ }).format(coupon.minSubTotalValue);
2721
+ if ((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length) {
2722
+ throw `Valor mínimo de ${formattedValue} não atingido na(s) categoria(s) elegíveis para o desconto.`;
2723
+ }
2724
+ throw `Valor mínimo de ${formattedValue} não atingido.`;
2725
+ }
2102
2726
  calcDiscountSubscription(coupon, checkout) {
2103
2727
  let discount = 0;
2104
2728
  if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
@@ -2121,7 +2745,7 @@ class CouponService {
2121
2745
  hasProductCategories(coupon, checkout) {
2122
2746
  var _a, _b;
2123
2747
  return __awaiter(this, void 0, void 0, function* () {
2124
- if (!coupon.productsCategories || !((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length)) {
2748
+ if (!((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length)) {
2125
2749
  return true;
2126
2750
  }
2127
2751
  const couponCategories = yield this.getCouponCategoriesId(coupon.productsCategories);
@@ -2129,17 +2753,17 @@ class CouponService {
2129
2753
  var _a;
2130
2754
  if (item.isGift)
2131
2755
  return false;
2132
- if (!item.categories || !((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length))
2756
+ if (!((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length))
2133
2757
  return true;
2134
2758
  return item.categories.some((c) => couponCategories.some((cat) => cat == c));
2135
2759
  });
2136
- return hasCategories.length ? true : false;
2760
+ return (hasCategories === null || hasCategories === void 0 ? void 0 : hasCategories.length) ? true : false;
2137
2761
  });
2138
2762
  }
2139
2763
  coupomUserValidation(coupon, user) {
2140
2764
  if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
2141
2765
  return true;
2142
- let userTypes = [];
2766
+ const userTypes = [];
2143
2767
  if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
2144
2768
  this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
2145
2769
  userTypes.push(Exclusivities.COLLABORATORS);
@@ -2162,11 +2786,11 @@ class CouponService {
2162
2786
  return __awaiter(this, void 0, void 0, function* () {
2163
2787
  const couponCategories = [];
2164
2788
  for (let index = 0; index < productsCategories.length; index++) {
2165
- const category = yield this.categoryRepository.get({
2789
+ const category = yield this.repositoriesFacade.categoryRepository.get({
2166
2790
  id: productsCategories[index],
2167
2791
  });
2168
2792
  if (category) {
2169
- const children = yield this.categoryRepository.getChildren(parseInt(productsCategories[index]));
2793
+ const children = yield this.repositoriesFacade.categoryRepository.getChildren(parseInt(productsCategories[index]));
2170
2794
  couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
2171
2795
  }
2172
2796
  }
@@ -2178,7 +2802,7 @@ class CouponService {
2178
2802
  return __awaiter(this, void 0, void 0, function* () {
2179
2803
  let lineItensDiscount = [];
2180
2804
  const couponCategories = yield this.getCouponCategoriesId(productsCategories);
2181
- if (productsCategories && productsCategories.length) {
2805
+ if (productsCategories === null || productsCategories === void 0 ? void 0 : productsCategories.length) {
2182
2806
  lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((item) => {
2183
2807
  var _a;
2184
2808
  if (item.isGift)
@@ -2197,15 +2821,15 @@ class CouponService {
2197
2821
  }
2198
2822
  calcCheckoutSubtotal(lineItens, user) {
2199
2823
  return ((lineItens === null || lineItens === void 0 ? void 0 : lineItens.filter((item) => !item.isGift).reduce((acc, curr) => {
2200
- var _a;
2201
- return (user === null || user === void 0 ? void 0 : user.isSubscriber) && curr.price.subscriberPrice
2202
- ? acc + ((_a = curr.price) === null || _a === void 0 ? void 0 : _a.subscriberPrice) * curr.quantity
2824
+ var _a, _b;
2825
+ return (user === null || user === void 0 ? void 0 : user.isSubscriber) && ((_a = curr.price) === null || _a === void 0 ? void 0 : _a.subscriberPrice)
2826
+ ? acc + ((_b = curr.price) === null || _b === void 0 ? void 0 : _b.subscriberPrice) * curr.quantity
2203
2827
  : acc + curr.pricePaid * curr.quantity;
2204
2828
  }, 0)) || 0);
2205
2829
  }
2206
2830
  getOrdersWithCoupon(coupon) {
2207
2831
  return __awaiter(this, void 0, void 0, function* () {
2208
- return yield this.orderRepository
2832
+ return yield this.repositoriesFacade.orderRepository
2209
2833
  .find({
2210
2834
  filters: {
2211
2835
  coupon: { id: coupon.id },
@@ -2217,7 +2841,7 @@ class CouponService {
2217
2841
  }
2218
2842
  getOrdersFromUser(email) {
2219
2843
  return __awaiter(this, void 0, void 0, function* () {
2220
- return yield this.orderRepository
2844
+ return yield this.repositoriesFacade.orderRepository
2221
2845
  .find({
2222
2846
  filters: {
2223
2847
  user: { email: { operator: Where.EQUALS, value: email } },
@@ -2238,7 +2862,7 @@ class CouponService {
2238
2862
  coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
2239
2863
  couponUseLimits = coupon.useLimits.non_subscriber;
2240
2864
  else
2241
- couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
2865
+ couponUseLimits = (user === null || user === void 0 ? void 0 : user.isSubscriber) ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
2242
2866
  }
2243
2867
  else {
2244
2868
  couponUseLimits = coupon.useLimits.subscription;
@@ -2246,28 +2870,14 @@ class CouponService {
2246
2870
  return couponUseLimits;
2247
2871
  }
2248
2872
  }
2249
- 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 });
2873
+ CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: CouponRepositoriesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable });
2250
2874
  CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
2251
2875
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
2252
2876
  type: Injectable,
2253
2877
  args: [{
2254
2878
  providedIn: 'root',
2255
2879
  }]
2256
- }], ctorParameters: function () {
2257
- return [{ type: undefined, decorators: [{
2258
- type: Inject,
2259
- args: ['CouponRepository']
2260
- }] }, { type: i1$3.Shops, decorators: [{
2261
- type: Inject,
2262
- args: [DEFAULT_SHOP]
2263
- }] }, { type: undefined, decorators: [{
2264
- type: Inject,
2265
- args: ['OrderRepository']
2266
- }] }, { type: undefined, decorators: [{
2267
- type: Inject,
2268
- args: ['CategoryRepository']
2269
- }] }];
2270
- } });
2880
+ }], ctorParameters: function () { return [{ type: CouponRepositoriesFacade }, { type: ConfigurationFacade }]; } });
2271
2881
 
2272
2882
  class CheckoutSubscriptionService {
2273
2883
  constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
@@ -2283,9 +2893,14 @@ class CheckoutSubscriptionService {
2283
2893
  clearCheckoutSubscriptionFromSession() {
2284
2894
  return this.dataPersistence.remove('checkoutSubscriptionId');
2285
2895
  }
2286
- checkCoupon(nickname, userEmail) {
2896
+ checkCoupon(nickname, _userEmail) {
2287
2897
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
2288
- .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
2898
+ .checkCoupon({
2899
+ nickname,
2900
+ checkoutType: CheckoutTypes.SUBSCRIPTION,
2901
+ checkout,
2902
+ plan: checkout.subscriptionPlan.name,
2903
+ })
2289
2904
  .pipe()));
2290
2905
  }
2291
2906
  calcDiscountSubscription(coupon) {
@@ -2317,33 +2932,55 @@ class UtilHelper {
2317
2932
  static createSlug(name) {
2318
2933
  return name
2319
2934
  .toLowerCase()
2320
- .replace(/\s+/g, '-') // Replace spaces with -
2321
- .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
2322
- .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
2323
- .replace(/[ìíïî]/g, 'i') // Replace spaces with -
2324
- .replace(/[õòóöô]/g, 'o') // Replace spaces with -
2325
- .replace(/[ùúüû]/g, 'u') // Replace spaces with -
2326
- .replace(/[ñ]/g, 'n') // Replace spaces with -
2327
- .replace(/[ç]/g, 'c') // Replace spaces with -
2328
- .replace(/[&]/g, 'and') // Replace spaces with -
2329
- .replace(/[^\w\-]+/g, '') // Remove all non-word chars
2330
- .replace(/\-\-+/g, '-'); // Replace multiple - with single -
2935
+ .replace(/\s+/g, '-')
2936
+ .replace(/[ãàáäâ]/g, 'a')
2937
+ .replace(/[ẽèéëê]/g, 'e')
2938
+ .replace(/[ìíïî]/g, 'i')
2939
+ .replace(/[õòóöô]/g, 'o')
2940
+ .replace(/[ùúüû]/g, 'u')
2941
+ .replace(/[ñ]/g, 'n')
2942
+ .replace(/[ç]/g, 'c')
2943
+ .replace(/[&]/g, 'and')
2944
+ .replace(/[^\w-]+/g, '')
2945
+ .replace(/--+/g, '-');
2946
+ }
2947
+ }
2948
+
2949
+ class HomeShopRepositoriesFacade {
2950
+ constructor(categoryRepository, homeRepository, productRepository) {
2951
+ this.categoryRepository = categoryRepository;
2952
+ this.homeRepository = homeRepository;
2953
+ this.productRepository = productRepository;
2331
2954
  }
2332
2955
  }
2956
+ HomeShopRepositoriesFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopRepositoriesFacade, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
2957
+ HomeShopRepositoriesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopRepositoriesFacade });
2958
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopRepositoriesFacade, decorators: [{
2959
+ type: Injectable
2960
+ }], ctorParameters: function () {
2961
+ return [{ type: undefined, decorators: [{
2962
+ type: Inject,
2963
+ args: ['CategoryRepository']
2964
+ }] }, { type: undefined, decorators: [{
2965
+ type: Inject,
2966
+ args: ['HomeRepository']
2967
+ }] }, { type: undefined, decorators: [{
2968
+ type: Inject,
2969
+ args: ['ProductRepository']
2970
+ }] }];
2971
+ } });
2333
2972
 
2334
2973
  class HomeShopService {
2335
2974
  get homeId() {
2336
- if (this.defaultShop === Shops.GLAMSHOP)
2975
+ if (this.configurationFacade.defaultShop === Shops.GLAMSHOP)
2337
2976
  return 'glamshop';
2338
- if (this.defaultShop === Shops.MENSMARKET)
2977
+ if (this.configurationFacade.defaultShop === Shops.MENSMARKET)
2339
2978
  return 'mens_market';
2340
2979
  return null;
2341
2980
  }
2342
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
2343
- this.categoryRepository = categoryRepository;
2344
- this.homeRepository = homeRepository;
2345
- this.productRepository = productRepository;
2346
- this.defaultShop = defaultShop;
2981
+ constructor(repositoriesFacade, configurationFacade) {
2982
+ this.repositoriesFacade = repositoriesFacade;
2983
+ this.configurationFacade = configurationFacade;
2347
2984
  this.buildCategoryGroupWithRequiredData = (group) => {
2348
2985
  var _a, _b;
2349
2986
  return ({
@@ -2397,14 +3034,20 @@ class HomeShopService {
2397
3034
  getMinValueForFreeShipping() {
2398
3035
  return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
2399
3036
  }
2400
- getDiscoverProducts(gender) {
2401
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories, this.defaultShop)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
3037
+ getDiscoverProducts(_gender) {
3038
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.repositoriesFacade.categoryRepository.getCategoriesForHome({
3039
+ categoryIds: home.discoverCategories,
3040
+ shop: this.configurationFacade.defaultShop,
3041
+ })).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2402
3042
  }
2403
- getFeaturedProducts(gender) {
2404
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories, this.defaultShop)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
3043
+ getFeaturedProducts(_gender) {
3044
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.repositoriesFacade.categoryRepository.getCategoriesForHome({
3045
+ categoryIds: home.featuredCategories,
3046
+ shop: this.configurationFacade.defaultShop,
3047
+ })).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2405
3048
  }
2406
3049
  getVerticalProducts(gender) {
2407
- 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({
3050
+ return this.getHomeConfiguration().pipe(concatMap((home) => forkJoin(home.verticalCarousels.filter(Boolean).map((id) => from(this.repositoriesFacade.categoryRepository.get({ id })).pipe(concatMap((category) => from(this.repositoriesFacade.productRepository.find({
2408
3051
  filters: Object.assign({ categories: { operator: Where.IN, value: [category.id] } }, (gender ? { tags: { operator: Where.IN, value: [gender] } } : {})),
2409
3052
  limits: { limit: 12 },
2410
3053
  })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
@@ -2413,8 +3056,8 @@ class HomeShopService {
2413
3056
  return of(this.homeConfiguration).pipe(concatMap((home) => home
2414
3057
  ? of(home)
2415
3058
  : !this.homeId
2416
- ? throwError(new RequiredArgumentError(['homeId']))
2417
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
3059
+ ? throwError(() => new RequiredArgumentError(['homeId']))
3060
+ : from(this.repositoriesFacade.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
2418
3061
  }
2419
3062
  saveHomeData(homeData) {
2420
3063
  const data = {
@@ -2422,7 +3065,7 @@ class HomeShopService {
2422
3065
  expiresAt: add(new Date(), { hours: 1 }),
2423
3066
  data: homeData,
2424
3067
  };
2425
- return from(this.homeRepository.update({
3068
+ return from(this.repositoriesFacade.homeRepository.update({
2426
3069
  id: this.homeId,
2427
3070
  data,
2428
3071
  })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
@@ -2431,25 +3074,11 @@ class HomeShopService {
2431
3074
  return this.homeId === 'mens_market' ? 'masculino' : undefined;
2432
3075
  }
2433
3076
  }
2434
- 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 });
3077
+ HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, deps: [{ token: HomeShopRepositoriesFacade }, { token: ConfigurationFacade }], target: i0.ɵɵFactoryTarget.Injectable });
2435
3078
  HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
2436
3079
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
2437
3080
  type: Injectable
2438
- }], ctorParameters: function () {
2439
- return [{ type: undefined, decorators: [{
2440
- type: Inject,
2441
- args: ['CategoryRepository']
2442
- }] }, { type: undefined, decorators: [{
2443
- type: Inject,
2444
- args: ['HomeRepository']
2445
- }] }, { type: undefined, decorators: [{
2446
- type: Inject,
2447
- args: ['ProductRepository']
2448
- }] }, { type: i1$3.Shops, decorators: [{
2449
- type: Inject,
2450
- args: [DEFAULT_SHOP]
2451
- }] }];
2452
- } });
3081
+ }], ctorParameters: function () { return [{ type: HomeShopRepositoriesFacade }, { type: ConfigurationFacade }]; } });
2453
3082
 
2454
3083
  class OrderService {
2455
3084
  constructor(angularFirestore, orderRepository) {
@@ -2469,7 +3098,7 @@ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version
2469
3098
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
2470
3099
  type: Injectable
2471
3100
  }], ctorParameters: function () {
2472
- return [{ type: i1$1.Firestore }, { type: i1$3.OrderFirestoreRepository, decorators: [{
3101
+ return [{ type: i1$1.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
2473
3102
  type: Inject,
2474
3103
  args: ['OrderRepository']
2475
3104
  }] }];
@@ -2480,28 +3109,44 @@ class AngularConnectModule {
2480
3109
  return {
2481
3110
  ngModule: AngularConnectModule,
2482
3111
  providers: [
2483
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
2484
- { provide: APP_CHECK_PROVIDER, useValue: options.appCheckProvider },
2485
- {
2486
- provide: CATEGORY_STRUCTURE,
2487
- useClass: isNil(options === null || options === void 0 ? void 0 : options.oldCategoryStructure) || (options === null || options === void 0 ? void 0 : options.oldCategoryStructure)
2488
- ? OldCategoryStructureAdapter
2489
- : NewCategoryStructureAdapter,
2490
- },
2491
- { provide: PERSISTENCE_PROVIDER, useClass: (options === null || options === void 0 ? void 0 : options.persistenceProvider) || CookieDataPersistence },
2492
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2493
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
2494
- ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2495
- ...(isNil(options === null || options === void 0 ? void 0 : options.vertexConfig) ? [] : [{ provide: VERTEX_CONFIG, useValue: options.vertexConfig }]),
2496
- ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2497
- ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2498
- ...(isNil(options === null || options === void 0 ? void 0 : options.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
3112
+ ...this.buildCoreProviders(nameOrConfig, options),
3113
+ ...this.buildConditionalProviders(defaultShop, options),
2499
3114
  ],
2500
3115
  };
2501
3116
  }
3117
+ static buildCoreProviders(nameOrConfig, options) {
3118
+ return [
3119
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
3120
+ { provide: APP_CHECK_PROVIDER, useValue: options.appCheckProvider },
3121
+ {
3122
+ provide: CATEGORY_STRUCTURE,
3123
+ useClass: this.selectCategoryStructureAdapter(options.oldCategoryStructure),
3124
+ },
3125
+ { provide: PERSISTENCE_PROVIDER, useClass: (options === null || options === void 0 ? void 0 : options.persistenceProvider) || CookieDataPersistence },
3126
+ ];
3127
+ }
3128
+ static buildConditionalProviders(defaultShop, options) {
3129
+ return [
3130
+ ...this.createProviderIfExists(DEFAULT_SHOP, defaultShop),
3131
+ ...this.createProviderIfExists(FIREBASE_OPTIONS, options.firebase),
3132
+ ...this.createProviderIfExists(ES_CONFIG, options.elasticSearch),
3133
+ ...this.createProviderIfExists(VERTEX_CONFIG, options.vertexConfig),
3134
+ ...this.createProviderIfExists(HASURA_OPTIONS, options.hasura),
3135
+ ...this.createProviderIfExists(BACKEND_URL, options.backendUrl),
3136
+ ...this.createProviderIfExists(STORAGE_BASE_URL, options.storageBaseUrl),
3137
+ ];
3138
+ }
3139
+ static selectCategoryStructureAdapter(oldCategoryStructure) {
3140
+ return isNil(oldCategoryStructure) || oldCategoryStructure
3141
+ ? OldCategoryStructureAdapter
3142
+ : NewCategoryStructureAdapter;
3143
+ }
3144
+ static createProviderIfExists(token, value) {
3145
+ return isNil(value) ? [] : [{ provide: token, useValue: value }];
3146
+ }
2502
3147
  }
2503
3148
  AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2504
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.AppCheckModule, i3.StorageModule, AngularElasticSeachModule,
3149
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$3.FirebaseAppModule, i2.AppCheckModule, i3$1.StorageModule, AngularElasticSeachModule,
2505
3150
  AngularVertexSeachModule,
2506
3151
  AngularFirebaseAuthModule,
2507
3152
  AngularFirestoreModule,
@@ -2517,6 +3162,42 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
2517
3162
  HomeShopService,
2518
3163
  OrderService,
2519
3164
  WishlistService,
3165
+ ConfigurationFacade,
3166
+ CartServicesFacade,
3167
+ CheckoutRepositoriesFacade,
3168
+ CheckoutDependenciesFacade,
3169
+ CategoryRepositoryFacade,
3170
+ ProductCatalogFacade,
3171
+ CatalogServiceFacade,
3172
+ CategoryServiceFacade,
3173
+ CatalogStrategiesFacade,
3174
+ CatalogOperationsFacade,
3175
+ ProductManagementFacade,
3176
+ {
3177
+ provide: 'ProductServicesFacade',
3178
+ useFactory: (productStockNotificationRepository, categoryRepository, productSearch) => ({
3179
+ productStockNotificationRepository,
3180
+ categoryRepository,
3181
+ productSearch,
3182
+ }),
3183
+ deps: ['ProductStockNotificationRepository', 'CategoryRepository', 'ProductSearch'],
3184
+ },
3185
+ CatalogFilterHelper,
3186
+ CatalogSortHelper,
3187
+ ProductFieldsHelper,
3188
+ BrandManagerHelper,
3189
+ CatalogRepositoryService,
3190
+ CatalogHelpersService,
3191
+ CategorySearchStrategy,
3192
+ TermSearchStrategy,
3193
+ ProfileSearchStrategy,
3194
+ {
3195
+ provide: CatalogSearchContext,
3196
+ useFactory: (categoryStrategy, termStrategy, profileStrategy) => {
3197
+ return new CatalogSearchContext(categoryStrategy, termStrategy, profileStrategy);
3198
+ },
3199
+ deps: [CategorySearchStrategy, TermSearchStrategy, ProfileSearchStrategy],
3200
+ },
2520
3201
  {
2521
3202
  provide: UpdateUserImage,
2522
3203
  useFactory: (userRepository, fileUploader) => {
@@ -2535,6 +3216,8 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
2535
3216
  provide: 'ProductSearch',
2536
3217
  useExisting: ProductsVertexSearch,
2537
3218
  },
3219
+ CouponRepositoriesFacade,
3220
+ HomeShopRepositoriesFacade,
2538
3221
  ], imports: [provideFirebaseApp((injector) => {
2539
3222
  const appName = injector.get(FIREBASE_APP_NAME);
2540
3223
  try {
@@ -2621,6 +3304,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
2621
3304
  HomeShopService,
2622
3305
  OrderService,
2623
3306
  WishlistService,
3307
+ ConfigurationFacade,
3308
+ CartServicesFacade,
3309
+ CheckoutRepositoriesFacade,
3310
+ CheckoutDependenciesFacade,
3311
+ CategoryRepositoryFacade,
3312
+ ProductCatalogFacade,
3313
+ CatalogServiceFacade,
3314
+ CategoryServiceFacade,
3315
+ CatalogStrategiesFacade,
3316
+ CatalogOperationsFacade,
3317
+ ProductManagementFacade,
3318
+ {
3319
+ provide: 'ProductServicesFacade',
3320
+ useFactory: (productStockNotificationRepository, categoryRepository, productSearch) => ({
3321
+ productStockNotificationRepository,
3322
+ categoryRepository,
3323
+ productSearch,
3324
+ }),
3325
+ deps: ['ProductStockNotificationRepository', 'CategoryRepository', 'ProductSearch'],
3326
+ },
3327
+ CatalogFilterHelper,
3328
+ CatalogSortHelper,
3329
+ ProductFieldsHelper,
3330
+ BrandManagerHelper,
3331
+ CatalogRepositoryService,
3332
+ CatalogHelpersService,
3333
+ CategorySearchStrategy,
3334
+ TermSearchStrategy,
3335
+ ProfileSearchStrategy,
3336
+ {
3337
+ provide: CatalogSearchContext,
3338
+ useFactory: (categoryStrategy, termStrategy, profileStrategy) => {
3339
+ return new CatalogSearchContext(categoryStrategy, termStrategy, profileStrategy);
3340
+ },
3341
+ deps: [CategorySearchStrategy, TermSearchStrategy, ProfileSearchStrategy],
3342
+ },
2624
3343
  {
2625
3344
  provide: UpdateUserImage,
2626
3345
  useFactory: (userRepository, fileUploader) => {
@@ -2639,6 +3358,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
2639
3358
  provide: 'ProductSearch',
2640
3359
  useExisting: ProductsVertexSearch,
2641
3360
  },
3361
+ CouponRepositoriesFacade,
3362
+ HomeShopRepositoriesFacade,
2642
3363
  ],
2643
3364
  }]
2644
3365
  }] });