@infrab4a/connect-angular 4.20.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.
- package/angular-connect.module.d.ts +4 -0
- package/esm2020/angular-connect.module.mjs +119 -17
- package/esm2020/angular-firestore.module.mjs +16 -2
- package/esm2020/angular-hasura-graphql.module.mjs +1 -1
- package/esm2020/consts/backend-url.const.mjs +1 -1
- package/esm2020/interfaces/catalog-strategies.interface.mjs +2 -0
- package/esm2020/interfaces/category-facades.interface.mjs +2 -0
- package/esm2020/interfaces/index.mjs +3 -0
- package/esm2020/persistence/cookie-data-persistence.mjs +1 -1
- package/esm2020/services/cart/cart-services.facade.mjs +21 -0
- package/esm2020/services/cart/index.mjs +2 -0
- package/esm2020/services/cart.service.mjs +25 -38
- package/esm2020/services/catalog/adapters/new-category-structure.adapter.mjs +1 -1
- package/esm2020/services/catalog/adapters/old-category-structure.adapter.mjs +1 -1
- package/esm2020/services/catalog/catalog.service.mjs +80 -294
- package/esm2020/services/catalog/category.service.mjs +15 -27
- package/esm2020/services/catalog/context/catalog-search.context.mjs +40 -0
- package/esm2020/services/catalog/facades/catalog-service.facade.mjs +32 -0
- package/esm2020/services/catalog/facades/catalog-strategies.facade.mjs +17 -0
- package/esm2020/services/catalog/facades/category-repository.facade.mjs +20 -0
- package/esm2020/services/catalog/facades/category-service.facade.mjs +30 -0
- package/esm2020/services/catalog/facades/index.mjs +6 -0
- package/esm2020/services/catalog/facades/product-catalog.facade.mjs +21 -0
- package/esm2020/services/catalog/helpers/brand-manager.helper.mjs +57 -0
- package/esm2020/services/catalog/helpers/catalog-filter.helper.mjs +44 -0
- package/esm2020/services/catalog/helpers/catalog-sort.helper.mjs +52 -0
- package/esm2020/services/catalog/helpers/index.mjs +5 -0
- package/esm2020/services/catalog/helpers/product-fields.helper.mjs +39 -0
- package/esm2020/services/catalog/models/category-with-tree.model.mjs +1 -1
- package/esm2020/services/catalog/services/catalog-helpers.service.mjs +33 -0
- package/esm2020/services/catalog/services/catalog-operations.facade.mjs +26 -0
- package/esm2020/services/catalog/services/catalog-repository.service.mjs +25 -0
- package/esm2020/services/catalog/services/index.mjs +5 -0
- package/esm2020/services/catalog/services/product-management.facade.mjs +25 -0
- package/esm2020/services/catalog/strategies/category-search.strategy.mjs +133 -0
- package/esm2020/services/catalog/strategies/index.mjs +4 -0
- package/esm2020/services/catalog/strategies/profile-search.strategy.mjs +42 -0
- package/esm2020/services/catalog/strategies/term-search.strategy.mjs +126 -0
- package/esm2020/services/catalog/strategies/types/strategy-params.type.mjs +2 -0
- package/esm2020/services/catalog/types/fetch-products-options.type.mjs +2 -0
- package/esm2020/services/catalog/types/fetch-products-params.type.mjs +2 -0
- package/esm2020/services/catalog/types/fetch-products-response.type.mjs +2 -0
- package/esm2020/services/catalog/types/index.mjs +5 -1
- package/esm2020/services/catalog/types/method-params.type.mjs +2 -0
- package/esm2020/services/catalog/wishlist.service.mjs +92 -72
- package/esm2020/services/checkout/checkout-dependencies.facade.mjs +20 -0
- package/esm2020/services/checkout/checkout-repositories.facade.mjs +20 -0
- package/esm2020/services/checkout/index.mjs +3 -0
- package/esm2020/services/checkout-subscription.service.mjs +8 -3
- package/esm2020/services/checkout.service.mjs +34 -50
- package/esm2020/services/coupon/coupon-repositories.facade.mjs +24 -0
- package/esm2020/services/coupon/index.mjs +2 -0
- package/esm2020/services/coupon/types/coupon-params.type.mjs +2 -0
- package/esm2020/services/coupon.service.mjs +79 -59
- package/esm2020/services/helpers/util.helper.mjs +12 -12
- package/esm2020/services/home-shop/home-shop-repositories.facade.mjs +24 -0
- package/esm2020/services/home-shop/index.mjs +2 -0
- package/esm2020/services/home-shop.service.mjs +27 -33
- package/esm2020/services/shared/configuration.facade.mjs +29 -0
- package/esm2020/services/shared/index.mjs +2 -0
- package/fesm2015/infrab4a-connect-angular.mjs +1286 -551
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +1198 -510
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/interfaces/catalog-strategies.interface.d.ts +31 -0
- package/interfaces/category-facades.interface.d.ts +6 -0
- package/interfaces/index.d.ts +2 -0
- package/package.json +5 -3
- package/services/cart/cart-services.facade.d.ts +12 -0
- package/services/cart/index.d.ts +1 -0
- package/services/cart.service.d.ts +6 -11
- package/services/catalog/catalog.service.d.ts +11 -83
- package/services/catalog/category.service.d.ts +5 -7
- package/services/catalog/context/catalog-search.context.d.ts +14 -0
- package/services/catalog/facades/catalog-service.facade.d.ts +15 -0
- package/services/catalog/facades/catalog-strategies.facade.d.ts +10 -0
- package/services/catalog/facades/category-repository.facade.d.ts +9 -0
- package/services/catalog/facades/category-service.facade.d.ts +15 -0
- package/services/catalog/facades/index.d.ts +5 -0
- package/services/catalog/facades/product-catalog.facade.d.ts +10 -0
- package/services/catalog/helpers/brand-manager.helper.d.ts +14 -0
- package/services/catalog/helpers/catalog-filter.helper.d.ts +8 -0
- package/services/catalog/helpers/catalog-sort.helper.d.ts +7 -0
- package/services/catalog/helpers/index.d.ts +4 -0
- package/services/catalog/helpers/product-fields.helper.d.ts +7 -0
- package/services/catalog/services/catalog-helpers.service.d.ts +17 -0
- package/services/catalog/services/catalog-operations.facade.d.ts +13 -0
- package/services/catalog/services/catalog-repository.service.d.ts +12 -0
- package/services/catalog/services/index.d.ts +4 -0
- package/services/catalog/services/product-management.facade.d.ts +12 -0
- package/services/catalog/strategies/category-search.strategy.d.ts +19 -0
- package/services/catalog/strategies/index.d.ts +3 -0
- package/services/catalog/strategies/profile-search.strategy.d.ts +14 -0
- package/services/catalog/strategies/term-search.strategy.d.ts +20 -0
- package/services/catalog/strategies/types/strategy-params.type.d.ts +58 -0
- package/services/catalog/types/fetch-products-options.type.d.ts +8 -0
- package/services/catalog/types/fetch-products-params.type.d.ts +25 -0
- package/services/catalog/types/fetch-products-response.type.d.ts +19 -0
- package/services/catalog/types/index.d.ts +4 -0
- package/services/catalog/types/method-params.type.d.ts +17 -0
- package/services/catalog/wishlist.service.d.ts +12 -4
- package/services/checkout/checkout-dependencies.facade.d.ts +10 -0
- package/services/checkout/checkout-repositories.facade.d.ts +9 -0
- package/services/checkout/index.d.ts +2 -0
- package/services/checkout-subscription.service.d.ts +2 -2
- package/services/checkout.service.d.ts +7 -11
- package/services/coupon/coupon-repositories.facade.d.ts +10 -0
- package/services/coupon/index.d.ts +1 -0
- package/services/coupon/types/coupon-params.type.d.ts +13 -0
- package/services/coupon.service.d.ts +16 -7
- package/services/home-shop/home-shop-repositories.facade.d.ts +10 -0
- package/services/home-shop/index.d.ts +1 -0
- package/services/home-shop.service.d.ts +6 -6
- package/services/shared/configuration.facade.d.ts +12 -0
- 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$
|
|
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
|
|
10
|
-
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, 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,
|
|
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';
|
|
@@ -309,6 +309,13 @@ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0",
|
|
|
309
309
|
},
|
|
310
310
|
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
311
311
|
},
|
|
312
|
+
{
|
|
313
|
+
provide: 'GroupRepository',
|
|
314
|
+
useFactory: (options) => {
|
|
315
|
+
return new GroupFirestoreRepository(options);
|
|
316
|
+
},
|
|
317
|
+
deps: ['FirestoreOptions'],
|
|
318
|
+
},
|
|
312
319
|
{
|
|
313
320
|
provide: 'HomeRepository',
|
|
314
321
|
useFactory: (options) => {
|
|
@@ -575,6 +582,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
575
582
|
},
|
|
576
583
|
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
577
584
|
},
|
|
585
|
+
{
|
|
586
|
+
provide: 'GroupRepository',
|
|
587
|
+
useFactory: (options) => {
|
|
588
|
+
return new GroupFirestoreRepository(options);
|
|
589
|
+
},
|
|
590
|
+
deps: ['FirestoreOptions'],
|
|
591
|
+
},
|
|
578
592
|
{
|
|
579
593
|
provide: 'HomeRepository',
|
|
580
594
|
useFactory: (options) => {
|
|
@@ -1134,81 +1148,137 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1134
1148
|
args: ['UserRepository']
|
|
1135
1149
|
}] }]; } });
|
|
1136
1150
|
|
|
1137
|
-
class
|
|
1138
|
-
constructor(checkoutRepository, userRepository
|
|
1151
|
+
class CheckoutRepositoriesFacade {
|
|
1152
|
+
constructor(checkoutRepository, userRepository) {
|
|
1139
1153
|
this.checkoutRepository = checkoutRepository;
|
|
1140
1154
|
this.userRepository = userRepository;
|
|
1141
|
-
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
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 });
|
|
1158
|
+
CheckoutRepositoriesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutRepositoriesFacade });
|
|
1159
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutRepositoriesFacade, decorators: [{
|
|
1160
|
+
type: Injectable
|
|
1161
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1162
|
+
type: Inject,
|
|
1163
|
+
args: ['CheckoutRepository']
|
|
1164
|
+
}] }, { type: undefined, decorators: [{
|
|
1165
|
+
type: Inject,
|
|
1166
|
+
args: ['UserRepository']
|
|
1167
|
+
}] }]; } });
|
|
1168
|
+
|
|
1169
|
+
class CheckoutDependenciesFacade {
|
|
1170
|
+
constructor(dataPersistence, httpClient) {
|
|
1142
1171
|
this.dataPersistence = dataPersistence;
|
|
1172
|
+
this.httpClient = httpClient;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
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 });
|
|
1176
|
+
CheckoutDependenciesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutDependenciesFacade });
|
|
1177
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutDependenciesFacade, decorators: [{
|
|
1178
|
+
type: Injectable
|
|
1179
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1180
|
+
type: Inject,
|
|
1181
|
+
args: [PERSISTENCE_PROVIDER]
|
|
1182
|
+
}] }, { type: i1$2.HttpClient }]; } });
|
|
1183
|
+
|
|
1184
|
+
class ConfigurationFacade {
|
|
1185
|
+
constructor(defaultShop, firebaseOptions) {
|
|
1186
|
+
this.defaultShop = defaultShop;
|
|
1143
1187
|
this.firebaseOptions = firebaseOptions;
|
|
1144
|
-
|
|
1188
|
+
}
|
|
1189
|
+
getCheckoutUrl() {
|
|
1190
|
+
return `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
|
|
1191
|
+
}
|
|
1192
|
+
getProjectId() {
|
|
1193
|
+
return this.firebaseOptions.projectId;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
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 });
|
|
1197
|
+
ConfigurationFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ConfigurationFacade });
|
|
1198
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ConfigurationFacade, decorators: [{
|
|
1199
|
+
type: Injectable
|
|
1200
|
+
}], ctorParameters: function () { return [{ type: i3.Shops, decorators: [{
|
|
1201
|
+
type: Inject,
|
|
1202
|
+
args: [DEFAULT_SHOP]
|
|
1203
|
+
}] }, { type: undefined, decorators: [{
|
|
1204
|
+
type: Inject,
|
|
1205
|
+
args: [FIREBASE_OPTIONS]
|
|
1206
|
+
}] }]; } });
|
|
1207
|
+
|
|
1208
|
+
class CheckoutService {
|
|
1209
|
+
constructor(repositoriesFacade, dependenciesFacade, configurationFacade) {
|
|
1210
|
+
this.repositoriesFacade = repositoriesFacade;
|
|
1211
|
+
this.dependenciesFacade = dependenciesFacade;
|
|
1212
|
+
this.configurationFacade = configurationFacade;
|
|
1145
1213
|
this.checkoutUrl = null;
|
|
1146
|
-
this.checkoutUrl =
|
|
1214
|
+
this.checkoutUrl = this.configurationFacade.getCheckoutUrl();
|
|
1147
1215
|
}
|
|
1148
1216
|
getCheckout(checkoutData) {
|
|
1149
|
-
return this.dataPersistence
|
|
1217
|
+
return this.dependenciesFacade.dataPersistence
|
|
1150
1218
|
.get('checkoutId')
|
|
1151
|
-
.pipe(concatMap((id) =>
|
|
1219
|
+
.pipe(concatMap((id) => !isNil(id) ? this.repositoriesFacade.checkoutRepository.get({ id }) : this.createCheckout(checkoutData)));
|
|
1152
1220
|
}
|
|
1153
1221
|
getUserByCheckout(checkoutId) {
|
|
1154
|
-
return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => checkout?.user?.id
|
|
1222
|
+
return from(this.repositoriesFacade.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => checkout?.user?.id
|
|
1223
|
+
? of(checkout.user)
|
|
1224
|
+
: from(this.repositoriesFacade.userRepository.get({ id: checkout.user.id }))), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
|
|
1155
1225
|
}
|
|
1156
1226
|
updateCheckoutLineItems(checkout) {
|
|
1157
|
-
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
|
|
1227
|
+
return from(this.repositoriesFacade.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
|
|
1158
1228
|
}
|
|
1159
1229
|
updateCheckoutUser(checkout) {
|
|
1160
|
-
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
|
|
1230
|
+
return from(this.repositoriesFacade.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
|
|
1161
1231
|
}
|
|
1162
1232
|
clearCheckoutFromSession() {
|
|
1163
|
-
return this.dataPersistence.remove('checkoutId');
|
|
1233
|
+
return this.dependenciesFacade.dataPersistence.remove('checkoutId');
|
|
1164
1234
|
}
|
|
1165
1235
|
resetCheckoutValues() {
|
|
1166
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.
|
|
1236
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutResetValues`, {
|
|
1167
1237
|
checkoutId: checkout.id,
|
|
1168
1238
|
})), concatMap(() => this.getCheckout()));
|
|
1169
1239
|
}
|
|
1170
1240
|
applyCouponDiscount(nickname, checkoutType) {
|
|
1171
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.
|
|
1241
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutApplyDiscount`, {
|
|
1172
1242
|
checkoutId: checkout.id,
|
|
1173
1243
|
coupon: nickname,
|
|
1174
1244
|
checkoutType,
|
|
1175
1245
|
})), concatMap(() => this.getCheckout()), map((checkout) => checkout.coupon));
|
|
1176
1246
|
}
|
|
1177
1247
|
removeCouponDiscount() {
|
|
1178
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.
|
|
1248
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutRemoveDiscount`, {
|
|
1179
1249
|
checkoutId: checkout.id,
|
|
1180
1250
|
})), concatMap(() => this.getCheckout()));
|
|
1181
1251
|
}
|
|
1182
1252
|
validateStockProducts() {
|
|
1183
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.
|
|
1253
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutValidateProductStock`, {
|
|
1184
1254
|
checkoutId: checkout.id,
|
|
1185
1255
|
})));
|
|
1186
1256
|
}
|
|
1187
1257
|
selectShippingAddress(address) {
|
|
1188
1258
|
return this.getCheckout().pipe(concatMap((checkout) => {
|
|
1189
|
-
return this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, shippingAddress: address, billingAddress: address }));
|
|
1259
|
+
return this.repositoriesFacade.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, shippingAddress: address, billingAddress: address }));
|
|
1190
1260
|
}));
|
|
1191
1261
|
}
|
|
1192
1262
|
getAvailableShippingForProduct(productShipping) {
|
|
1193
|
-
return this.
|
|
1263
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
|
|
1194
1264
|
checkoutId: null,
|
|
1195
1265
|
productShipping,
|
|
1196
1266
|
});
|
|
1197
1267
|
}
|
|
1198
1268
|
getAvailableShippingForCheckout() {
|
|
1199
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.
|
|
1269
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
|
|
1200
1270
|
checkoutId: checkout.id,
|
|
1201
1271
|
productShipping: null,
|
|
1202
1272
|
})));
|
|
1203
1273
|
}
|
|
1204
1274
|
selectShipping(option) {
|
|
1205
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.
|
|
1275
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutSelectShipping`, {
|
|
1206
1276
|
checkoutId: checkout.id,
|
|
1207
1277
|
shippingOption: option,
|
|
1208
1278
|
})), concatMap(() => this.getCheckout()));
|
|
1209
1279
|
}
|
|
1210
1280
|
createOrder(checkoutPayload, paymentProvider, applicationVersion) {
|
|
1211
|
-
return this.
|
|
1281
|
+
return this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkout`, {
|
|
1212
1282
|
data: {
|
|
1213
1283
|
...checkoutPayload,
|
|
1214
1284
|
applicationVersion,
|
|
@@ -1217,43 +1287,38 @@ class CheckoutService {
|
|
|
1217
1287
|
});
|
|
1218
1288
|
}
|
|
1219
1289
|
async createCheckout(checkoutData) {
|
|
1220
|
-
const checkout = await this.checkoutRepository.create({
|
|
1290
|
+
const checkout = await this.repositoriesFacade.checkoutRepository.create({
|
|
1221
1291
|
createdAt: new Date(),
|
|
1222
1292
|
...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
1223
|
-
shop: checkoutData?.shop || this.defaultShop,
|
|
1293
|
+
shop: checkoutData?.shop || this.configurationFacade.defaultShop,
|
|
1224
1294
|
});
|
|
1225
|
-
await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
|
|
1295
|
+
await this.dependenciesFacade.dataPersistence.set('checkoutId', checkout.id).toPromise();
|
|
1226
1296
|
return checkout;
|
|
1227
1297
|
}
|
|
1228
1298
|
}
|
|
1229
|
-
CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token:
|
|
1299
|
+
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 });
|
|
1230
1300
|
CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
|
|
1231
1301
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
|
|
1232
1302
|
type: Injectable
|
|
1233
|
-
}], ctorParameters: function () { return [{ type:
|
|
1234
|
-
type: Inject,
|
|
1235
|
-
args: ['CheckoutRepository']
|
|
1236
|
-
}] }, { type: undefined, decorators: [{
|
|
1237
|
-
type: Inject,
|
|
1238
|
-
args: ['UserRepository']
|
|
1239
|
-
}] }, { type: i1$3.Shops, decorators: [{
|
|
1240
|
-
type: Inject,
|
|
1241
|
-
args: [DEFAULT_SHOP]
|
|
1242
|
-
}] }, { type: undefined, decorators: [{
|
|
1243
|
-
type: Inject,
|
|
1244
|
-
args: [PERSISTENCE_PROVIDER]
|
|
1245
|
-
}] }, { type: undefined, decorators: [{
|
|
1246
|
-
type: Inject,
|
|
1247
|
-
args: [FIREBASE_OPTIONS]
|
|
1248
|
-
}] }, { type: i1$2.HttpClient }]; } });
|
|
1303
|
+
}], ctorParameters: function () { return [{ type: CheckoutRepositoriesFacade }, { type: CheckoutDependenciesFacade }, { type: ConfigurationFacade }]; } });
|
|
1249
1304
|
|
|
1250
|
-
class
|
|
1251
|
-
constructor(authService, checkoutService,
|
|
1305
|
+
class CartServicesFacade {
|
|
1306
|
+
constructor(authService, checkoutService, httpClient) {
|
|
1252
1307
|
this.authService = authService;
|
|
1253
1308
|
this.checkoutService = checkoutService;
|
|
1254
|
-
this.
|
|
1255
|
-
|
|
1256
|
-
|
|
1309
|
+
this.httpClient = httpClient;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
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 });
|
|
1313
|
+
CartServicesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartServicesFacade });
|
|
1314
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartServicesFacade, decorators: [{
|
|
1315
|
+
type: Injectable
|
|
1316
|
+
}], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$2.HttpClient }]; } });
|
|
1317
|
+
|
|
1318
|
+
class CartService {
|
|
1319
|
+
constructor(servicesFacade, configurationFacade) {
|
|
1320
|
+
this.servicesFacade = servicesFacade;
|
|
1321
|
+
this.configurationFacade = configurationFacade;
|
|
1257
1322
|
this.cartSubject = new Subject();
|
|
1258
1323
|
this.checkoutUrl = null;
|
|
1259
1324
|
this.generateCartObject = (items) => items?.reduce((cart, item) => ({
|
|
@@ -1263,34 +1328,34 @@ class CartService {
|
|
|
1263
1328
|
quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
|
|
1264
1329
|
}),
|
|
1265
1330
|
}), {}) || {};
|
|
1266
|
-
this.checkoutUrl =
|
|
1331
|
+
this.checkoutUrl = this.configurationFacade.getCheckoutUrl();
|
|
1267
1332
|
}
|
|
1268
1333
|
addItem(item, quantity = 1) {
|
|
1269
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.
|
|
1334
|
+
return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutAddItemToCart`, {
|
|
1270
1335
|
checkoutId: checkout.id,
|
|
1271
1336
|
productId: item.id,
|
|
1272
1337
|
quantity,
|
|
1273
|
-
})), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1338
|
+
})), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1274
1339
|
}
|
|
1275
1340
|
decreaseItem(item) {
|
|
1276
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.
|
|
1341
|
+
return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutDecreaseProductFromCart`, {
|
|
1277
1342
|
checkoutId: checkout.id,
|
|
1278
1343
|
productId: item.id,
|
|
1279
1344
|
quantity: 1,
|
|
1280
|
-
})), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1345
|
+
})), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1281
1346
|
}
|
|
1282
1347
|
removeItem(item) {
|
|
1283
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.
|
|
1348
|
+
return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutRemoveProductFromCart`, {
|
|
1284
1349
|
checkoutId: checkout.id,
|
|
1285
1350
|
productId: item.id,
|
|
1286
|
-
})), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1351
|
+
})), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1287
1352
|
}
|
|
1288
1353
|
updateUserCart(user) {
|
|
1289
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap((checkout) => {
|
|
1290
|
-
return this.
|
|
1354
|
+
return this.servicesFacade.checkoutService.getCheckout().pipe(concatMap((checkout) => this.servicesFacade.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap((checkout) => {
|
|
1355
|
+
return this.servicesFacade.httpClient.post(`${this.checkoutUrl}/checkoutUpdateUserCart`, {
|
|
1291
1356
|
checkoutId: checkout.id,
|
|
1292
1357
|
});
|
|
1293
|
-
}), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => {
|
|
1358
|
+
}), concatMap(() => this.servicesFacade.checkoutService.getCheckout()), map((updatedCheckout) => {
|
|
1294
1359
|
return this.generateCartObject(updatedCheckout.lineItems);
|
|
1295
1360
|
}), tap((cart) => this.cartSubject.next(cart)));
|
|
1296
1361
|
}
|
|
@@ -1299,26 +1364,20 @@ class CartService {
|
|
|
1299
1364
|
return this.cartSubject;
|
|
1300
1365
|
}
|
|
1301
1366
|
clearCart() {
|
|
1302
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1303
|
-
this.checkoutService.clearCheckoutFromSession();
|
|
1367
|
+
return this.servicesFacade.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1368
|
+
this.servicesFacade.checkoutService.clearCheckoutFromSession();
|
|
1304
1369
|
return checkout;
|
|
1305
1370
|
}), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
|
|
1306
1371
|
}
|
|
1307
1372
|
buildCartFromCheckout(checkoutData) {
|
|
1308
|
-
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
1373
|
+
return this.servicesFacade.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
1309
1374
|
}
|
|
1310
1375
|
}
|
|
1311
|
-
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token:
|
|
1376
|
+
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 });
|
|
1312
1377
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
1313
1378
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
1314
1379
|
type: Injectable
|
|
1315
|
-
}], ctorParameters: function () { return [{ type:
|
|
1316
|
-
type: Inject,
|
|
1317
|
-
args: [DEFAULT_SHOP]
|
|
1318
|
-
}] }, { type: undefined, decorators: [{
|
|
1319
|
-
type: Inject,
|
|
1320
|
-
args: [FIREBASE_OPTIONS]
|
|
1321
|
-
}] }, { type: i1$2.HttpClient }]; } });
|
|
1380
|
+
}], ctorParameters: function () { return [{ type: CartServicesFacade }, { type: ConfigurationFacade }]; } });
|
|
1322
1381
|
|
|
1323
1382
|
class NewCategoryStructureAdapter {
|
|
1324
1383
|
constructor(categoryRepository) {
|
|
@@ -1380,237 +1439,288 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1380
1439
|
args: ['CategoryRepository']
|
|
1381
1440
|
}] }]; } });
|
|
1382
1441
|
|
|
1383
|
-
class
|
|
1384
|
-
constructor(
|
|
1385
|
-
this.
|
|
1386
|
-
this.
|
|
1387
|
-
this.
|
|
1388
|
-
this.
|
|
1389
|
-
this.
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
'
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
'
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
'
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
|
|
1421
|
-
const filters = {};
|
|
1422
|
-
if (clubDiscount?.length)
|
|
1423
|
-
set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
|
|
1424
|
-
if (brands?.length)
|
|
1425
|
-
filters.brand = { operator: Where.IN, value: brands };
|
|
1426
|
-
if (gender?.length)
|
|
1427
|
-
filters.gender = { operator: Where.IN, value: gender };
|
|
1428
|
-
if (prices?.min || prices?.max)
|
|
1429
|
-
set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
|
|
1430
|
-
...(prices.min ? [{ operator: Where.GTE, value: Math.floor(prices.min) }] : []),
|
|
1431
|
-
...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
|
|
1432
|
-
]);
|
|
1433
|
-
if (rate)
|
|
1434
|
-
filters.rate = { operator: Where.GTE, value: rate };
|
|
1435
|
-
if (tags?.length)
|
|
1436
|
-
filters.tags = { operator: Where.LIKE, value: tags };
|
|
1437
|
-
if (customOptions?.length)
|
|
1438
|
-
filters.filters = { operator: Where.LIKE, value: customOptions };
|
|
1439
|
-
return filters;
|
|
1440
|
-
};
|
|
1441
|
-
this.buildSortQuery = (sort) => {
|
|
1442
|
-
if (!sort || sort === 'most-relevant')
|
|
1443
|
-
return {};
|
|
1444
|
-
if (sort === 'best-sellers')
|
|
1445
|
-
return {
|
|
1446
|
-
shoppingCount: 'desc',
|
|
1447
|
-
rate: 'desc',
|
|
1448
|
-
stock: 'desc',
|
|
1449
|
-
name: 'asc',
|
|
1450
|
-
};
|
|
1451
|
-
if (sort === 'biggest-price')
|
|
1452
|
-
return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
|
|
1453
|
-
if (sort === 'lowest-price')
|
|
1454
|
-
return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
|
|
1455
|
-
if (sort === 'best-rating')
|
|
1456
|
-
return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
|
|
1457
|
-
if (sort === 'news')
|
|
1458
|
-
return { createdAt: 'desc' };
|
|
1459
|
-
if (sort === 'biggest-discount')
|
|
1460
|
-
return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
|
|
1461
|
-
};
|
|
1462
|
-
this.buildLimitQuery = (options) => {
|
|
1463
|
-
const limit = options?.perPage || 20;
|
|
1464
|
-
return {
|
|
1465
|
-
limit,
|
|
1466
|
-
offset: ((options?.page || 1) - 1) * limit,
|
|
1467
|
-
};
|
|
1468
|
-
};
|
|
1469
|
-
this.hasProfile = (options) => 'profile' in options;
|
|
1470
|
-
this.hasTerm = (options) => 'term' in options;
|
|
1471
|
-
this.hasCategory = (options) => 'category' in options;
|
|
1472
|
-
this.buildIndexBrands = (options) => {
|
|
1473
|
-
if (this.hasCategory(options))
|
|
1474
|
-
return `category-${options.category.id}`;
|
|
1475
|
-
if (this.hasTerm(options))
|
|
1476
|
-
return `term-${options.term}`;
|
|
1477
|
-
if (this.hasProfile(options))
|
|
1478
|
-
return `profile-${options.profile.join(',')}`;
|
|
1479
|
-
return '';
|
|
1480
|
-
};
|
|
1442
|
+
class CatalogSearchContext {
|
|
1443
|
+
constructor(categoryStrategy, termStrategy, profileStrategy) {
|
|
1444
|
+
this.categoryStrategy = categoryStrategy;
|
|
1445
|
+
this.termStrategy = termStrategy;
|
|
1446
|
+
this.profileStrategy = profileStrategy;
|
|
1447
|
+
this.strategies = new Map();
|
|
1448
|
+
this.initializeStrategies();
|
|
1449
|
+
}
|
|
1450
|
+
async executeSearch(params, shop, optionsCache) {
|
|
1451
|
+
const strategy = this.selectStrategy(params);
|
|
1452
|
+
return strategy.search(params, shop, optionsCache);
|
|
1453
|
+
}
|
|
1454
|
+
initializeStrategies() {
|
|
1455
|
+
this.strategies.set('category', this.categoryStrategy);
|
|
1456
|
+
this.strategies.set('term', this.termStrategy);
|
|
1457
|
+
this.strategies.set('profile', this.profileStrategy);
|
|
1458
|
+
}
|
|
1459
|
+
selectStrategy(params) {
|
|
1460
|
+
if (params.category) {
|
|
1461
|
+
const strategy = this.strategies.get('category');
|
|
1462
|
+
if (!strategy)
|
|
1463
|
+
throw new Error('Category strategy not found');
|
|
1464
|
+
return strategy;
|
|
1465
|
+
}
|
|
1466
|
+
if (params.term) {
|
|
1467
|
+
const strategy = this.strategies.get('term');
|
|
1468
|
+
if (!strategy)
|
|
1469
|
+
throw new Error('Term strategy not found');
|
|
1470
|
+
return strategy;
|
|
1471
|
+
}
|
|
1472
|
+
if (params.profile?.length) {
|
|
1473
|
+
const strategy = this.strategies.get('profile');
|
|
1474
|
+
if (!strategy)
|
|
1475
|
+
throw new Error('Profile strategy not found');
|
|
1476
|
+
return strategy;
|
|
1477
|
+
}
|
|
1478
|
+
throw new Error('No valid search strategy found for the given parameters');
|
|
1481
1479
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
class CategorySearchStrategy {
|
|
1483
|
+
constructor(repositoryService, helpersService) {
|
|
1484
|
+
this.repositoryService = repositoryService;
|
|
1485
|
+
this.helpersService = helpersService;
|
|
1486
|
+
}
|
|
1487
|
+
async search(params, shop, optionsCache) {
|
|
1488
|
+
const { category, filters, limits, sort, mainGender } = params;
|
|
1489
|
+
if (!category) {
|
|
1490
|
+
throw new Error('Category is required for CategorySearchStrategy');
|
|
1491
|
+
}
|
|
1492
|
+
const fields = this.helpersService.getFieldsHelper().getStandardFields();
|
|
1493
|
+
if (sort === 'most-relevant') {
|
|
1494
|
+
return this.searchWithMostRelevant({
|
|
1495
|
+
category,
|
|
1496
|
+
filters,
|
|
1497
|
+
limits,
|
|
1498
|
+
shop,
|
|
1499
|
+
mainGender,
|
|
1500
|
+
optionsCache,
|
|
1501
|
+
fields,
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
return this.searchDefault({
|
|
1505
|
+
category,
|
|
1506
|
+
filters,
|
|
1507
|
+
limits,
|
|
1508
|
+
shop,
|
|
1509
|
+
mainGender,
|
|
1510
|
+
sort,
|
|
1511
|
+
optionsCache,
|
|
1512
|
+
fields,
|
|
1504
1513
|
});
|
|
1505
1514
|
}
|
|
1506
|
-
async
|
|
1507
|
-
|
|
1515
|
+
async searchWithMostRelevant(params) {
|
|
1516
|
+
const { category, filters, shop, optionsCache } = params;
|
|
1517
|
+
const mostRelevant = category.isWishlist ? [] : category.getMostRelevantByShop(shop);
|
|
1518
|
+
const productsIds = await this.getProductIds(category, filters, optionsCache);
|
|
1519
|
+
return this.findAndSortByMostRelevant({
|
|
1520
|
+
mostRelevants: mostRelevant,
|
|
1521
|
+
productIds: productsIds,
|
|
1522
|
+
filters: params.filters,
|
|
1523
|
+
limits: params.limits,
|
|
1524
|
+
shop: params.shop,
|
|
1525
|
+
mainGender: params.mainGender,
|
|
1526
|
+
optionsCache: params.optionsCache,
|
|
1527
|
+
fields: params.fields,
|
|
1528
|
+
});
|
|
1508
1529
|
}
|
|
1509
|
-
async
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
if (this.hasCategory(options) && options.sort === 'most-relevant') {
|
|
1515
|
-
const mostRelevant = options.category.isWishlist ? [] : options.category.getMostRelevantByShop(this.shop);
|
|
1516
|
-
const productsIds = await this.productRepository
|
|
1517
|
-
.findCatalog({
|
|
1518
|
-
fields: ['id'],
|
|
1519
|
-
filters: {
|
|
1520
|
-
...(await this.buildMainFilter(options)),
|
|
1521
|
-
...this.buildFilterQuery(options?.filters || {}),
|
|
1522
|
-
},
|
|
1523
|
-
}, undefined, optionsCache)
|
|
1524
|
-
.then((products) => products.data.map((product) => product.id));
|
|
1525
|
-
return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits, optionsCache);
|
|
1526
|
-
}
|
|
1530
|
+
async searchDefault(params) {
|
|
1531
|
+
const { category, filters, limits, shop, mainGender, sort, optionsCache, fields } = params;
|
|
1532
|
+
const productCatalog = this.repositoryService.getProductCatalog();
|
|
1533
|
+
const filterHelper = this.helpersService.getFilterHelper();
|
|
1534
|
+
const sortHelper = this.helpersService.getSortHelper();
|
|
1527
1535
|
const repoParams = {
|
|
1528
|
-
fields
|
|
1536
|
+
fields,
|
|
1529
1537
|
filters: {
|
|
1530
|
-
...(await
|
|
1531
|
-
...
|
|
1538
|
+
...(await productCatalog.categoryStructureAdapter.buildProductFilterByCategory(category)),
|
|
1539
|
+
...filterHelper.buildFilterQuery(filters || {}),
|
|
1532
1540
|
},
|
|
1533
|
-
...(
|
|
1541
|
+
...(sort ? { orderBy: sortHelper.buildSortQuery(sort) } : {}),
|
|
1534
1542
|
limits,
|
|
1535
1543
|
options: {
|
|
1536
1544
|
minimal: ['price'],
|
|
1537
1545
|
maximum: ['price'],
|
|
1538
|
-
|
|
1539
|
-
? { distinct: ['brand'] }
|
|
1540
|
-
: {}),
|
|
1546
|
+
distinct: ['brand'],
|
|
1541
1547
|
},
|
|
1542
1548
|
};
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1549
|
+
return productCatalog.productRepository.findCatalog(repoParams, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'), optionsCache);
|
|
1550
|
+
}
|
|
1551
|
+
async getProductIds(category, filters, optionsCache) {
|
|
1552
|
+
const productCatalog = this.repositoryService.getProductCatalog();
|
|
1553
|
+
const filterHelper = this.helpersService.getFilterHelper();
|
|
1554
|
+
return productCatalog.productRepository
|
|
1555
|
+
.findCatalog({
|
|
1556
|
+
fields: ['id'],
|
|
1557
|
+
filters: {
|
|
1558
|
+
...(await productCatalog.categoryStructureAdapter.buildProductFilterByCategory(category)),
|
|
1559
|
+
...filterHelper.buildFilterQuery(filters || {}),
|
|
1560
|
+
},
|
|
1561
|
+
}, undefined, optionsCache)
|
|
1562
|
+
.then((products) => products.data.map((product) => product.id));
|
|
1563
|
+
}
|
|
1564
|
+
async findAndSortByMostRelevant(params) {
|
|
1565
|
+
const { mostRelevants, productIds, filters, shop, mainGender, optionsCache, fields, limits } = params;
|
|
1566
|
+
const productCatalog = this.repositoryService.getProductCatalog();
|
|
1567
|
+
const filterHelper = this.helpersService.getFilterHelper();
|
|
1568
|
+
const sortHelper = this.helpersService.getSortHelper();
|
|
1559
1569
|
const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
|
|
1560
|
-
const totalResult = await
|
|
1561
|
-
fields
|
|
1570
|
+
const totalResult = await productCatalog.productRepository.findCatalog({
|
|
1571
|
+
fields,
|
|
1562
1572
|
filters: {
|
|
1563
1573
|
id: { operator: Where.IN, value: mostRelevantProductsIds },
|
|
1564
|
-
...
|
|
1574
|
+
...filterHelper.buildFilterQuery(filters || {}),
|
|
1565
1575
|
},
|
|
1566
|
-
orderBy:
|
|
1576
|
+
orderBy: sortHelper.buildSortQuery('best-sellers'),
|
|
1567
1577
|
options: {
|
|
1568
1578
|
minimal: ['price'],
|
|
1569
1579
|
maximum: ['price'],
|
|
1570
|
-
...(
|
|
1580
|
+
...(isEmpty(filters?.brands) ? { distinct: ['brand'] } : {}),
|
|
1571
1581
|
},
|
|
1572
|
-
},
|
|
1573
|
-
|
|
1582
|
+
}, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'), optionsCache);
|
|
1583
|
+
return this.sortProductsByRelevance(totalResult, mostRelevants, limits);
|
|
1584
|
+
}
|
|
1585
|
+
sortProductsByRelevance(totalResult, mostRelevants, limits) {
|
|
1586
|
+
const mostRelevantWithoutStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
|
|
1574
1587
|
const firstProducts = totalResult.data
|
|
1575
1588
|
.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
1576
1589
|
.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
|
|
1577
1590
|
const lastProducts = totalResult.data
|
|
1578
1591
|
.filter((product) => !mostRelevants.includes(product.id))
|
|
1579
|
-
.concat(
|
|
1592
|
+
.concat(mostRelevantWithoutStock);
|
|
1580
1593
|
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
1581
1594
|
const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
|
|
1582
|
-
await this.setBrandsList(options, totalResult.distinct?.brand);
|
|
1583
1595
|
return {
|
|
1584
1596
|
data: resultFinal,
|
|
1585
1597
|
count: totalResult.count,
|
|
1586
1598
|
maximum: totalResult.maximum,
|
|
1587
1599
|
minimal: totalResult.minimal,
|
|
1588
|
-
distinct:
|
|
1589
|
-
|
|
1590
|
-
|
|
1600
|
+
distinct: totalResult.distinct,
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
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 });
|
|
1605
|
+
CategorySearchStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategorySearchStrategy });
|
|
1606
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategorySearchStrategy, decorators: [{
|
|
1607
|
+
type: Injectable
|
|
1608
|
+
}], ctorParameters: function () { return [{ type: CatalogRepositoryService }, { type: CatalogHelpersService }]; } });
|
|
1609
|
+
|
|
1610
|
+
class ProfileSearchStrategy {
|
|
1611
|
+
constructor(repositoryService, helpersService) {
|
|
1612
|
+
this.repositoryService = repositoryService;
|
|
1613
|
+
this.helpersService = helpersService;
|
|
1614
|
+
}
|
|
1615
|
+
async search(params, shop, optionsCache) {
|
|
1616
|
+
const { profile, filters, limits, sort, mainGender } = params;
|
|
1617
|
+
if (!profile) {
|
|
1618
|
+
throw new Error('Profile is required for ProfileSearchStrategy');
|
|
1619
|
+
}
|
|
1620
|
+
const productCatalog = this.repositoryService.getProductCatalog();
|
|
1621
|
+
const filterHelper = this.helpersService.getFilterHelper();
|
|
1622
|
+
const sortHelper = this.helpersService.getSortHelper();
|
|
1623
|
+
const fieldsHelper = this.helpersService.getFieldsHelper();
|
|
1624
|
+
const repoParams = {
|
|
1625
|
+
fields: fieldsHelper.getStandardFields(),
|
|
1626
|
+
filters: {
|
|
1627
|
+
tags: { operator: Where.LIKE, value: profile },
|
|
1628
|
+
...filterHelper.buildFilterQuery(filters || {}),
|
|
1629
|
+
},
|
|
1630
|
+
...(sort ? { orderBy: sortHelper.buildSortQuery(sort) } : {}),
|
|
1631
|
+
limits,
|
|
1632
|
+
options: {
|
|
1633
|
+
minimal: ['price'],
|
|
1634
|
+
maximum: ['price'],
|
|
1635
|
+
distinct: ['brand'],
|
|
1591
1636
|
},
|
|
1592
1637
|
};
|
|
1638
|
+
return productCatalog.productRepository.findCatalog(repoParams, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'), optionsCache);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
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 });
|
|
1642
|
+
ProfileSearchStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProfileSearchStrategy });
|
|
1643
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProfileSearchStrategy, decorators: [{
|
|
1644
|
+
type: Injectable
|
|
1645
|
+
}], ctorParameters: function () { return [{ type: CatalogRepositoryService }, { type: CatalogHelpersService }]; } });
|
|
1646
|
+
|
|
1647
|
+
class TermSearchStrategy {
|
|
1648
|
+
constructor(repositoryService, helpersService) {
|
|
1649
|
+
this.repositoryService = repositoryService;
|
|
1650
|
+
this.helpersService = helpersService;
|
|
1651
|
+
this.productsByTerm = {};
|
|
1652
|
+
}
|
|
1653
|
+
async search(params, shop, _optionsCache) {
|
|
1654
|
+
const { term, filters, limits, sort, mainGender } = params;
|
|
1655
|
+
if (!term) {
|
|
1656
|
+
throw new Error('Term is required for TermSearchStrategy');
|
|
1657
|
+
}
|
|
1658
|
+
const productIds = await this.findCatalogIdsBySearch(term, shop);
|
|
1659
|
+
if (sort === 'most-relevant') {
|
|
1660
|
+
return this.searchWithMostRelevant({
|
|
1661
|
+
productIds,
|
|
1662
|
+
filters,
|
|
1663
|
+
limits,
|
|
1664
|
+
shop,
|
|
1665
|
+
mainGender,
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
return this.searchDefault({
|
|
1669
|
+
productIds,
|
|
1670
|
+
filters,
|
|
1671
|
+
limits,
|
|
1672
|
+
shop,
|
|
1673
|
+
mainGender,
|
|
1674
|
+
fields: this.helpersService.getFieldsHelper().getStandardFields(),
|
|
1675
|
+
});
|
|
1593
1676
|
}
|
|
1594
|
-
async
|
|
1595
|
-
const
|
|
1596
|
-
const
|
|
1677
|
+
async searchWithMostRelevant(params) {
|
|
1678
|
+
const { productIds, filters, shop, mainGender } = params;
|
|
1679
|
+
const productCatalog = this.repositoryService.getProductCatalog();
|
|
1680
|
+
const filterHelper = this.helpersService.getFilterHelper();
|
|
1681
|
+
const totalResult = await productCatalog.productRepository.findCatalog({
|
|
1597
1682
|
fields: ['id', 'stock', 'gender'],
|
|
1598
1683
|
filters: {
|
|
1599
1684
|
id: { operator: Where.IN, value: productIds },
|
|
1600
1685
|
published: { operator: Where.EQUALS, value: true },
|
|
1601
|
-
...
|
|
1686
|
+
...filterHelper.buildFilterQuery(filters || {}),
|
|
1687
|
+
},
|
|
1688
|
+
options: {
|
|
1689
|
+
minimal: ['price'],
|
|
1690
|
+
maximum: ['price'],
|
|
1691
|
+
...(isEmpty(filters?.brands) ? { distinct: ['brand'] } : {}),
|
|
1692
|
+
},
|
|
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
|
+
async searchDefault(params) {
|
|
1703
|
+
const { productIds, filters, limits, shop, mainGender, fields } = params;
|
|
1704
|
+
const productCatalog = this.repositoryService.getProductCatalog();
|
|
1705
|
+
const filterHelper = this.helpersService.getFilterHelper();
|
|
1706
|
+
return productCatalog.productRepository.findCatalog({
|
|
1707
|
+
fields,
|
|
1708
|
+
filters: {
|
|
1709
|
+
id: { operator: Where.IN, value: productIds },
|
|
1710
|
+
published: { operator: Where.EQUALS, value: true },
|
|
1711
|
+
...filterHelper.buildFilterQuery(filters || {}),
|
|
1602
1712
|
},
|
|
1713
|
+
limits,
|
|
1603
1714
|
options: {
|
|
1604
1715
|
minimal: ['price'],
|
|
1605
1716
|
maximum: ['price'],
|
|
1606
|
-
|
|
1607
|
-
},
|
|
1608
|
-
},
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
: 'male';
|
|
1717
|
+
distinct: ['brand'],
|
|
1718
|
+
},
|
|
1719
|
+
}, mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'));
|
|
1720
|
+
}
|
|
1721
|
+
sortByTermRelevance(params) {
|
|
1722
|
+
const { productIds, totalResult, limits, filters, fieldsHelper } = params;
|
|
1723
|
+
const defaultGender = filters?.gender?.at(0) || 'male';
|
|
1614
1724
|
const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
|
|
1615
1725
|
const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
|
|
1616
1726
|
const productIdsStockGender = productIds.filter((product) => stockData.some((result) => result.id === product && (result.gender?.includes(defaultGender) || result.gender?.includes('unisex'))));
|
|
@@ -1621,129 +1731,533 @@ class CatalogService {
|
|
|
1621
1731
|
.concat(productIdsStockOut)
|
|
1622
1732
|
.slice(limits.offset, limits.offset + limits.limit);
|
|
1623
1733
|
const orderedId = productIds.filter((product) => limitedProductId.includes(product));
|
|
1624
|
-
|
|
1734
|
+
return this.getDetailedProducts(orderedId, totalResult, fieldsHelper);
|
|
1735
|
+
}
|
|
1736
|
+
async getDetailedProducts(orderedId, totalResult, fieldsHelper) {
|
|
1737
|
+
const productCatalog = this.repositoryService.getProductCatalog();
|
|
1738
|
+
const fields = fieldsHelper.getStandardFields();
|
|
1739
|
+
const productResult = await productCatalog.productRepository.findCatalog({
|
|
1625
1740
|
filters: {
|
|
1626
1741
|
id: { operator: Where.IN, value: orderedId },
|
|
1627
1742
|
},
|
|
1628
|
-
fields
|
|
1743
|
+
fields,
|
|
1629
1744
|
});
|
|
1630
|
-
await this.setBrandsList(options, totalResult.distinct?.brand);
|
|
1631
1745
|
return {
|
|
1632
|
-
data:
|
|
1746
|
+
data: orderedId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
|
|
1633
1747
|
count: totalResult.count,
|
|
1634
1748
|
maximum: totalResult.maximum,
|
|
1635
1749
|
minimal: totalResult.minimal,
|
|
1636
|
-
distinct:
|
|
1637
|
-
...totalResult.distinct,
|
|
1638
|
-
brand: this.brandsList[this.buildIndexBrands(options)],
|
|
1639
|
-
},
|
|
1750
|
+
distinct: totalResult.distinct,
|
|
1640
1751
|
};
|
|
1641
1752
|
}
|
|
1642
|
-
async findCatalogIdsBySearch(term,
|
|
1753
|
+
async findCatalogIdsBySearch(term, shop) {
|
|
1643
1754
|
if (this.productsByTerm[term])
|
|
1644
1755
|
return this.productsByTerm[term];
|
|
1645
|
-
|
|
1646
|
-
|
|
1756
|
+
const productServices = this.repositoryService.getProductServices();
|
|
1757
|
+
return (this.productsByTerm[term] = await productServices.productSearch
|
|
1758
|
+
.search(term, 999, shop === Shops.GLAMSHOP ? 'female' : 'male')
|
|
1647
1759
|
.then((products) => [...new Set(products.map((product) => product.id))]));
|
|
1648
1760
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
|
|
1662
|
-
.then((result) => {
|
|
1663
|
-
return result.distinct.brand;
|
|
1664
|
-
});
|
|
1761
|
+
}
|
|
1762
|
+
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 });
|
|
1763
|
+
TermSearchStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: TermSearchStrategy });
|
|
1764
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: TermSearchStrategy, decorators: [{
|
|
1765
|
+
type: Injectable
|
|
1766
|
+
}], ctorParameters: function () { return [{ type: CatalogRepositoryService }, { type: CatalogHelpersService }]; } });
|
|
1767
|
+
|
|
1768
|
+
class CatalogStrategiesFacade {
|
|
1769
|
+
constructor(categoryStrategy, termStrategy, profileStrategy) {
|
|
1770
|
+
this.categoryStrategy = categoryStrategy;
|
|
1771
|
+
this.termStrategy = termStrategy;
|
|
1772
|
+
this.profileStrategy = profileStrategy;
|
|
1665
1773
|
}
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1774
|
+
}
|
|
1775
|
+
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 });
|
|
1776
|
+
CatalogStrategiesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogStrategiesFacade });
|
|
1777
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogStrategiesFacade, decorators: [{
|
|
1778
|
+
type: Injectable
|
|
1779
|
+
}], ctorParameters: function () { return [{ type: CategorySearchStrategy }, { type: TermSearchStrategy }, { type: ProfileSearchStrategy }]; } });
|
|
1780
|
+
|
|
1781
|
+
class CatalogServiceFacade {
|
|
1782
|
+
constructor(helpersService, strategiesFacade, shop) {
|
|
1783
|
+
this.helpersService = helpersService;
|
|
1784
|
+
this.strategiesFacade = strategiesFacade;
|
|
1785
|
+
this.shop = shop;
|
|
1786
|
+
const searchContext = new CatalogSearchContext(this.strategiesFacade.categoryStrategy, this.strategiesFacade.termStrategy, this.strategiesFacade.profileStrategy);
|
|
1787
|
+
this.catalogService = new CatalogService(searchContext, this.helpersService, this.shop);
|
|
1788
|
+
}
|
|
1789
|
+
getCatalogService() {
|
|
1790
|
+
return this.catalogService;
|
|
1677
1791
|
}
|
|
1678
1792
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type:
|
|
1793
|
+
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 });
|
|
1794
|
+
CatalogServiceFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogServiceFacade });
|
|
1795
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogServiceFacade, decorators: [{
|
|
1682
1796
|
type: Injectable
|
|
1683
|
-
}], ctorParameters: function () { return [{ type:
|
|
1684
|
-
type: Inject,
|
|
1685
|
-
args: ['ProductRepository']
|
|
1686
|
-
}] }, { type: undefined, decorators: [{
|
|
1797
|
+
}], ctorParameters: function () { return [{ type: CatalogHelpersService }, { type: CatalogStrategiesFacade }, { type: i3.Shops, decorators: [{
|
|
1687
1798
|
type: Inject,
|
|
1688
|
-
args: [
|
|
1689
|
-
}] }
|
|
1799
|
+
args: [DEFAULT_SHOP]
|
|
1800
|
+
}] }]; } });
|
|
1801
|
+
|
|
1802
|
+
class CategoryRepositoryFacade {
|
|
1803
|
+
constructor(categoryRepository, categoryFilterRepository) {
|
|
1804
|
+
this.categoryRepository = categoryRepository;
|
|
1805
|
+
this.categoryFilterRepository = categoryFilterRepository;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
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 });
|
|
1809
|
+
CategoryRepositoryFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryRepositoryFacade });
|
|
1810
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryRepositoryFacade, decorators: [{
|
|
1811
|
+
type: Injectable
|
|
1812
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1690
1813
|
type: Inject,
|
|
1691
1814
|
args: ['CategoryRepository']
|
|
1692
1815
|
}] }, { type: undefined, decorators: [{
|
|
1693
1816
|
type: Inject,
|
|
1694
|
-
args: [
|
|
1695
|
-
}] }, { type: i1$3.Shops, decorators: [{
|
|
1696
|
-
type: Inject,
|
|
1697
|
-
args: [DEFAULT_SHOP]
|
|
1698
|
-
}] }, { type: undefined, decorators: [{
|
|
1699
|
-
type: Inject,
|
|
1700
|
-
args: ['ProductSearch']
|
|
1817
|
+
args: ['CategoryFilterRepository']
|
|
1701
1818
|
}] }]; } });
|
|
1702
1819
|
|
|
1703
1820
|
class CategoryService {
|
|
1704
|
-
constructor(
|
|
1705
|
-
this.
|
|
1706
|
-
this.
|
|
1707
|
-
this.categoryFilterRepository = categoryFilterRepository;
|
|
1708
|
-
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
1821
|
+
constructor(categoryFacade, productCatalog, shop) {
|
|
1822
|
+
this.categoryFacade = categoryFacade;
|
|
1823
|
+
this.productCatalog = productCatalog;
|
|
1709
1824
|
this.shop = shop;
|
|
1710
1825
|
}
|
|
1711
1826
|
async fetchBrands(category, options, optionsCache) {
|
|
1712
|
-
const brands = await this.productRepository
|
|
1827
|
+
const brands = await this.productCatalog.productRepository
|
|
1713
1828
|
.findCatalog({
|
|
1714
|
-
filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
|
|
1829
|
+
filters: await this.productCatalog.categoryStructureAdapter.buildProductFilterByCategory(category),
|
|
1715
1830
|
fields: ['brand'],
|
|
1716
1831
|
}, options?.mainGender ? options?.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache)
|
|
1717
1832
|
.then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
|
|
1718
|
-
return this.categoryRepository
|
|
1833
|
+
return this.categoryFacade.categoryRepository
|
|
1719
1834
|
.find({ filters: { brandCategory: true, shop: options?.shop || this.shop }, orderBy: { name: 'asc' } }, optionsCache)
|
|
1720
1835
|
.then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
|
|
1721
1836
|
}
|
|
1722
1837
|
async fetchFilterOptions(category, optionsCache) {
|
|
1723
|
-
return await this.categoryFilterRepository
|
|
1838
|
+
return await this.categoryFacade.categoryFilterRepository
|
|
1724
1839
|
.find({ filters: { categoryId: +category.id } }, optionsCache)
|
|
1725
1840
|
.then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
|
|
1726
1841
|
}
|
|
1727
1842
|
}
|
|
1728
|
-
CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token:
|
|
1843
|
+
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 });
|
|
1729
1844
|
CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
|
|
1730
1845
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
|
|
1731
1846
|
type: Injectable
|
|
1847
|
+
}], ctorParameters: function () { return [{ type: CategoryRepositoryFacade }, { type: ProductCatalogFacade }, { type: i3.Shops, decorators: [{
|
|
1848
|
+
type: Inject,
|
|
1849
|
+
args: [DEFAULT_SHOP]
|
|
1850
|
+
}] }]; } });
|
|
1851
|
+
|
|
1852
|
+
class ProductCatalogFacade {
|
|
1853
|
+
constructor(productRepository, categoryStructureAdapter) {
|
|
1854
|
+
this.productRepository = productRepository;
|
|
1855
|
+
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
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 });
|
|
1859
|
+
ProductCatalogFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductCatalogFacade });
|
|
1860
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductCatalogFacade, decorators: [{
|
|
1861
|
+
type: Injectable
|
|
1732
1862
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1733
1863
|
type: Inject,
|
|
1734
1864
|
args: ['ProductRepository']
|
|
1735
|
-
}] }, { type: undefined, decorators: [{
|
|
1736
|
-
type: Inject,
|
|
1737
|
-
args: ['CategoryRepository']
|
|
1738
|
-
}] }, { type: undefined, decorators: [{
|
|
1739
|
-
type: Inject,
|
|
1740
|
-
args: ['CategoryFilterRepository']
|
|
1741
1865
|
}] }, { type: undefined, decorators: [{
|
|
1742
1866
|
type: Inject,
|
|
1743
1867
|
args: [CATEGORY_STRUCTURE]
|
|
1744
|
-
}] }
|
|
1745
|
-
|
|
1746
|
-
|
|
1868
|
+
}] }]; } });
|
|
1869
|
+
|
|
1870
|
+
class CategoryServiceFacade {
|
|
1871
|
+
constructor(categoryRepositoryFacade, productCatalogFacade, shop) {
|
|
1872
|
+
this.categoryRepositoryFacade = categoryRepositoryFacade;
|
|
1873
|
+
this.productCatalogFacade = productCatalogFacade;
|
|
1874
|
+
this.shop = shop;
|
|
1875
|
+
this.categoryService = new CategoryService(this.categoryRepositoryFacade, this.productCatalogFacade, this.shop);
|
|
1876
|
+
}
|
|
1877
|
+
getCategoryService() {
|
|
1878
|
+
return this.categoryService;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
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 });
|
|
1882
|
+
CategoryServiceFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryServiceFacade });
|
|
1883
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryServiceFacade, decorators: [{
|
|
1884
|
+
type: Injectable
|
|
1885
|
+
}], ctorParameters: function () { return [{ type: CategoryRepositoryFacade }, { type: ProductCatalogFacade }, { type: i3.Shops, decorators: [{
|
|
1886
|
+
type: Inject,
|
|
1887
|
+
args: [DEFAULT_SHOP]
|
|
1888
|
+
}] }]; } });
|
|
1889
|
+
|
|
1890
|
+
class BrandManagerHelper {
|
|
1891
|
+
constructor(productCatalog) {
|
|
1892
|
+
this.productCatalog = productCatalog;
|
|
1893
|
+
this.brandsList = {};
|
|
1894
|
+
}
|
|
1895
|
+
async setBrandsList(options, brands) {
|
|
1896
|
+
const filterBrands = options.filters?.brands;
|
|
1897
|
+
const indexKey = this.buildIndexBrands(options);
|
|
1898
|
+
if (isEmpty(brands) && options.filters) {
|
|
1899
|
+
delete options.filters.brands;
|
|
1900
|
+
}
|
|
1901
|
+
this.brandsList[indexKey] = this.brandsList[indexKey] || brands || (await this.fetchBrandsOnly(options));
|
|
1902
|
+
this.brandsList[indexKey] = this.brandsList[indexKey].filter(Boolean);
|
|
1903
|
+
if (options.filters) {
|
|
1904
|
+
options.filters = {
|
|
1905
|
+
...options.filters,
|
|
1906
|
+
brands: filterBrands,
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
getBrandsList(indexKey) {
|
|
1911
|
+
return this.brandsList[indexKey];
|
|
1912
|
+
}
|
|
1913
|
+
buildIndexBrands(options) {
|
|
1914
|
+
if (options.category)
|
|
1915
|
+
return `category-${options.category.id}`;
|
|
1916
|
+
if (options.term)
|
|
1917
|
+
return `term-${options.term}`;
|
|
1918
|
+
if (options.profile)
|
|
1919
|
+
return `profile-${options.profile.join(',')}`;
|
|
1920
|
+
return '';
|
|
1921
|
+
}
|
|
1922
|
+
async fetchBrandsOnly(options) {
|
|
1923
|
+
return this.productCatalog.productRepository
|
|
1924
|
+
.findCatalog({
|
|
1925
|
+
fields: ['id'],
|
|
1926
|
+
filters: {
|
|
1927
|
+
published: { operator: Where.EQUALS, value: true },
|
|
1928
|
+
},
|
|
1929
|
+
options: {
|
|
1930
|
+
distinct: ['brand'],
|
|
1931
|
+
},
|
|
1932
|
+
}, options.mainGender)
|
|
1933
|
+
.then((result) => result.distinct.brand);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
BrandManagerHelper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: BrandManagerHelper, deps: [{ token: ProductCatalogFacade }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1937
|
+
BrandManagerHelper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: BrandManagerHelper });
|
|
1938
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: BrandManagerHelper, decorators: [{
|
|
1939
|
+
type: Injectable
|
|
1940
|
+
}], ctorParameters: function () { return [{ type: ProductCatalogFacade }]; } });
|
|
1941
|
+
|
|
1942
|
+
class CatalogFilterHelper {
|
|
1943
|
+
buildFilterQuery(filters) {
|
|
1944
|
+
const filterQuery = {};
|
|
1945
|
+
if (filters.clubDiscount?.length) {
|
|
1946
|
+
set(filterQuery, 'price.subscriberDiscountPercentage', {
|
|
1947
|
+
operator: Where.IN,
|
|
1948
|
+
value: filters.clubDiscount,
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
if (filters.brands?.length) {
|
|
1952
|
+
filterQuery.brand = { operator: Where.IN, value: filters.brands };
|
|
1953
|
+
}
|
|
1954
|
+
if (filters.gender?.length) {
|
|
1955
|
+
filterQuery.gender = { operator: Where.IN, value: filters.gender };
|
|
1956
|
+
}
|
|
1957
|
+
if (filters.prices?.min || filters.prices?.max) {
|
|
1958
|
+
const priceField = filters.prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price';
|
|
1959
|
+
const priceFilters = [
|
|
1960
|
+
...(filters.prices.min ? [{ operator: Where.GTE, value: Math.floor(filters.prices.min) }] : []),
|
|
1961
|
+
...(filters.prices.max ? [{ operator: Where.LTE, value: Math.ceil(filters.prices.max) }] : []),
|
|
1962
|
+
];
|
|
1963
|
+
set(filterQuery, priceField, priceFilters);
|
|
1964
|
+
}
|
|
1965
|
+
if (filters.rate) {
|
|
1966
|
+
filterQuery.rate = { operator: Where.GTE, value: filters.rate };
|
|
1967
|
+
}
|
|
1968
|
+
if (filters.tags?.length) {
|
|
1969
|
+
filterQuery.tags = { operator: Where.LIKE, value: filters.tags };
|
|
1970
|
+
}
|
|
1971
|
+
if (filters.customOptions?.length) {
|
|
1972
|
+
filterQuery.filters = { operator: Where.LIKE, value: filters.customOptions };
|
|
1973
|
+
}
|
|
1974
|
+
return filterQuery;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
CatalogFilterHelper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogFilterHelper, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1978
|
+
CatalogFilterHelper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogFilterHelper });
|
|
1979
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogFilterHelper, decorators: [{
|
|
1980
|
+
type: Injectable
|
|
1981
|
+
}] });
|
|
1982
|
+
|
|
1983
|
+
class CatalogSortHelper {
|
|
1984
|
+
buildSortQuery(sort) {
|
|
1985
|
+
if (!sort || sort === 'most-relevant')
|
|
1986
|
+
return {};
|
|
1987
|
+
switch (sort) {
|
|
1988
|
+
case 'best-sellers':
|
|
1989
|
+
return {
|
|
1990
|
+
shoppingCount: 'desc',
|
|
1991
|
+
rate: 'desc',
|
|
1992
|
+
stock: 'desc',
|
|
1993
|
+
name: 'asc',
|
|
1994
|
+
};
|
|
1995
|
+
case 'biggest-price':
|
|
1996
|
+
return {
|
|
1997
|
+
subscriberPrice: 'desc',
|
|
1998
|
+
rate: 'desc',
|
|
1999
|
+
shoppingCount: 'desc',
|
|
2000
|
+
};
|
|
2001
|
+
case 'lowest-price':
|
|
2002
|
+
return {
|
|
2003
|
+
subscriberPrice: 'asc',
|
|
2004
|
+
rate: 'desc',
|
|
2005
|
+
shoppingCount: 'desc',
|
|
2006
|
+
};
|
|
2007
|
+
case 'best-rating':
|
|
2008
|
+
return {
|
|
2009
|
+
rate: 'desc',
|
|
2010
|
+
shoppingCount: 'desc',
|
|
2011
|
+
stock: 'desc',
|
|
2012
|
+
name: 'asc',
|
|
2013
|
+
};
|
|
2014
|
+
case 'news':
|
|
2015
|
+
return { createdAt: 'desc' };
|
|
2016
|
+
case 'biggest-discount':
|
|
2017
|
+
return {
|
|
2018
|
+
subscriberDiscountPercentage: 'desc',
|
|
2019
|
+
rate: 'desc',
|
|
2020
|
+
shoppingCount: 'desc',
|
|
2021
|
+
};
|
|
2022
|
+
default:
|
|
2023
|
+
return {};
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
CatalogSortHelper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogSortHelper, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2028
|
+
CatalogSortHelper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogSortHelper });
|
|
2029
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogSortHelper, decorators: [{
|
|
2030
|
+
type: Injectable
|
|
2031
|
+
}] });
|
|
2032
|
+
|
|
2033
|
+
class ProductFieldsHelper {
|
|
2034
|
+
getStandardFields() {
|
|
2035
|
+
return [
|
|
2036
|
+
'id',
|
|
2037
|
+
'name',
|
|
2038
|
+
'slug',
|
|
2039
|
+
'images',
|
|
2040
|
+
'miniatures',
|
|
2041
|
+
'price',
|
|
2042
|
+
'stock',
|
|
2043
|
+
'published',
|
|
2044
|
+
'CEST',
|
|
2045
|
+
'EAN',
|
|
2046
|
+
'NCM',
|
|
2047
|
+
'brand',
|
|
2048
|
+
'costPrice',
|
|
2049
|
+
'hasVariants',
|
|
2050
|
+
'isKit',
|
|
2051
|
+
'sku',
|
|
2052
|
+
'rate',
|
|
2053
|
+
'tags',
|
|
2054
|
+
'type',
|
|
2055
|
+
'shoppingCount',
|
|
2056
|
+
'gender',
|
|
2057
|
+
'createdAt',
|
|
2058
|
+
'label',
|
|
2059
|
+
'outlet',
|
|
2060
|
+
'group',
|
|
2061
|
+
];
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
ProductFieldsHelper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductFieldsHelper, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2065
|
+
ProductFieldsHelper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductFieldsHelper });
|
|
2066
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductFieldsHelper, decorators: [{
|
|
2067
|
+
type: Injectable
|
|
2068
|
+
}] });
|
|
2069
|
+
|
|
2070
|
+
class CatalogOperationsFacade {
|
|
2071
|
+
constructor(filterHelper, sortHelper, fieldsHelper) {
|
|
2072
|
+
this.filterHelper = filterHelper;
|
|
2073
|
+
this.sortHelper = sortHelper;
|
|
2074
|
+
this.fieldsHelper = fieldsHelper;
|
|
2075
|
+
}
|
|
2076
|
+
getFilterHelper() {
|
|
2077
|
+
return this.filterHelper;
|
|
2078
|
+
}
|
|
2079
|
+
getSortHelper() {
|
|
2080
|
+
return this.sortHelper;
|
|
2081
|
+
}
|
|
2082
|
+
getFieldsHelper() {
|
|
2083
|
+
return this.fieldsHelper;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
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 });
|
|
2087
|
+
CatalogOperationsFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogOperationsFacade });
|
|
2088
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogOperationsFacade, decorators: [{
|
|
2089
|
+
type: Injectable
|
|
2090
|
+
}], ctorParameters: function () { return [{ type: CatalogFilterHelper }, { type: CatalogSortHelper }, { type: ProductFieldsHelper }]; } });
|
|
2091
|
+
|
|
2092
|
+
class ProductManagementFacade {
|
|
2093
|
+
constructor(brandManager, productServices) {
|
|
2094
|
+
this.brandManager = brandManager;
|
|
2095
|
+
this.productServices = productServices;
|
|
2096
|
+
}
|
|
2097
|
+
getBrandManager() {
|
|
2098
|
+
return this.brandManager;
|
|
2099
|
+
}
|
|
2100
|
+
getProductServices() {
|
|
2101
|
+
return this.productServices;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
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 });
|
|
2105
|
+
ProductManagementFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductManagementFacade });
|
|
2106
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ProductManagementFacade, decorators: [{
|
|
2107
|
+
type: Injectable
|
|
2108
|
+
}], ctorParameters: function () { return [{ type: BrandManagerHelper }, { type: undefined, decorators: [{
|
|
2109
|
+
type: Inject,
|
|
2110
|
+
args: ['ProductServicesFacade']
|
|
2111
|
+
}] }]; } });
|
|
2112
|
+
|
|
2113
|
+
class CatalogHelpersService {
|
|
2114
|
+
constructor(catalogOperations, productManagement) {
|
|
2115
|
+
this.catalogOperations = catalogOperations;
|
|
2116
|
+
this.productManagement = productManagement;
|
|
2117
|
+
}
|
|
2118
|
+
getFilterHelper() {
|
|
2119
|
+
return this.catalogOperations.getFilterHelper();
|
|
2120
|
+
}
|
|
2121
|
+
getSortHelper() {
|
|
2122
|
+
return this.catalogOperations.getSortHelper();
|
|
2123
|
+
}
|
|
2124
|
+
getFieldsHelper() {
|
|
2125
|
+
return this.catalogOperations.getFieldsHelper();
|
|
2126
|
+
}
|
|
2127
|
+
getBrandManager() {
|
|
2128
|
+
return this.productManagement.getBrandManager();
|
|
2129
|
+
}
|
|
2130
|
+
getProductServices() {
|
|
2131
|
+
return this.productManagement.getProductServices();
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
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 });
|
|
2135
|
+
CatalogHelpersService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogHelpersService });
|
|
2136
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogHelpersService, decorators: [{
|
|
2137
|
+
type: Injectable
|
|
2138
|
+
}], ctorParameters: function () { return [{ type: CatalogOperationsFacade }, { type: ProductManagementFacade }]; } });
|
|
2139
|
+
|
|
2140
|
+
class CatalogRepositoryService {
|
|
2141
|
+
constructor(productCatalog, productServices) {
|
|
2142
|
+
this.productCatalog = productCatalog;
|
|
2143
|
+
this.productServices = productServices;
|
|
2144
|
+
}
|
|
2145
|
+
getProductCatalog() {
|
|
2146
|
+
return this.productCatalog;
|
|
2147
|
+
}
|
|
2148
|
+
getProductServices() {
|
|
2149
|
+
return this.productServices;
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
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 });
|
|
2153
|
+
CatalogRepositoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogRepositoryService });
|
|
2154
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogRepositoryService, decorators: [{
|
|
2155
|
+
type: Injectable
|
|
2156
|
+
}], ctorParameters: function () { return [{ type: ProductCatalogFacade }, { type: undefined, decorators: [{
|
|
2157
|
+
type: Inject,
|
|
2158
|
+
args: ['ProductServicesFacade']
|
|
2159
|
+
}] }]; } });
|
|
2160
|
+
|
|
2161
|
+
class CatalogService {
|
|
2162
|
+
constructor(searchContext, helpersService, shop) {
|
|
2163
|
+
this.searchContext = searchContext;
|
|
2164
|
+
this.helpersService = helpersService;
|
|
2165
|
+
this.shop = shop;
|
|
2166
|
+
}
|
|
2167
|
+
async fetchProducts(options, optionsCache) {
|
|
2168
|
+
this.validateRequest(options);
|
|
2169
|
+
const searchParams = this.buildSearchParams(options);
|
|
2170
|
+
const { data, count: total, maximum, minimal, distinct, } = await this.searchContext.executeSearch(searchParams, this.shop, optionsCache);
|
|
2171
|
+
await this.helpersService.getBrandManager().setBrandsList(searchParams, distinct?.brand);
|
|
2172
|
+
return this.buildResponse({
|
|
2173
|
+
data,
|
|
2174
|
+
total,
|
|
2175
|
+
maximum,
|
|
2176
|
+
minimal,
|
|
2177
|
+
searchParams,
|
|
2178
|
+
options,
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
async addCustomerToStockNotification(params) {
|
|
2182
|
+
const { shop, productId, name, email } = params;
|
|
2183
|
+
const productServices = this.helpersService.getProductServices();
|
|
2184
|
+
return productServices.productStockNotificationRepository.addCustomerEmail({
|
|
2185
|
+
shop,
|
|
2186
|
+
productId,
|
|
2187
|
+
name,
|
|
2188
|
+
email,
|
|
2189
|
+
});
|
|
2190
|
+
}
|
|
2191
|
+
validateRequest(options) {
|
|
2192
|
+
if (this.hasProfile(options) && options.filters?.customOptions) {
|
|
2193
|
+
throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
|
|
2194
|
+
}
|
|
2195
|
+
if (this.hasProfile(options) && options.filters?.tags) {
|
|
2196
|
+
throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
|
|
2197
|
+
}
|
|
2198
|
+
if (this.hasTerm(options) && options.filters?.customOptions) {
|
|
2199
|
+
throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
buildSearchParams(options) {
|
|
2203
|
+
const limits = this.buildLimitQuery(options);
|
|
2204
|
+
return {
|
|
2205
|
+
category: this.hasCategory(options) ? options.category : undefined,
|
|
2206
|
+
profile: this.hasProfile(options) ? options.profile : undefined,
|
|
2207
|
+
term: this.hasTerm(options) ? options.term : undefined,
|
|
2208
|
+
filters: options.filters,
|
|
2209
|
+
mainGender: options.mainGender,
|
|
2210
|
+
sort: options.sort,
|
|
2211
|
+
limits,
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
buildResponse(params) {
|
|
2215
|
+
const { data, total, maximum, minimal, searchParams } = params;
|
|
2216
|
+
const limits = searchParams.limits;
|
|
2217
|
+
const indexKey = this.helpersService.getBrandManager().buildIndexBrands(searchParams);
|
|
2218
|
+
return {
|
|
2219
|
+
products: {
|
|
2220
|
+
data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)),
|
|
2221
|
+
total,
|
|
2222
|
+
},
|
|
2223
|
+
pages: Math.ceil(total / limits.limit),
|
|
2224
|
+
prices: {
|
|
2225
|
+
price: {
|
|
2226
|
+
min: +(minimal?.price?.price?.toFixed(2) || 0),
|
|
2227
|
+
max: +(maximum?.price?.price?.toFixed(2) || 0),
|
|
2228
|
+
},
|
|
2229
|
+
subscriberPrice: {
|
|
2230
|
+
min: +(minimal?.price?.subscriberPrice?.toFixed(2) || 0),
|
|
2231
|
+
max: +(maximum?.price?.subscriberPrice?.toFixed(2) || 0),
|
|
2232
|
+
},
|
|
2233
|
+
},
|
|
2234
|
+
brands: this.helpersService.getBrandManager().getBrandsList(indexKey),
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2237
|
+
buildLimitQuery(options) {
|
|
2238
|
+
const limit = options?.perPage || 20;
|
|
2239
|
+
return {
|
|
2240
|
+
limit,
|
|
2241
|
+
offset: ((options?.page || 1) - 1) * limit,
|
|
2242
|
+
};
|
|
2243
|
+
}
|
|
2244
|
+
hasProfile(options) {
|
|
2245
|
+
return 'profile' in options;
|
|
2246
|
+
}
|
|
2247
|
+
hasTerm(options) {
|
|
2248
|
+
return 'term' in options;
|
|
2249
|
+
}
|
|
2250
|
+
hasCategory(options) {
|
|
2251
|
+
return 'category' in options;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
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 });
|
|
2255
|
+
CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
|
|
2256
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
|
|
2257
|
+
type: Injectable
|
|
2258
|
+
}], ctorParameters: function () { return [{ type: CatalogSearchContext }, { type: CatalogHelpersService }, { type: i3.Shops, decorators: [{
|
|
2259
|
+
type: Inject,
|
|
2260
|
+
args: [DEFAULT_SHOP]
|
|
1747
2261
|
}] }]; } });
|
|
1748
2262
|
|
|
1749
2263
|
var ProductSorts;
|
|
@@ -1765,15 +2279,14 @@ __decorate([
|
|
|
1765
2279
|
], CategoryWithTree.prototype, "children", void 0);
|
|
1766
2280
|
|
|
1767
2281
|
class WishlistService {
|
|
1768
|
-
constructor(wishlistRepository, shop,
|
|
2282
|
+
constructor(wishlistRepository, shop, logRepository) {
|
|
1769
2283
|
this.wishlistRepository = wishlistRepository;
|
|
1770
2284
|
this.shop = shop;
|
|
1771
|
-
this.productRepository = productRepository;
|
|
1772
|
-
this.productSearch = productSearch;
|
|
1773
2285
|
this.logRepository = logRepository;
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
this.
|
|
2286
|
+
}
|
|
2287
|
+
initializeServices(catalogServiceFacade, categoryServiceFacade) {
|
|
2288
|
+
this.catalogService = catalogServiceFacade.getCatalogService();
|
|
2289
|
+
this.categoryService = categoryServiceFacade.getCategoryService();
|
|
1777
2290
|
}
|
|
1778
2291
|
getCatalogService() {
|
|
1779
2292
|
return this.catalogService;
|
|
@@ -1782,7 +2295,26 @@ class WishlistService {
|
|
|
1782
2295
|
return this.categoryService;
|
|
1783
2296
|
}
|
|
1784
2297
|
async create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
|
|
1785
|
-
const
|
|
2298
|
+
const wishlistData = this.buildWishlistData({
|
|
2299
|
+
title,
|
|
2300
|
+
description,
|
|
2301
|
+
published,
|
|
2302
|
+
userFullName,
|
|
2303
|
+
userPhoto,
|
|
2304
|
+
theme,
|
|
2305
|
+
bannerUrl,
|
|
2306
|
+
personType,
|
|
2307
|
+
personIsSubscriber,
|
|
2308
|
+
personId,
|
|
2309
|
+
});
|
|
2310
|
+
const existingWishlist = await this.findExistingWishlistByPersonId(personId);
|
|
2311
|
+
await this.createWishlistLog(WishlistLogType.CREATE, wishlistData);
|
|
2312
|
+
if (existingWishlist)
|
|
2313
|
+
return existingWishlist;
|
|
2314
|
+
return this.createNewWishlist(wishlistData);
|
|
2315
|
+
}
|
|
2316
|
+
buildWishlistData({ title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, personId, }) {
|
|
2317
|
+
return {
|
|
1786
2318
|
slug: '',
|
|
1787
2319
|
name: title,
|
|
1788
2320
|
description,
|
|
@@ -1805,6 +2337,8 @@ class WishlistService {
|
|
|
1805
2337
|
personType: personType ?? PersonTypes.NONE,
|
|
1806
2338
|
personIsSubscriber: personIsSubscriber ?? false,
|
|
1807
2339
|
};
|
|
2340
|
+
}
|
|
2341
|
+
async findExistingWishlistByPersonId(personId) {
|
|
1808
2342
|
const hasWishlist = await this.wishlistRepository
|
|
1809
2343
|
.find({
|
|
1810
2344
|
filters: {
|
|
@@ -1818,9 +2352,9 @@ class WishlistService {
|
|
|
1818
2352
|
},
|
|
1819
2353
|
})
|
|
1820
2354
|
.then((res) => res.data);
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
2355
|
+
return hasWishlist.length ? hasWishlist.at(0) : null;
|
|
2356
|
+
}
|
|
2357
|
+
async createNewWishlist(data) {
|
|
1824
2358
|
const newWishlist = await this.wishlistRepository.create(data);
|
|
1825
2359
|
await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
|
|
1826
2360
|
return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
|
|
@@ -1897,7 +2431,12 @@ class WishlistService {
|
|
|
1897
2431
|
.then((res) => res.data.at(0));
|
|
1898
2432
|
}
|
|
1899
2433
|
async findProductById(id) {
|
|
1900
|
-
|
|
2434
|
+
if (!this.catalogService) {
|
|
2435
|
+
throw new Error('CatalogService not initialized. Call initializeServices first.');
|
|
2436
|
+
}
|
|
2437
|
+
const helpersService = this.catalogService['helpersService'];
|
|
2438
|
+
const productServices = helpersService.getProductServices();
|
|
2439
|
+
return productServices.productRepository
|
|
1901
2440
|
.find({
|
|
1902
2441
|
fields: ['id', 'sku', 'EAN', 'name', 'brand'],
|
|
1903
2442
|
filters: {
|
|
@@ -1911,103 +2450,122 @@ class WishlistService {
|
|
|
1911
2450
|
case WishlistLogType.CREATE:
|
|
1912
2451
|
case WishlistLogType.UPDATE:
|
|
1913
2452
|
case WishlistLogType.DELETE:
|
|
1914
|
-
await this.
|
|
1915
|
-
collection: 'wishlist',
|
|
1916
|
-
date: new Date(),
|
|
1917
|
-
operation: WishlistLogType.CREATE ? 'CREATE' : WishlistLogType.UPDATE ? 'UPDATE' : 'DELETE',
|
|
1918
|
-
documentId: wishlist.id,
|
|
1919
|
-
document: {
|
|
1920
|
-
id: wishlist.id,
|
|
1921
|
-
shop: this.shop,
|
|
1922
|
-
name: wishlist.name,
|
|
1923
|
-
description: wishlist.description,
|
|
1924
|
-
published: wishlist.published,
|
|
1925
|
-
type: type,
|
|
1926
|
-
personType: wishlist.personType,
|
|
1927
|
-
personId: wishlist.personId,
|
|
1928
|
-
personName: wishlist.personName,
|
|
1929
|
-
personIsSubscriber: wishlist.personIsSubscriber,
|
|
1930
|
-
},
|
|
1931
|
-
});
|
|
2453
|
+
await this.createWishlistOperationLog(type, wishlist);
|
|
1932
2454
|
break;
|
|
1933
2455
|
case WishlistLogType.ADD_PRODUCT:
|
|
1934
2456
|
case WishlistLogType.REMOVE_PRODUCT:
|
|
1935
|
-
await this.
|
|
1936
|
-
collection: 'wishlist',
|
|
1937
|
-
date: new Date(),
|
|
1938
|
-
operation: 'UPDATE',
|
|
1939
|
-
documentId: wishlist.id,
|
|
1940
|
-
document: {
|
|
1941
|
-
id: wishlist.id,
|
|
1942
|
-
shop: this.shop,
|
|
1943
|
-
name: wishlist.name,
|
|
1944
|
-
description: wishlist.description,
|
|
1945
|
-
published: wishlist.published,
|
|
1946
|
-
type: type,
|
|
1947
|
-
personType: wishlist.personType,
|
|
1948
|
-
personId: wishlist.personId,
|
|
1949
|
-
personName: wishlist.personName,
|
|
1950
|
-
personIsSubscriber: wishlist.personIsSubscriber,
|
|
1951
|
-
productId: product.id,
|
|
1952
|
-
productEAN: product.EAN,
|
|
1953
|
-
productSKU: product.sku,
|
|
1954
|
-
productName: product.name,
|
|
1955
|
-
productBrand: product.brand,
|
|
1956
|
-
},
|
|
1957
|
-
});
|
|
2457
|
+
await this.createWishlistProductLog(type, wishlist, product);
|
|
1958
2458
|
break;
|
|
1959
2459
|
default:
|
|
1960
2460
|
break;
|
|
1961
2461
|
}
|
|
1962
2462
|
}
|
|
2463
|
+
async createWishlistOperationLog(type, wishlist) {
|
|
2464
|
+
const operation = this.getOperationTypeFromWishlistLogType(type);
|
|
2465
|
+
await this.logRepository.create({
|
|
2466
|
+
collection: 'wishlist',
|
|
2467
|
+
date: new Date(),
|
|
2468
|
+
operation,
|
|
2469
|
+
documentId: wishlist.id,
|
|
2470
|
+
document: this.buildWishlistLogDocument(wishlist, type),
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
async createWishlistProductLog(type, wishlist, product) {
|
|
2474
|
+
await this.logRepository.create({
|
|
2475
|
+
collection: 'wishlist',
|
|
2476
|
+
date: new Date(),
|
|
2477
|
+
operation: 'UPDATE',
|
|
2478
|
+
documentId: wishlist.id,
|
|
2479
|
+
document: {
|
|
2480
|
+
...this.buildWishlistLogDocument(wishlist, type),
|
|
2481
|
+
...this.buildProductLogData(product),
|
|
2482
|
+
},
|
|
2483
|
+
});
|
|
2484
|
+
}
|
|
2485
|
+
getOperationTypeFromWishlistLogType(type) {
|
|
2486
|
+
if (type === WishlistLogType.CREATE)
|
|
2487
|
+
return 'CREATE';
|
|
2488
|
+
if (type === WishlistLogType.UPDATE)
|
|
2489
|
+
return 'UPDATE';
|
|
2490
|
+
return 'DELETE';
|
|
2491
|
+
}
|
|
2492
|
+
buildWishlistLogDocument(wishlist, type) {
|
|
2493
|
+
return {
|
|
2494
|
+
id: wishlist.id,
|
|
2495
|
+
shop: this.shop,
|
|
2496
|
+
name: wishlist.name,
|
|
2497
|
+
description: wishlist.description,
|
|
2498
|
+
published: wishlist.published,
|
|
2499
|
+
type: type,
|
|
2500
|
+
personType: wishlist.personType,
|
|
2501
|
+
personId: wishlist.personId,
|
|
2502
|
+
personName: wishlist.personName,
|
|
2503
|
+
personIsSubscriber: wishlist.personIsSubscriber,
|
|
2504
|
+
};
|
|
2505
|
+
}
|
|
2506
|
+
buildProductLogData(product) {
|
|
2507
|
+
return {
|
|
2508
|
+
productId: product.id,
|
|
2509
|
+
productEAN: product.EAN,
|
|
2510
|
+
productSKU: product.sku,
|
|
2511
|
+
productName: product.name,
|
|
2512
|
+
productBrand: product.brand,
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
1963
2515
|
}
|
|
1964
|
-
WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: '
|
|
2516
|
+
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 });
|
|
1965
2517
|
WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
|
|
1966
2518
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
|
|
1967
2519
|
type: Injectable
|
|
1968
2520
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1969
2521
|
type: Inject,
|
|
1970
2522
|
args: ['WishlistRepository']
|
|
1971
|
-
}] }, { type:
|
|
2523
|
+
}] }, { type: i3.Shops, decorators: [{
|
|
1972
2524
|
type: Inject,
|
|
1973
2525
|
args: [DEFAULT_SHOP]
|
|
1974
2526
|
}] }, { type: undefined, decorators: [{
|
|
1975
2527
|
type: Inject,
|
|
1976
|
-
args: ['
|
|
1977
|
-
}] }
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2528
|
+
args: ['LogRepository']
|
|
2529
|
+
}] }]; } });
|
|
2530
|
+
|
|
2531
|
+
class CouponRepositoriesFacade {
|
|
2532
|
+
constructor(couponRepository, orderRepository, categoryRepository) {
|
|
2533
|
+
this.couponRepository = couponRepository;
|
|
2534
|
+
this.orderRepository = orderRepository;
|
|
2535
|
+
this.categoryRepository = categoryRepository;
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
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 });
|
|
2539
|
+
CouponRepositoriesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade });
|
|
2540
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponRepositoriesFacade, decorators: [{
|
|
2541
|
+
type: Injectable
|
|
2542
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1984
2543
|
type: Inject,
|
|
1985
|
-
args: ['
|
|
2544
|
+
args: ['CouponRepository']
|
|
1986
2545
|
}] }, { type: undefined, decorators: [{
|
|
1987
2546
|
type: Inject,
|
|
1988
|
-
args: ['
|
|
2547
|
+
args: ['OrderRepository']
|
|
1989
2548
|
}] }, { type: undefined, decorators: [{
|
|
1990
2549
|
type: Inject,
|
|
1991
|
-
args: ['
|
|
2550
|
+
args: ['CategoryRepository']
|
|
1992
2551
|
}] }]; } });
|
|
1993
2552
|
|
|
1994
2553
|
class CouponService {
|
|
1995
|
-
constructor(
|
|
1996
|
-
this.
|
|
1997
|
-
this.
|
|
1998
|
-
this.orderRepository = orderRepository;
|
|
1999
|
-
this.categoryRepository = categoryRepository;
|
|
2554
|
+
constructor(repositoriesFacade, configurationFacade) {
|
|
2555
|
+
this.repositoriesFacade = repositoriesFacade;
|
|
2556
|
+
this.configurationFacade = configurationFacade;
|
|
2000
2557
|
this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
|
|
2001
2558
|
}
|
|
2002
|
-
checkCoupon(
|
|
2003
|
-
|
|
2559
|
+
checkCoupon(params) {
|
|
2560
|
+
const { nickname, checkoutType, checkout, plan } = params;
|
|
2561
|
+
return from(this.repositoriesFacade.couponRepository
|
|
2004
2562
|
.find({
|
|
2005
2563
|
filters: {
|
|
2006
2564
|
nickname: { operator: Where.EQUALS, value: nickname },
|
|
2007
2565
|
active: { operator: Where.EQUALS, value: true },
|
|
2008
2566
|
},
|
|
2009
2567
|
})
|
|
2010
|
-
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
|
|
2568
|
+
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation({ coupon: couponValid, checkoutType, checkout, plan })), map((couponValidated) => couponValidated));
|
|
2011
2569
|
}
|
|
2012
2570
|
async couponValidation(coupon, checkoutType) {
|
|
2013
2571
|
if (!coupon)
|
|
@@ -2016,7 +2574,7 @@ class CouponService {
|
|
|
2016
2574
|
throw 'Cupom inválido.';
|
|
2017
2575
|
if (coupon?.expiresIn && (coupon?.expiresIn).getTime() < new Date().getTime())
|
|
2018
2576
|
throw 'Cupom expirado.';
|
|
2019
|
-
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
2577
|
+
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.configurationFacade.defaultShop;
|
|
2020
2578
|
if (!isInShop)
|
|
2021
2579
|
throw 'Cupom inválido para loja.';
|
|
2022
2580
|
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
@@ -2024,42 +2582,73 @@ class CouponService {
|
|
|
2024
2582
|
throw 'Cupom inválido. Erro de checkout.';
|
|
2025
2583
|
return coupon;
|
|
2026
2584
|
}
|
|
2027
|
-
async couponRulesValidation(
|
|
2585
|
+
async couponRulesValidation(params) {
|
|
2586
|
+
const { coupon, checkoutType, checkout, plan } = params;
|
|
2028
2587
|
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2588
|
+
return this.validateSubscriptionCoupon(coupon, plan);
|
|
2589
|
+
}
|
|
2590
|
+
return this.validateEcommerceCoupon(coupon, checkoutType, checkout);
|
|
2591
|
+
}
|
|
2592
|
+
validateSubscriptionCoupon(coupon, plan) {
|
|
2593
|
+
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase()) {
|
|
2594
|
+
throw 'Cupom inválido para sua assinatura.';
|
|
2032
2595
|
}
|
|
2033
|
-
|
|
2596
|
+
return coupon;
|
|
2597
|
+
}
|
|
2598
|
+
async validateEcommerceCoupon(coupon, checkoutType, checkout) {
|
|
2599
|
+
this.validateUserEligibility(coupon, checkout?.user);
|
|
2600
|
+
await this.validateUsageLimits(coupon, checkoutType, checkout);
|
|
2601
|
+
await this.validateProductEligibility(coupon, checkout);
|
|
2602
|
+
return coupon;
|
|
2603
|
+
}
|
|
2604
|
+
validateUserEligibility(coupon, user) {
|
|
2605
|
+
const validUser = this.coupomUserValidation(coupon, user);
|
|
2034
2606
|
if (!validUser)
|
|
2035
2607
|
throw 'Usuário não elegível.';
|
|
2608
|
+
}
|
|
2609
|
+
async validateUsageLimits(coupon, checkoutType, checkout) {
|
|
2036
2610
|
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
2037
2611
|
if (couponUseLimits.firstOrder) {
|
|
2038
|
-
|
|
2039
|
-
if (couponUseLimits.firstOrder && ordersUser.length >= 1)
|
|
2040
|
-
throw 'Limite de uso atingido';
|
|
2612
|
+
await this.validateFirstOrderLimit(checkout.user.email);
|
|
2041
2613
|
}
|
|
2042
2614
|
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2615
|
+
await this.validateCouponUsageLimits(coupon, couponUseLimits, checkout.user.email);
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
async validateFirstOrderLimit(userEmail) {
|
|
2619
|
+
const ordersUser = await this.getOrdersFromUser(userEmail.toLocaleLowerCase());
|
|
2620
|
+
if (ordersUser.length >= 1)
|
|
2621
|
+
throw 'Limite de uso atingido';
|
|
2622
|
+
}
|
|
2623
|
+
async validateCouponUsageLimits(coupon, couponUseLimits, userEmail) {
|
|
2624
|
+
const ordersCoupon = await this.getOrdersWithCoupon(coupon);
|
|
2625
|
+
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total) {
|
|
2626
|
+
throw 'Limite de uso atingido.';
|
|
2051
2627
|
}
|
|
2628
|
+
if (couponUseLimits.limitedPerUser) {
|
|
2629
|
+
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, userEmail);
|
|
2630
|
+
if (ordersWithUser > 0)
|
|
2631
|
+
throw 'Limite de uso por usuário atingido.';
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
async validateProductEligibility(coupon, checkout) {
|
|
2052
2635
|
const hasProductCategories = await this.hasProductCategories(coupon, checkout);
|
|
2053
2636
|
if (!hasProductCategories)
|
|
2054
2637
|
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
2055
2638
|
const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
|
|
2056
2639
|
if (!hasMinSubTotal) {
|
|
2057
|
-
|
|
2058
|
-
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.`;
|
|
2059
|
-
}
|
|
2060
|
-
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido.`;
|
|
2640
|
+
this.throwMinSubTotalError(coupon);
|
|
2061
2641
|
}
|
|
2062
|
-
|
|
2642
|
+
}
|
|
2643
|
+
throwMinSubTotalError(coupon) {
|
|
2644
|
+
const formattedValue = Intl.NumberFormat('pt-BR', {
|
|
2645
|
+
style: 'currency',
|
|
2646
|
+
currency: 'BRL',
|
|
2647
|
+
}).format(coupon.minSubTotalValue);
|
|
2648
|
+
if (coupon.productsCategories?.length) {
|
|
2649
|
+
throw `Valor mínimo de ${formattedValue} não atingido na(s) categoria(s) elegíveis para o desconto.`;
|
|
2650
|
+
}
|
|
2651
|
+
throw `Valor mínimo de ${formattedValue} não atingido.`;
|
|
2063
2652
|
}
|
|
2064
2653
|
calcDiscountSubscription(coupon, checkout) {
|
|
2065
2654
|
let discount = 0;
|
|
@@ -2079,23 +2668,23 @@ class CouponService {
|
|
|
2079
2668
|
return false;
|
|
2080
2669
|
}
|
|
2081
2670
|
async hasProductCategories(coupon, checkout) {
|
|
2082
|
-
if (!coupon.productsCategories
|
|
2671
|
+
if (!coupon.productsCategories?.length) {
|
|
2083
2672
|
return true;
|
|
2084
2673
|
}
|
|
2085
2674
|
const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
|
|
2086
2675
|
const hasCategories = checkout.lineItems?.filter((item) => {
|
|
2087
2676
|
if (item.isGift)
|
|
2088
2677
|
return false;
|
|
2089
|
-
if (!item.categories
|
|
2678
|
+
if (!item.categories?.length)
|
|
2090
2679
|
return true;
|
|
2091
2680
|
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2092
2681
|
});
|
|
2093
|
-
return hasCategories
|
|
2682
|
+
return hasCategories?.length ? true : false;
|
|
2094
2683
|
}
|
|
2095
2684
|
coupomUserValidation(coupon, user) {
|
|
2096
2685
|
if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
|
|
2097
2686
|
return true;
|
|
2098
|
-
|
|
2687
|
+
const userTypes = [];
|
|
2099
2688
|
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
|
|
2100
2689
|
this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
|
|
2101
2690
|
userTypes.push(Exclusivities.COLLABORATORS);
|
|
@@ -2117,11 +2706,11 @@ class CouponService {
|
|
|
2117
2706
|
async getCouponCategoriesId(productsCategories) {
|
|
2118
2707
|
const couponCategories = [];
|
|
2119
2708
|
for (let index = 0; index < productsCategories.length; index++) {
|
|
2120
|
-
const category = await this.categoryRepository.get({
|
|
2709
|
+
const category = await this.repositoriesFacade.categoryRepository.get({
|
|
2121
2710
|
id: productsCategories[index],
|
|
2122
2711
|
});
|
|
2123
2712
|
if (category) {
|
|
2124
|
-
const children = await this.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
2713
|
+
const children = await this.repositoriesFacade.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
2125
2714
|
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
2126
2715
|
}
|
|
2127
2716
|
}
|
|
@@ -2130,7 +2719,7 @@ class CouponService {
|
|
|
2130
2719
|
async getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
2131
2720
|
let lineItensDiscount = [];
|
|
2132
2721
|
const couponCategories = await this.getCouponCategoriesId(productsCategories);
|
|
2133
|
-
if (productsCategories
|
|
2722
|
+
if (productsCategories?.length) {
|
|
2134
2723
|
lineItensDiscount = checkout.lineItems?.filter((item) => {
|
|
2135
2724
|
if (item.isGift)
|
|
2136
2725
|
return false;
|
|
@@ -2148,12 +2737,12 @@ class CouponService {
|
|
|
2148
2737
|
calcCheckoutSubtotal(lineItens, user) {
|
|
2149
2738
|
return (lineItens
|
|
2150
2739
|
?.filter((item) => !item.isGift)
|
|
2151
|
-
.reduce((acc, curr) => user?.isSubscriber && curr.price
|
|
2740
|
+
.reduce((acc, curr) => user?.isSubscriber && curr.price?.subscriberPrice
|
|
2152
2741
|
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
2153
2742
|
: acc + curr.pricePaid * curr.quantity, 0) || 0);
|
|
2154
2743
|
}
|
|
2155
2744
|
async getOrdersWithCoupon(coupon) {
|
|
2156
|
-
return await this.orderRepository
|
|
2745
|
+
return await this.repositoriesFacade.orderRepository
|
|
2157
2746
|
.find({
|
|
2158
2747
|
filters: {
|
|
2159
2748
|
coupon: { id: coupon.id },
|
|
@@ -2163,7 +2752,7 @@ class CouponService {
|
|
|
2163
2752
|
.then((result) => result.data);
|
|
2164
2753
|
}
|
|
2165
2754
|
async getOrdersFromUser(email) {
|
|
2166
|
-
return await this.orderRepository
|
|
2755
|
+
return await this.repositoriesFacade.orderRepository
|
|
2167
2756
|
.find({
|
|
2168
2757
|
filters: {
|
|
2169
2758
|
user: { email: { operator: Where.EQUALS, value: email } },
|
|
@@ -2183,7 +2772,7 @@ class CouponService {
|
|
|
2183
2772
|
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
2184
2773
|
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
2185
2774
|
else
|
|
2186
|
-
couponUseLimits = user
|
|
2775
|
+
couponUseLimits = user?.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
2187
2776
|
}
|
|
2188
2777
|
else {
|
|
2189
2778
|
couponUseLimits = coupon.useLimits.subscription;
|
|
@@ -2191,26 +2780,14 @@ class CouponService {
|
|
|
2191
2780
|
return couponUseLimits;
|
|
2192
2781
|
}
|
|
2193
2782
|
}
|
|
2194
|
-
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token:
|
|
2783
|
+
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 });
|
|
2195
2784
|
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
2196
2785
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
2197
2786
|
type: Injectable,
|
|
2198
2787
|
args: [{
|
|
2199
2788
|
providedIn: 'root',
|
|
2200
2789
|
}]
|
|
2201
|
-
}], ctorParameters: function () { return [{ type:
|
|
2202
|
-
type: Inject,
|
|
2203
|
-
args: ['CouponRepository']
|
|
2204
|
-
}] }, { type: i1$3.Shops, decorators: [{
|
|
2205
|
-
type: Inject,
|
|
2206
|
-
args: [DEFAULT_SHOP]
|
|
2207
|
-
}] }, { type: undefined, decorators: [{
|
|
2208
|
-
type: Inject,
|
|
2209
|
-
args: ['OrderRepository']
|
|
2210
|
-
}] }, { type: undefined, decorators: [{
|
|
2211
|
-
type: Inject,
|
|
2212
|
-
args: ['CategoryRepository']
|
|
2213
|
-
}] }]; } });
|
|
2790
|
+
}], ctorParameters: function () { return [{ type: CouponRepositoriesFacade }, { type: ConfigurationFacade }]; } });
|
|
2214
2791
|
|
|
2215
2792
|
class CheckoutSubscriptionService {
|
|
2216
2793
|
constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
|
|
@@ -2226,9 +2803,14 @@ class CheckoutSubscriptionService {
|
|
|
2226
2803
|
clearCheckoutSubscriptionFromSession() {
|
|
2227
2804
|
return this.dataPersistence.remove('checkoutSubscriptionId');
|
|
2228
2805
|
}
|
|
2229
|
-
checkCoupon(nickname,
|
|
2806
|
+
checkCoupon(nickname, _userEmail) {
|
|
2230
2807
|
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
2231
|
-
.checkCoupon(
|
|
2808
|
+
.checkCoupon({
|
|
2809
|
+
nickname,
|
|
2810
|
+
checkoutType: CheckoutTypes.SUBSCRIPTION,
|
|
2811
|
+
checkout,
|
|
2812
|
+
plan: checkout.subscriptionPlan.name,
|
|
2813
|
+
})
|
|
2232
2814
|
.pipe()));
|
|
2233
2815
|
}
|
|
2234
2816
|
calcDiscountSubscription(coupon) {
|
|
@@ -2259,33 +2841,53 @@ class UtilHelper {
|
|
|
2259
2841
|
static createSlug(name) {
|
|
2260
2842
|
return name
|
|
2261
2843
|
.toLowerCase()
|
|
2262
|
-
.replace(/\s+/g, '-')
|
|
2263
|
-
.replace(/[ãàáäâ]/g, 'a')
|
|
2264
|
-
.replace(/[ẽèéëê]/g, 'e')
|
|
2265
|
-
.replace(/[ìíïî]/g, 'i')
|
|
2266
|
-
.replace(/[õòóöô]/g, 'o')
|
|
2267
|
-
.replace(/[ùúüû]/g, 'u')
|
|
2268
|
-
.replace(/[ñ]/g, 'n')
|
|
2269
|
-
.replace(/[ç]/g, 'c')
|
|
2270
|
-
.replace(/[&]/g, 'and')
|
|
2271
|
-
.replace(/[^\w
|
|
2272
|
-
.replace(
|
|
2844
|
+
.replace(/\s+/g, '-')
|
|
2845
|
+
.replace(/[ãàáäâ]/g, 'a')
|
|
2846
|
+
.replace(/[ẽèéëê]/g, 'e')
|
|
2847
|
+
.replace(/[ìíïî]/g, 'i')
|
|
2848
|
+
.replace(/[õòóöô]/g, 'o')
|
|
2849
|
+
.replace(/[ùúüû]/g, 'u')
|
|
2850
|
+
.replace(/[ñ]/g, 'n')
|
|
2851
|
+
.replace(/[ç]/g, 'c')
|
|
2852
|
+
.replace(/[&]/g, 'and')
|
|
2853
|
+
.replace(/[^\w-]+/g, '')
|
|
2854
|
+
.replace(/--+/g, '-');
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
class HomeShopRepositoriesFacade {
|
|
2859
|
+
constructor(categoryRepository, homeRepository, productRepository) {
|
|
2860
|
+
this.categoryRepository = categoryRepository;
|
|
2861
|
+
this.homeRepository = homeRepository;
|
|
2862
|
+
this.productRepository = productRepository;
|
|
2273
2863
|
}
|
|
2274
2864
|
}
|
|
2865
|
+
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 });
|
|
2866
|
+
HomeShopRepositoriesFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopRepositoriesFacade });
|
|
2867
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopRepositoriesFacade, decorators: [{
|
|
2868
|
+
type: Injectable
|
|
2869
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
2870
|
+
type: Inject,
|
|
2871
|
+
args: ['CategoryRepository']
|
|
2872
|
+
}] }, { type: undefined, decorators: [{
|
|
2873
|
+
type: Inject,
|
|
2874
|
+
args: ['HomeRepository']
|
|
2875
|
+
}] }, { type: undefined, decorators: [{
|
|
2876
|
+
type: Inject,
|
|
2877
|
+
args: ['ProductRepository']
|
|
2878
|
+
}] }]; } });
|
|
2275
2879
|
|
|
2276
2880
|
class HomeShopService {
|
|
2277
2881
|
get homeId() {
|
|
2278
|
-
if (this.defaultShop === Shops.GLAMSHOP)
|
|
2882
|
+
if (this.configurationFacade.defaultShop === Shops.GLAMSHOP)
|
|
2279
2883
|
return 'glamshop';
|
|
2280
|
-
if (this.defaultShop === Shops.MENSMARKET)
|
|
2884
|
+
if (this.configurationFacade.defaultShop === Shops.MENSMARKET)
|
|
2281
2885
|
return 'mens_market';
|
|
2282
2886
|
return null;
|
|
2283
2887
|
}
|
|
2284
|
-
constructor(
|
|
2285
|
-
this.
|
|
2286
|
-
this.
|
|
2287
|
-
this.productRepository = productRepository;
|
|
2288
|
-
this.defaultShop = defaultShop;
|
|
2888
|
+
constructor(repositoriesFacade, configurationFacade) {
|
|
2889
|
+
this.repositoriesFacade = repositoriesFacade;
|
|
2890
|
+
this.configurationFacade = configurationFacade;
|
|
2289
2891
|
this.buildCategoryGroupWithRequiredData = (group) => ({
|
|
2290
2892
|
category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
|
|
2291
2893
|
products: group?.products?.map((product) => Product.toInstance(pick(product?.toPlain() || {}, [
|
|
@@ -2336,14 +2938,20 @@ class HomeShopService {
|
|
|
2336
2938
|
getMinValueForFreeShipping() {
|
|
2337
2939
|
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
2338
2940
|
}
|
|
2339
|
-
getDiscoverProducts(
|
|
2340
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(
|
|
2941
|
+
getDiscoverProducts(_gender) {
|
|
2942
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.repositoriesFacade.categoryRepository.getCategoriesForHome({
|
|
2943
|
+
categoryIds: home.discoverCategories,
|
|
2944
|
+
shop: this.configurationFacade.defaultShop,
|
|
2945
|
+
})).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
2341
2946
|
}
|
|
2342
|
-
getFeaturedProducts(
|
|
2343
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(
|
|
2947
|
+
getFeaturedProducts(_gender) {
|
|
2948
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.repositoriesFacade.categoryRepository.getCategoriesForHome({
|
|
2949
|
+
categoryIds: home.featuredCategories,
|
|
2950
|
+
shop: this.configurationFacade.defaultShop,
|
|
2951
|
+
})).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
2344
2952
|
}
|
|
2345
2953
|
getVerticalProducts(gender) {
|
|
2346
|
-
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({
|
|
2954
|
+
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({
|
|
2347
2955
|
filters: {
|
|
2348
2956
|
categories: { operator: Where.IN, value: [category.id] },
|
|
2349
2957
|
...(gender ? { tags: { operator: Where.IN, value: [gender] } } : {}),
|
|
@@ -2355,8 +2963,8 @@ class HomeShopService {
|
|
|
2355
2963
|
return of(this.homeConfiguration).pipe(concatMap((home) => home
|
|
2356
2964
|
? of(home)
|
|
2357
2965
|
: !this.homeId
|
|
2358
|
-
? throwError(new RequiredArgumentError(['homeId']))
|
|
2359
|
-
: from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
|
|
2966
|
+
? throwError(() => new RequiredArgumentError(['homeId']))
|
|
2967
|
+
: from(this.repositoriesFacade.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
|
|
2360
2968
|
}
|
|
2361
2969
|
saveHomeData(homeData) {
|
|
2362
2970
|
const data = {
|
|
@@ -2364,7 +2972,7 @@ class HomeShopService {
|
|
|
2364
2972
|
expiresAt: add(new Date(), { hours: 1 }),
|
|
2365
2973
|
data: homeData,
|
|
2366
2974
|
};
|
|
2367
|
-
return from(this.homeRepository.update({
|
|
2975
|
+
return from(this.repositoriesFacade.homeRepository.update({
|
|
2368
2976
|
id: this.homeId,
|
|
2369
2977
|
data,
|
|
2370
2978
|
})).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
|
|
@@ -2373,23 +2981,11 @@ class HomeShopService {
|
|
|
2373
2981
|
return this.homeId === 'mens_market' ? 'masculino' : undefined;
|
|
2374
2982
|
}
|
|
2375
2983
|
}
|
|
2376
|
-
HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, deps: [{ token:
|
|
2984
|
+
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 });
|
|
2377
2985
|
HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
|
|
2378
2986
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
|
|
2379
2987
|
type: Injectable
|
|
2380
|
-
}], ctorParameters: function () { return [{ type:
|
|
2381
|
-
type: Inject,
|
|
2382
|
-
args: ['CategoryRepository']
|
|
2383
|
-
}] }, { type: undefined, decorators: [{
|
|
2384
|
-
type: Inject,
|
|
2385
|
-
args: ['HomeRepository']
|
|
2386
|
-
}] }, { type: undefined, decorators: [{
|
|
2387
|
-
type: Inject,
|
|
2388
|
-
args: ['ProductRepository']
|
|
2389
|
-
}] }, { type: i1$3.Shops, decorators: [{
|
|
2390
|
-
type: Inject,
|
|
2391
|
-
args: [DEFAULT_SHOP]
|
|
2392
|
-
}] }]; } });
|
|
2988
|
+
}], ctorParameters: function () { return [{ type: HomeShopRepositoriesFacade }, { type: ConfigurationFacade }]; } });
|
|
2393
2989
|
|
|
2394
2990
|
class OrderService {
|
|
2395
2991
|
constructor(angularFirestore, orderRepository) {
|
|
@@ -2408,7 +3004,7 @@ OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "1
|
|
|
2408
3004
|
OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
|
|
2409
3005
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
2410
3006
|
type: Injectable
|
|
2411
|
-
}], ctorParameters: function () { return [{ type: i1$1.Firestore }, { type:
|
|
3007
|
+
}], ctorParameters: function () { return [{ type: i1$1.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
|
|
2412
3008
|
type: Inject,
|
|
2413
3009
|
args: ['OrderRepository']
|
|
2414
3010
|
}] }]; } });
|
|
@@ -2418,28 +3014,44 @@ class AngularConnectModule {
|
|
|
2418
3014
|
return {
|
|
2419
3015
|
ngModule: AngularConnectModule,
|
|
2420
3016
|
providers: [
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
{
|
|
2424
|
-
provide: CATEGORY_STRUCTURE,
|
|
2425
|
-
useClass: isNil(options?.oldCategoryStructure) || options?.oldCategoryStructure
|
|
2426
|
-
? OldCategoryStructureAdapter
|
|
2427
|
-
: NewCategoryStructureAdapter,
|
|
2428
|
-
},
|
|
2429
|
-
{ provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
|
|
2430
|
-
...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
|
|
2431
|
-
...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
|
|
2432
|
-
...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
|
|
2433
|
-
...(isNil(options?.vertexConfig) ? [] : [{ provide: VERTEX_CONFIG, useValue: options.vertexConfig }]),
|
|
2434
|
-
...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
|
|
2435
|
-
...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
|
|
2436
|
-
...(isNil(options?.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
|
|
3017
|
+
...this.buildCoreProviders(nameOrConfig, options),
|
|
3018
|
+
...this.buildConditionalProviders(defaultShop, options),
|
|
2437
3019
|
],
|
|
2438
3020
|
};
|
|
2439
3021
|
}
|
|
3022
|
+
static buildCoreProviders(nameOrConfig, options) {
|
|
3023
|
+
return [
|
|
3024
|
+
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
3025
|
+
{ provide: APP_CHECK_PROVIDER, useValue: options.appCheckProvider },
|
|
3026
|
+
{
|
|
3027
|
+
provide: CATEGORY_STRUCTURE,
|
|
3028
|
+
useClass: this.selectCategoryStructureAdapter(options.oldCategoryStructure),
|
|
3029
|
+
},
|
|
3030
|
+
{ provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
|
|
3031
|
+
];
|
|
3032
|
+
}
|
|
3033
|
+
static buildConditionalProviders(defaultShop, options) {
|
|
3034
|
+
return [
|
|
3035
|
+
...this.createProviderIfExists(DEFAULT_SHOP, defaultShop),
|
|
3036
|
+
...this.createProviderIfExists(FIREBASE_OPTIONS, options.firebase),
|
|
3037
|
+
...this.createProviderIfExists(ES_CONFIG, options.elasticSearch),
|
|
3038
|
+
...this.createProviderIfExists(VERTEX_CONFIG, options.vertexConfig),
|
|
3039
|
+
...this.createProviderIfExists(HASURA_OPTIONS, options.hasura),
|
|
3040
|
+
...this.createProviderIfExists(BACKEND_URL, options.backendUrl),
|
|
3041
|
+
...this.createProviderIfExists(STORAGE_BASE_URL, options.storageBaseUrl),
|
|
3042
|
+
];
|
|
3043
|
+
}
|
|
3044
|
+
static selectCategoryStructureAdapter(oldCategoryStructure) {
|
|
3045
|
+
return isNil(oldCategoryStructure) || oldCategoryStructure
|
|
3046
|
+
? OldCategoryStructureAdapter
|
|
3047
|
+
: NewCategoryStructureAdapter;
|
|
3048
|
+
}
|
|
3049
|
+
static createProviderIfExists(token, value) {
|
|
3050
|
+
return isNil(value) ? [] : [{ provide: token, useValue: value }];
|
|
3051
|
+
}
|
|
2440
3052
|
}
|
|
2441
3053
|
AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2442
|
-
AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$
|
|
3054
|
+
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,
|
|
2443
3055
|
AngularVertexSeachModule,
|
|
2444
3056
|
AngularFirebaseAuthModule,
|
|
2445
3057
|
AngularFirestoreModule,
|
|
@@ -2455,6 +3067,42 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
|
|
|
2455
3067
|
HomeShopService,
|
|
2456
3068
|
OrderService,
|
|
2457
3069
|
WishlistService,
|
|
3070
|
+
ConfigurationFacade,
|
|
3071
|
+
CartServicesFacade,
|
|
3072
|
+
CheckoutRepositoriesFacade,
|
|
3073
|
+
CheckoutDependenciesFacade,
|
|
3074
|
+
CategoryRepositoryFacade,
|
|
3075
|
+
ProductCatalogFacade,
|
|
3076
|
+
CatalogServiceFacade,
|
|
3077
|
+
CategoryServiceFacade,
|
|
3078
|
+
CatalogStrategiesFacade,
|
|
3079
|
+
CatalogOperationsFacade,
|
|
3080
|
+
ProductManagementFacade,
|
|
3081
|
+
{
|
|
3082
|
+
provide: 'ProductServicesFacade',
|
|
3083
|
+
useFactory: (productStockNotificationRepository, categoryRepository, productSearch) => ({
|
|
3084
|
+
productStockNotificationRepository,
|
|
3085
|
+
categoryRepository,
|
|
3086
|
+
productSearch,
|
|
3087
|
+
}),
|
|
3088
|
+
deps: ['ProductStockNotificationRepository', 'CategoryRepository', 'ProductSearch'],
|
|
3089
|
+
},
|
|
3090
|
+
CatalogFilterHelper,
|
|
3091
|
+
CatalogSortHelper,
|
|
3092
|
+
ProductFieldsHelper,
|
|
3093
|
+
BrandManagerHelper,
|
|
3094
|
+
CatalogRepositoryService,
|
|
3095
|
+
CatalogHelpersService,
|
|
3096
|
+
CategorySearchStrategy,
|
|
3097
|
+
TermSearchStrategy,
|
|
3098
|
+
ProfileSearchStrategy,
|
|
3099
|
+
{
|
|
3100
|
+
provide: CatalogSearchContext,
|
|
3101
|
+
useFactory: (categoryStrategy, termStrategy, profileStrategy) => {
|
|
3102
|
+
return new CatalogSearchContext(categoryStrategy, termStrategy, profileStrategy);
|
|
3103
|
+
},
|
|
3104
|
+
deps: [CategorySearchStrategy, TermSearchStrategy, ProfileSearchStrategy],
|
|
3105
|
+
},
|
|
2458
3106
|
{
|
|
2459
3107
|
provide: UpdateUserImage,
|
|
2460
3108
|
useFactory: (userRepository, fileUploader) => {
|
|
@@ -2473,6 +3121,8 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
|
|
|
2473
3121
|
provide: 'ProductSearch',
|
|
2474
3122
|
useExisting: ProductsVertexSearch,
|
|
2475
3123
|
},
|
|
3124
|
+
CouponRepositoriesFacade,
|
|
3125
|
+
HomeShopRepositoriesFacade,
|
|
2476
3126
|
], imports: [provideFirebaseApp((injector) => {
|
|
2477
3127
|
const appName = injector.get(FIREBASE_APP_NAME);
|
|
2478
3128
|
try {
|
|
@@ -2559,6 +3209,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2559
3209
|
HomeShopService,
|
|
2560
3210
|
OrderService,
|
|
2561
3211
|
WishlistService,
|
|
3212
|
+
ConfigurationFacade,
|
|
3213
|
+
CartServicesFacade,
|
|
3214
|
+
CheckoutRepositoriesFacade,
|
|
3215
|
+
CheckoutDependenciesFacade,
|
|
3216
|
+
CategoryRepositoryFacade,
|
|
3217
|
+
ProductCatalogFacade,
|
|
3218
|
+
CatalogServiceFacade,
|
|
3219
|
+
CategoryServiceFacade,
|
|
3220
|
+
CatalogStrategiesFacade,
|
|
3221
|
+
CatalogOperationsFacade,
|
|
3222
|
+
ProductManagementFacade,
|
|
3223
|
+
{
|
|
3224
|
+
provide: 'ProductServicesFacade',
|
|
3225
|
+
useFactory: (productStockNotificationRepository, categoryRepository, productSearch) => ({
|
|
3226
|
+
productStockNotificationRepository,
|
|
3227
|
+
categoryRepository,
|
|
3228
|
+
productSearch,
|
|
3229
|
+
}),
|
|
3230
|
+
deps: ['ProductStockNotificationRepository', 'CategoryRepository', 'ProductSearch'],
|
|
3231
|
+
},
|
|
3232
|
+
CatalogFilterHelper,
|
|
3233
|
+
CatalogSortHelper,
|
|
3234
|
+
ProductFieldsHelper,
|
|
3235
|
+
BrandManagerHelper,
|
|
3236
|
+
CatalogRepositoryService,
|
|
3237
|
+
CatalogHelpersService,
|
|
3238
|
+
CategorySearchStrategy,
|
|
3239
|
+
TermSearchStrategy,
|
|
3240
|
+
ProfileSearchStrategy,
|
|
3241
|
+
{
|
|
3242
|
+
provide: CatalogSearchContext,
|
|
3243
|
+
useFactory: (categoryStrategy, termStrategy, profileStrategy) => {
|
|
3244
|
+
return new CatalogSearchContext(categoryStrategy, termStrategy, profileStrategy);
|
|
3245
|
+
},
|
|
3246
|
+
deps: [CategorySearchStrategy, TermSearchStrategy, ProfileSearchStrategy],
|
|
3247
|
+
},
|
|
2562
3248
|
{
|
|
2563
3249
|
provide: UpdateUserImage,
|
|
2564
3250
|
useFactory: (userRepository, fileUploader) => {
|
|
@@ -2577,6 +3263,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2577
3263
|
provide: 'ProductSearch',
|
|
2578
3264
|
useExisting: ProductsVertexSearch,
|
|
2579
3265
|
},
|
|
3266
|
+
CouponRepositoriesFacade,
|
|
3267
|
+
HomeShopRepositoriesFacade,
|
|
2580
3268
|
],
|
|
2581
3269
|
}]
|
|
2582
3270
|
}] });
|