@infrab4a/connect-angular 5.0.0-beta.6 → 5.0.0-beta.61
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 +13 -8
- package/angular-firestore.module.d.ts +1 -2
- package/angular-vertex-search.module.d.ts +9 -0
- package/consts/index.d.ts +2 -0
- package/consts/persistence.const.d.ts +1 -0
- package/consts/vertex-config.const.d.ts +1 -0
- package/esm2022/angular-connect.module.mjs +38 -5
- package/esm2022/angular-elastic-search.module.mjs +1 -1
- package/esm2022/angular-firebase-auth.module.mjs +1 -1
- package/esm2022/angular-firestore.module.mjs +39 -28
- package/esm2022/angular-hasura-graphql.module.mjs +24 -2
- package/esm2022/angular-vertex-search.module.mjs +34 -0
- package/esm2022/consts/category-structure.mjs +1 -1
- package/esm2022/consts/default-shop.const.mjs +1 -1
- package/esm2022/consts/es-config.const.mjs +1 -1
- package/esm2022/consts/firebase-const.mjs +1 -1
- package/esm2022/consts/hasura-options.const.mjs +1 -1
- package/esm2022/consts/index.mjs +3 -1
- package/esm2022/consts/persistence.const.mjs +2 -0
- package/esm2022/consts/storage-base-url.const.mjs +1 -1
- package/esm2022/consts/vertex-config.const.mjs +2 -0
- package/esm2022/helpers/index.mjs +1 -1
- package/esm2022/helpers/mobile-operation-system-checker.helper.mjs +1 -1
- package/esm2022/index.mjs +2 -1
- package/esm2022/persistence/cookie-data-persistence.mjs +22 -0
- package/esm2022/persistence/data-persistence.mjs +2 -0
- package/esm2022/persistence/index.mjs +3 -0
- package/esm2022/services/auth.service.mjs +1 -1
- package/esm2022/services/cart.service.mjs +15 -12
- package/esm2022/services/catalog/adapters/category-structure.adapter.mjs +1 -1
- package/esm2022/services/catalog/adapters/index.mjs +1 -1
- package/esm2022/services/catalog/adapters/new-category-structure.adapter.mjs +6 -4
- package/esm2022/services/catalog/adapters/old-category-structure.adapter.mjs +1 -1
- package/esm2022/services/catalog/catalog.service.mjs +89 -33
- package/esm2022/services/catalog/category.service.mjs +1 -1
- package/esm2022/services/catalog/enums/index.mjs +1 -1
- package/esm2022/services/catalog/enums/product-sorts.enum.mjs +1 -1
- package/esm2022/services/catalog/index.mjs +1 -1
- package/esm2022/services/catalog/models/category-with-tree.model.mjs +1 -1
- package/esm2022/services/catalog/models/index.mjs +1 -1
- package/esm2022/services/catalog/types/index.mjs +1 -1
- package/esm2022/services/catalog/types/product-sort.type.mjs +1 -1
- package/esm2022/services/catalog/wishlist.service.mjs +140 -18
- package/esm2022/services/checkout-subscription.service.mjs +18 -21
- package/esm2022/services/checkout.service.mjs +13 -16
- package/esm2022/services/coupon.service.mjs +60 -21
- package/esm2022/services/helpers/index.mjs +1 -1
- package/esm2022/services/helpers/util.helper.mjs +1 -1
- package/esm2022/services/home-shop.service.mjs +4 -4
- package/esm2022/services/index.mjs +1 -1
- package/esm2022/services/order.service.mjs +1 -1
- package/esm2022/services/shipping.service.mjs +1 -1
- package/esm2022/services/types/index.mjs +1 -1
- package/esm2022/services/types/required-checkout-data.type.mjs +1 -1
- package/esm2022/services/types/required-checkout-subscription-data.type.mjs +1 -1
- package/esm2022/services/types/shipping-methods.type.mjs +1 -1
- package/esm2022/types/firebase-app-config.type.mjs +1 -1
- package/esm2022/types/index.mjs +1 -1
- package/fesm2022/infrab4a-connect-angular.mjs +479 -145
- package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/package.json +5 -5
- package/persistence/cookie-data-persistence.d.ts +10 -0
- package/persistence/data-persistence.d.ts +6 -0
- package/persistence/index.d.ts +2 -0
- package/services/catalog/catalog.service.d.ts +7 -4
- package/services/catalog/wishlist.service.d.ts +16 -4
- package/services/checkout-subscription.service.d.ts +5 -4
- package/services/checkout.service.d.ts +8 -4
- package/services/coupon.service.d.ts +6 -2
|
@@ -2,18 +2,18 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angular/core';
|
|
3
3
|
import * as i1$4 from '@angular/fire/app';
|
|
4
4
|
import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
|
|
5
|
+
import * as i2 from '@angular/fire/storage';
|
|
6
|
+
import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
|
|
5
7
|
import * as i1$2 from '@infrab4a/connect';
|
|
6
|
-
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, 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,
|
|
8
|
+
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, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, PersonTypes, WishlistLogType, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
|
|
7
9
|
import * as i1 from '@angular/fire/auth';
|
|
8
10
|
import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
9
11
|
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
|
|
10
12
|
import * as i1$1 from '@angular/fire/firestore';
|
|
11
|
-
import { Firestore, provideFirestore,
|
|
12
|
-
import * as i2 from '@angular/fire/storage';
|
|
13
|
-
import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
|
|
14
|
-
import { combineLatest, from, of, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
15
|
-
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
13
|
+
import { Firestore, provideFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
|
|
16
14
|
import cookie from 'js-cookie';
|
|
15
|
+
import { of, from, combineLatest, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
16
|
+
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
17
17
|
import { __decorate, __metadata } from 'tslib';
|
|
18
18
|
import { Type } from 'class-transformer';
|
|
19
19
|
import * as i1$3 from '@angular/common/http';
|
|
@@ -61,6 +61,10 @@ const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
|
|
|
61
61
|
|
|
62
62
|
const HASURA_OPTIONS = 'HASURA_OPTIONS';
|
|
63
63
|
|
|
64
|
+
const PERSISTENCE_PROVIDER = 'PERSISTENCE_PROVIDER';
|
|
65
|
+
|
|
66
|
+
const VERTEX_CONFIG = 'VERTEX_CONFIG';
|
|
67
|
+
|
|
64
68
|
class AngularFirebaseAuthModule {
|
|
65
69
|
static initializeApp(options, nameOrConfig) {
|
|
66
70
|
return {
|
|
@@ -169,8 +173,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
169
173
|
}]
|
|
170
174
|
}] });
|
|
171
175
|
|
|
172
|
-
const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
|
|
173
|
-
|
|
174
176
|
class MobileOperationSystemCheckerHelper {
|
|
175
177
|
static isAppleDevice() {
|
|
176
178
|
return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator?.platform) ||
|
|
@@ -190,12 +192,12 @@ class AngularFirestoreModule {
|
|
|
190
192
|
};
|
|
191
193
|
}
|
|
192
194
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
193
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule
|
|
195
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule] }); }
|
|
194
196
|
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, providers: [
|
|
195
197
|
{
|
|
196
198
|
provide: 'FirestoreOptions',
|
|
197
199
|
useFactory: (firestore, platformId) => ({
|
|
198
|
-
firestore,
|
|
200
|
+
firestore: new ConnectFirestoreService(firestore),
|
|
199
201
|
interceptors: {
|
|
200
202
|
request: (request) => {
|
|
201
203
|
if (isPlatformBrowser(platformId))
|
|
@@ -404,26 +406,33 @@ class AngularFirestoreModule {
|
|
|
404
406
|
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
405
407
|
},
|
|
406
408
|
{
|
|
407
|
-
provide: '
|
|
408
|
-
useFactory: (
|
|
409
|
-
return new
|
|
409
|
+
provide: 'OrderBlockedRepository',
|
|
410
|
+
useFactory: (options) => {
|
|
411
|
+
return new OrderBlockedFirestoreRepository(options);
|
|
410
412
|
},
|
|
411
|
-
deps: [
|
|
413
|
+
deps: ['FirestoreOptions'],
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
provide: 'LogRepository',
|
|
417
|
+
useFactory: (options) => {
|
|
418
|
+
return new LogFirestoreRepository(options);
|
|
419
|
+
},
|
|
420
|
+
deps: ['FirestoreOptions'],
|
|
412
421
|
},
|
|
413
422
|
], imports: [AngularElasticSeachModule,
|
|
414
423
|
provideFirestore((injector) => {
|
|
415
424
|
const platformId = injector.get(PLATFORM_ID);
|
|
416
|
-
if (isPlatformServer(platformId))
|
|
417
|
-
return
|
|
418
|
-
|
|
419
|
-
|
|
425
|
+
if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
|
|
426
|
+
return initializeFirestore(injector.get(FirebaseApp), {
|
|
427
|
+
ignoreUndefinedProperties: true,
|
|
428
|
+
});
|
|
420
429
|
const firestore = initializeFirestore(injector.get(FirebaseApp), {
|
|
421
430
|
experimentalForceLongPolling: true,
|
|
431
|
+
ignoreUndefinedProperties: true,
|
|
422
432
|
localCache: memoryLocalCache(),
|
|
423
433
|
});
|
|
424
434
|
return firestore;
|
|
425
|
-
})
|
|
426
|
-
provideStorage(() => getStorage())] }); }
|
|
435
|
+
})] }); }
|
|
427
436
|
}
|
|
428
437
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, decorators: [{
|
|
429
438
|
type: NgModule,
|
|
@@ -432,23 +441,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
432
441
|
AngularElasticSeachModule,
|
|
433
442
|
provideFirestore((injector) => {
|
|
434
443
|
const platformId = injector.get(PLATFORM_ID);
|
|
435
|
-
if (isPlatformServer(platformId))
|
|
436
|
-
return
|
|
437
|
-
|
|
438
|
-
|
|
444
|
+
if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
|
|
445
|
+
return initializeFirestore(injector.get(FirebaseApp), {
|
|
446
|
+
ignoreUndefinedProperties: true,
|
|
447
|
+
});
|
|
439
448
|
const firestore = initializeFirestore(injector.get(FirebaseApp), {
|
|
440
449
|
experimentalForceLongPolling: true,
|
|
450
|
+
ignoreUndefinedProperties: true,
|
|
441
451
|
localCache: memoryLocalCache(),
|
|
442
452
|
});
|
|
443
453
|
return firestore;
|
|
444
454
|
}),
|
|
445
|
-
provideStorage(() => getStorage()),
|
|
446
455
|
],
|
|
447
456
|
providers: [
|
|
448
457
|
{
|
|
449
458
|
provide: 'FirestoreOptions',
|
|
450
459
|
useFactory: (firestore, platformId) => ({
|
|
451
|
-
firestore,
|
|
460
|
+
firestore: new ConnectFirestoreService(firestore),
|
|
452
461
|
interceptors: {
|
|
453
462
|
request: (request) => {
|
|
454
463
|
if (isPlatformBrowser(platformId))
|
|
@@ -657,11 +666,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
657
666
|
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
658
667
|
},
|
|
659
668
|
{
|
|
660
|
-
provide: '
|
|
661
|
-
useFactory: (
|
|
662
|
-
return new
|
|
669
|
+
provide: 'OrderBlockedRepository',
|
|
670
|
+
useFactory: (options) => {
|
|
671
|
+
return new OrderBlockedFirestoreRepository(options);
|
|
663
672
|
},
|
|
664
|
-
deps: [
|
|
673
|
+
deps: ['FirestoreOptions'],
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
provide: 'LogRepository',
|
|
677
|
+
useFactory: (options) => {
|
|
678
|
+
return new LogFirestoreRepository(options);
|
|
679
|
+
},
|
|
680
|
+
deps: ['FirestoreOptions'],
|
|
665
681
|
},
|
|
666
682
|
],
|
|
667
683
|
}]
|
|
@@ -744,6 +760,17 @@ class AngularHasuraGraphQLModule {
|
|
|
744
760
|
},
|
|
745
761
|
deps: ['HasuraConfig'],
|
|
746
762
|
},
|
|
763
|
+
{
|
|
764
|
+
provide: 'ProductStockNotificationRepository',
|
|
765
|
+
useExisting: ProductStockNotificationHasuraGraphQLRepository,
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
provide: ProductStockNotificationHasuraGraphQLRepository,
|
|
769
|
+
useFactory: (hasuraConfig) => {
|
|
770
|
+
return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
|
|
771
|
+
},
|
|
772
|
+
deps: ['HasuraConfig'],
|
|
773
|
+
},
|
|
747
774
|
{
|
|
748
775
|
provide: 'CategoryFilterRepository',
|
|
749
776
|
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
@@ -870,6 +897,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
870
897
|
},
|
|
871
898
|
deps: ['HasuraConfig'],
|
|
872
899
|
},
|
|
900
|
+
{
|
|
901
|
+
provide: 'ProductStockNotificationRepository',
|
|
902
|
+
useExisting: ProductStockNotificationHasuraGraphQLRepository,
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
provide: ProductStockNotificationHasuraGraphQLRepository,
|
|
906
|
+
useFactory: (hasuraConfig) => {
|
|
907
|
+
return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
|
|
908
|
+
},
|
|
909
|
+
deps: ['HasuraConfig'],
|
|
910
|
+
},
|
|
873
911
|
{
|
|
874
912
|
provide: 'CategoryFilterRepository',
|
|
875
913
|
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
@@ -927,6 +965,55 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
927
965
|
}]
|
|
928
966
|
}] });
|
|
929
967
|
|
|
968
|
+
class AngularVertexSeachModule {
|
|
969
|
+
static initializeApp(options) {
|
|
970
|
+
return {
|
|
971
|
+
ngModule: AngularVertexSeachModule,
|
|
972
|
+
providers: [{ provide: VERTEX_CONFIG, useValue: options }],
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
976
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule }); }
|
|
977
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, providers: [
|
|
978
|
+
{
|
|
979
|
+
provide: ProductsVertexSearch,
|
|
980
|
+
useFactory: (configuration) => new ProductsVertexSearch(new VertexAxiosAdapter(configuration)),
|
|
981
|
+
deps: [VERTEX_CONFIG],
|
|
982
|
+
},
|
|
983
|
+
] }); }
|
|
984
|
+
}
|
|
985
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, decorators: [{
|
|
986
|
+
type: NgModule,
|
|
987
|
+
args: [{
|
|
988
|
+
providers: [
|
|
989
|
+
{
|
|
990
|
+
provide: ProductsVertexSearch,
|
|
991
|
+
useFactory: (configuration) => new ProductsVertexSearch(new VertexAxiosAdapter(configuration)),
|
|
992
|
+
deps: [VERTEX_CONFIG],
|
|
993
|
+
},
|
|
994
|
+
],
|
|
995
|
+
}]
|
|
996
|
+
}] });
|
|
997
|
+
|
|
998
|
+
const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
|
|
999
|
+
|
|
1000
|
+
class CookieDataPersistence {
|
|
1001
|
+
get(key) {
|
|
1002
|
+
return of(cookie.get(key));
|
|
1003
|
+
}
|
|
1004
|
+
remove(key) {
|
|
1005
|
+
return of(cookie.remove(key));
|
|
1006
|
+
}
|
|
1007
|
+
set(key, value) {
|
|
1008
|
+
return from(cookie.set(key, value)).pipe(map(() => { }));
|
|
1009
|
+
}
|
|
1010
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1011
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence }); }
|
|
1012
|
+
}
|
|
1013
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, decorators: [{
|
|
1014
|
+
type: Injectable
|
|
1015
|
+
}] });
|
|
1016
|
+
|
|
930
1017
|
class AuthService {
|
|
931
1018
|
constructor(angularFireAuth, userRepository) {
|
|
932
1019
|
this.angularFireAuth = angularFireAuth;
|
|
@@ -1007,11 +1094,11 @@ class CouponService {
|
|
|
1007
1094
|
throw 'Limite de uso atingido';
|
|
1008
1095
|
}
|
|
1009
1096
|
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
1010
|
-
const
|
|
1011
|
-
if (!couponUseLimits.unlimited && couponUseLimits.total &&
|
|
1097
|
+
const ordersCoupon = await this.getOrdersWithCoupon(coupon);
|
|
1098
|
+
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total)
|
|
1012
1099
|
throw 'Limite de uso atingido.';
|
|
1013
1100
|
if (couponUseLimits.limitedPerUser) {
|
|
1014
|
-
const ordersWithUser = this.countOrdersWithUser(
|
|
1101
|
+
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, checkout.user.email);
|
|
1015
1102
|
if (ordersWithUser > 0)
|
|
1016
1103
|
throw 'Limite de uso por usuário atingido.';
|
|
1017
1104
|
}
|
|
@@ -1020,8 +1107,12 @@ class CouponService {
|
|
|
1020
1107
|
if (!hasProductCategories)
|
|
1021
1108
|
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
1022
1109
|
const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
|
|
1023
|
-
if (!hasMinSubTotal)
|
|
1024
|
-
|
|
1110
|
+
if (!hasMinSubTotal) {
|
|
1111
|
+
if (coupon.productsCategories?.length) {
|
|
1112
|
+
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.`;
|
|
1113
|
+
}
|
|
1114
|
+
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido.`;
|
|
1115
|
+
}
|
|
1025
1116
|
return coupon;
|
|
1026
1117
|
}
|
|
1027
1118
|
calcDiscountSubscription(coupon, checkout) {
|
|
@@ -1033,38 +1124,44 @@ class CouponService {
|
|
|
1033
1124
|
return of(discount);
|
|
1034
1125
|
}
|
|
1035
1126
|
async calcDiscountShopping(coupon, checkout) {
|
|
1036
|
-
let
|
|
1127
|
+
let discountInfo = null;
|
|
1037
1128
|
if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
|
|
1038
|
-
|
|
1129
|
+
discountInfo = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
|
|
1039
1130
|
}
|
|
1040
1131
|
else {
|
|
1041
|
-
|
|
1132
|
+
discountInfo = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
|
|
1042
1133
|
}
|
|
1043
|
-
return discount;
|
|
1134
|
+
return { discount: discountInfo.discount, lineItems: discountInfo.lineItems };
|
|
1044
1135
|
}
|
|
1045
1136
|
async calcDiscountByType(type, value, categories, checkout) {
|
|
1046
1137
|
let discount = 0;
|
|
1047
|
-
|
|
1048
|
-
|
|
1138
|
+
if (type == CouponTypes.SHIPPING) {
|
|
1139
|
+
const subTotal = checkout.shipping.ShippingPrice;
|
|
1140
|
+
const discount = subTotal * ((value > 100 ? 100 : value) / 100);
|
|
1141
|
+
return { discount, lineItems: checkout.lineItems };
|
|
1142
|
+
}
|
|
1143
|
+
let lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
|
|
1144
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
|
|
1049
1145
|
if (type == CouponTypes.ABSOLUTE) {
|
|
1050
1146
|
discount = value > subTotal ? subTotal : value;
|
|
1051
1147
|
}
|
|
1052
1148
|
else {
|
|
1053
|
-
discount = subTotal * (value / 100);
|
|
1149
|
+
discount = subTotal * ((value > 100 ? 100 : value) / 100);
|
|
1054
1150
|
}
|
|
1055
|
-
|
|
1151
|
+
const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
|
|
1152
|
+
return { discount, lineItems };
|
|
1056
1153
|
}
|
|
1057
1154
|
async hasMinSubTotal(coupon, checkout) {
|
|
1058
1155
|
if (!coupon.minSubTotalValue)
|
|
1059
1156
|
return true;
|
|
1060
1157
|
let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
1061
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user
|
|
1158
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
1062
1159
|
if (coupon.minSubTotalValue <= subTotal)
|
|
1063
1160
|
return true;
|
|
1064
1161
|
return false;
|
|
1065
1162
|
}
|
|
1066
1163
|
async hasProductCategories(coupon, checkout) {
|
|
1067
|
-
if (!coupon.productsCategories || !coupon.productsCategories
|
|
1164
|
+
if (!coupon.productsCategories || !coupon.productsCategories?.length) {
|
|
1068
1165
|
return true;
|
|
1069
1166
|
}
|
|
1070
1167
|
const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
|
|
@@ -1126,7 +1223,7 @@ class CouponService {
|
|
|
1126
1223
|
}
|
|
1127
1224
|
return lineItensDiscount;
|
|
1128
1225
|
}
|
|
1129
|
-
calcCheckoutSubtotal(lineItens, user
|
|
1226
|
+
calcCheckoutSubtotal(lineItens, user) {
|
|
1130
1227
|
return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
|
|
1131
1228
|
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
1132
1229
|
: acc + curr.pricePaid * curr.quantity, 0) || 0);
|
|
@@ -1136,7 +1233,7 @@ class CouponService {
|
|
|
1136
1233
|
.find({
|
|
1137
1234
|
filters: {
|
|
1138
1235
|
coupon: { id: coupon.id },
|
|
1139
|
-
|
|
1236
|
+
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
1140
1237
|
},
|
|
1141
1238
|
})
|
|
1142
1239
|
.then((result) => result.data);
|
|
@@ -1146,7 +1243,7 @@ class CouponService {
|
|
|
1146
1243
|
.find({
|
|
1147
1244
|
filters: {
|
|
1148
1245
|
user: { email: { operator: Where.EQUALS, value: email } },
|
|
1149
|
-
|
|
1246
|
+
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
1150
1247
|
},
|
|
1151
1248
|
})
|
|
1152
1249
|
.then((result) => result.data);
|
|
@@ -1157,13 +1254,42 @@ class CouponService {
|
|
|
1157
1254
|
getCouponUseLimits(coupon, checkoutType, user) {
|
|
1158
1255
|
let couponUseLimits;
|
|
1159
1256
|
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
1160
|
-
|
|
1257
|
+
if (coupon.exclusivityType.length === 1 &&
|
|
1258
|
+
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
1259
|
+
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
1260
|
+
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
1261
|
+
else
|
|
1262
|
+
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
1161
1263
|
}
|
|
1162
1264
|
else {
|
|
1163
1265
|
couponUseLimits = coupon.useLimits.subscription;
|
|
1164
1266
|
}
|
|
1165
1267
|
return couponUseLimits;
|
|
1166
1268
|
}
|
|
1269
|
+
calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
|
|
1270
|
+
let lineItemsDiscount = [];
|
|
1271
|
+
if (type === CouponTypes.ABSOLUTE) {
|
|
1272
|
+
const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
|
|
1273
|
+
lineItemsDiscount = lineItems.map((item) => {
|
|
1274
|
+
const totalItemPercentage = item.pricePaid / subTotal;
|
|
1275
|
+
const discountItem = couponDiscountMax * totalItemPercentage;
|
|
1276
|
+
return {
|
|
1277
|
+
...item,
|
|
1278
|
+
discount: Number(discountItem.toFixed(2)),
|
|
1279
|
+
};
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
else {
|
|
1283
|
+
lineItemsDiscount = lineItems.map((item) => {
|
|
1284
|
+
const discountItem = item.pricePaid * (couponDiscount / 100);
|
|
1285
|
+
return {
|
|
1286
|
+
...item,
|
|
1287
|
+
discount: Number(discountItem.toFixed(2)),
|
|
1288
|
+
};
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
return lineItemsDiscount;
|
|
1292
|
+
}
|
|
1167
1293
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1168
1294
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, providedIn: 'root' }); }
|
|
1169
1295
|
}
|
|
@@ -1187,18 +1313,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1187
1313
|
}] }] });
|
|
1188
1314
|
|
|
1189
1315
|
class CheckoutService {
|
|
1190
|
-
constructor(couponService, checkoutRepository,
|
|
1316
|
+
constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence) {
|
|
1191
1317
|
this.couponService = couponService;
|
|
1192
1318
|
this.checkoutRepository = checkoutRepository;
|
|
1193
|
-
this.orderRepository = orderRepository;
|
|
1194
1319
|
this.userRepository = userRepository;
|
|
1195
1320
|
this.defaultShop = defaultShop;
|
|
1321
|
+
this.dataPersistence = dataPersistence;
|
|
1196
1322
|
}
|
|
1197
1323
|
getCheckout(checkoutData) {
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
return from(this.createCheckout(checkoutData));
|
|
1324
|
+
return this.dataPersistence
|
|
1325
|
+
.get('checkoutId')
|
|
1326
|
+
.pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
|
|
1202
1327
|
}
|
|
1203
1328
|
getUserByCheckout(checkoutId) {
|
|
1204
1329
|
return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => checkout?.user?.id ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id }))), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
|
|
@@ -1210,8 +1335,7 @@ class CheckoutService {
|
|
|
1210
1335
|
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
|
|
1211
1336
|
}
|
|
1212
1337
|
clearCheckoutFromSession() {
|
|
1213
|
-
|
|
1214
|
-
return of();
|
|
1338
|
+
return this.dataPersistence.remove('checkoutId');
|
|
1215
1339
|
}
|
|
1216
1340
|
calcDiscount(coupon) {
|
|
1217
1341
|
return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
|
|
@@ -1225,10 +1349,10 @@ class CheckoutService {
|
|
|
1225
1349
|
...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
1226
1350
|
shop: checkoutData?.shop || this.defaultShop,
|
|
1227
1351
|
});
|
|
1228
|
-
|
|
1352
|
+
await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
|
|
1229
1353
|
return checkout;
|
|
1230
1354
|
}
|
|
1231
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: '
|
|
1355
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }, { token: PERSISTENCE_PROVIDER }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1232
1356
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService }); }
|
|
1233
1357
|
}
|
|
1234
1358
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, decorators: [{
|
|
@@ -1236,15 +1360,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1236
1360
|
}], ctorParameters: () => [{ type: CouponService }, { type: undefined, decorators: [{
|
|
1237
1361
|
type: Inject,
|
|
1238
1362
|
args: ['CheckoutRepository']
|
|
1239
|
-
}] }, { type: undefined, decorators: [{
|
|
1240
|
-
type: Inject,
|
|
1241
|
-
args: ['OrderRepository']
|
|
1242
1363
|
}] }, { type: undefined, decorators: [{
|
|
1243
1364
|
type: Inject,
|
|
1244
1365
|
args: ['UserRepository']
|
|
1245
1366
|
}] }, { type: i1$2.Shops, decorators: [{
|
|
1246
1367
|
type: Inject,
|
|
1247
1368
|
args: [DEFAULT_SHOP]
|
|
1369
|
+
}] }, { type: undefined, decorators: [{
|
|
1370
|
+
type: Inject,
|
|
1371
|
+
args: [PERSISTENCE_PROVIDER]
|
|
1248
1372
|
}] }] });
|
|
1249
1373
|
|
|
1250
1374
|
class CartService {
|
|
@@ -1263,6 +1387,7 @@ class CartService {
|
|
|
1263
1387
|
if (index > -1) {
|
|
1264
1388
|
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
1265
1389
|
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
1390
|
+
checkoutLoaded.lineItems[index].price = lineItem.price;
|
|
1266
1391
|
}
|
|
1267
1392
|
else
|
|
1268
1393
|
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
@@ -1280,17 +1405,18 @@ class CartService {
|
|
|
1280
1405
|
this.buildLineItem = async ({ checkout, item, quantity, }) => {
|
|
1281
1406
|
const product = await this.getProductData(item.id);
|
|
1282
1407
|
item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
|
|
1283
|
-
if (this.checkMaxStock(item, quantity || 0))
|
|
1284
|
-
throw new Error('Desculpe! Temos apenas ' +
|
|
1408
|
+
if (this.checkMaxStock(product.stock.quantity, item.quantity || 0, quantity || 0))
|
|
1409
|
+
throw new Error('Desculpe! Temos apenas ' + product.stock?.quantity + ' em estoque.');
|
|
1285
1410
|
const image = item.image || item.images?.shift();
|
|
1286
|
-
const { id, name, EAN, slug,
|
|
1411
|
+
const { id, name, EAN, slug, weight, sku, type } = item;
|
|
1287
1412
|
const isGift = item.isGift || null;
|
|
1288
1413
|
const pricePaid = this.getProductPrice({
|
|
1289
|
-
product:
|
|
1414
|
+
product: LineItem.toInstance(product),
|
|
1290
1415
|
shop: checkout.shop || this.defaultShop,
|
|
1291
1416
|
isSubscriber: checkout.user?.isSubscriber,
|
|
1292
1417
|
});
|
|
1293
1418
|
RoundProductPricesHelper.roundProductPrices(item);
|
|
1419
|
+
RoundProductPricesHelper.roundProductPrices(product);
|
|
1294
1420
|
return {
|
|
1295
1421
|
checkout,
|
|
1296
1422
|
lineItem: LineItem.toInstance({
|
|
@@ -1300,13 +1426,14 @@ class CartService {
|
|
|
1300
1426
|
brand: product.brand,
|
|
1301
1427
|
slug: slug ?? product.slug,
|
|
1302
1428
|
sku: sku ?? product.sku,
|
|
1303
|
-
stock,
|
|
1304
|
-
price: this.roundPrice(price),
|
|
1429
|
+
stock: product.stock,
|
|
1430
|
+
price: this.roundPrice(product.price),
|
|
1305
1431
|
image,
|
|
1306
1432
|
weight: weight ?? product.weight,
|
|
1307
1433
|
quantity: (item.quantity || 0) + (quantity || 0),
|
|
1308
1434
|
pricePaid,
|
|
1309
|
-
|
|
1435
|
+
discount: 0,
|
|
1436
|
+
categories: product.categories || product.category?.id ? [product.category?.id, ...product.categories] : [],
|
|
1310
1437
|
isGift: isGift ?? null,
|
|
1311
1438
|
costPrice: product.costPrice ?? 0,
|
|
1312
1439
|
type,
|
|
@@ -1321,10 +1448,10 @@ class CartService {
|
|
|
1321
1448
|
? Number(info.subscriberPrice.toFixed(2))
|
|
1322
1449
|
: Number(info.price.toFixed(2));
|
|
1323
1450
|
};
|
|
1324
|
-
this.checkMaxStock = (
|
|
1325
|
-
const maxStock =
|
|
1326
|
-
const currentItemAmount =
|
|
1327
|
-
return currentItemAmount +
|
|
1451
|
+
this.checkMaxStock = (currentStock, currentItemQtd, quantityToAdd) => {
|
|
1452
|
+
const maxStock = currentStock || 0;
|
|
1453
|
+
const currentItemAmount = currentItemQtd || 0;
|
|
1454
|
+
return currentItemAmount + quantityToAdd > maxStock;
|
|
1328
1455
|
};
|
|
1329
1456
|
}
|
|
1330
1457
|
addItem(item, quantity = 1) {
|
|
@@ -1541,9 +1668,11 @@ class NewCategoryStructureAdapter {
|
|
|
1541
1668
|
.then((categories) => categories.map((category) => category.id.toString()));
|
|
1542
1669
|
}
|
|
1543
1670
|
async getCategory(category) {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1671
|
+
const collectionCategory = category.isCollection ||
|
|
1672
|
+
(isNil(category.isCollection) && !category.products?.length) ||
|
|
1673
|
+
category.isWishlist ||
|
|
1674
|
+
category.brandCategory;
|
|
1675
|
+
return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
|
|
1547
1676
|
}
|
|
1548
1677
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1549
1678
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter }); }
|
|
@@ -1576,12 +1705,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1576
1705
|
}] }] });
|
|
1577
1706
|
|
|
1578
1707
|
class CatalogService {
|
|
1579
|
-
constructor(productRepository, categoryRepository, categoryStructureAdapter, shop,
|
|
1708
|
+
constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch) {
|
|
1580
1709
|
this.productRepository = productRepository;
|
|
1710
|
+
this.productStockNotificationRepository = productStockNotificationRepository;
|
|
1581
1711
|
this.categoryRepository = categoryRepository;
|
|
1582
1712
|
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
1583
1713
|
this.shop = shop;
|
|
1584
|
-
this.
|
|
1714
|
+
this.productSearch = productSearch;
|
|
1585
1715
|
this.productsByTerm = {};
|
|
1586
1716
|
this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
|
|
1587
1717
|
const filters = {};
|
|
@@ -1608,17 +1738,22 @@ class CatalogService {
|
|
|
1608
1738
|
if (!sort || sort === 'most-relevant')
|
|
1609
1739
|
return {};
|
|
1610
1740
|
if (sort === 'best-sellers')
|
|
1611
|
-
return {
|
|
1741
|
+
return {
|
|
1742
|
+
shoppingCount: 'desc',
|
|
1743
|
+
rate: 'desc',
|
|
1744
|
+
stock: 'desc',
|
|
1745
|
+
name: 'asc',
|
|
1746
|
+
};
|
|
1612
1747
|
if (sort === 'biggest-price')
|
|
1613
|
-
return { subscriberPrice: 'desc' };
|
|
1748
|
+
return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
|
|
1614
1749
|
if (sort === 'lowest-price')
|
|
1615
|
-
return { subscriberPrice: 'asc' };
|
|
1750
|
+
return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
|
|
1616
1751
|
if (sort === 'best-rating')
|
|
1617
|
-
return { rate: 'desc' };
|
|
1752
|
+
return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
|
|
1618
1753
|
if (sort === 'news')
|
|
1619
1754
|
return { createdAt: 'desc' };
|
|
1620
1755
|
if (sort === 'biggest-discount')
|
|
1621
|
-
return { subscriberDiscountPercentage: 'desc' };
|
|
1756
|
+
return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
|
|
1622
1757
|
};
|
|
1623
1758
|
this.buildLimitQuery = (options) => {
|
|
1624
1759
|
const limit = options?.perPage || 20;
|
|
@@ -1652,16 +1787,26 @@ class CatalogService {
|
|
|
1652
1787
|
brands: distinct?.brand,
|
|
1653
1788
|
}));
|
|
1654
1789
|
}
|
|
1790
|
+
async addCustomerToStockNotification(shop, productId, name, email) {
|
|
1791
|
+
return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
|
|
1792
|
+
}
|
|
1655
1793
|
async findCatalog(options, limits) {
|
|
1656
1794
|
if (this.hasTerm(options) && options.sort === 'most-relevant') {
|
|
1657
|
-
const productsIds = await this.
|
|
1658
|
-
return this.
|
|
1795
|
+
const productsIds = await this.findCatalogIdsBySearch(options.term);
|
|
1796
|
+
return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
|
|
1659
1797
|
}
|
|
1660
1798
|
if (this.hasCategory(options) && options.sort === 'most-relevant') {
|
|
1661
|
-
const
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1799
|
+
const mostRelevant = options.category.isWishlist ? [] : options.category.getMostRelevantByShop(this.shop);
|
|
1800
|
+
const productsIds = await this.productRepository
|
|
1801
|
+
.findCatalog({
|
|
1802
|
+
fields: ['id'],
|
|
1803
|
+
filters: {
|
|
1804
|
+
...(await this.buildMainFilter(options)),
|
|
1805
|
+
...this.buildFilterQuery(options?.filters || {}),
|
|
1806
|
+
},
|
|
1807
|
+
})
|
|
1808
|
+
.then((products) => products.data.map((product) => product.id));
|
|
1809
|
+
return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
|
|
1665
1810
|
}
|
|
1666
1811
|
const repoParams = {
|
|
1667
1812
|
filters: {
|
|
@@ -1686,15 +1831,47 @@ class CatalogService {
|
|
|
1686
1831
|
if (profile)
|
|
1687
1832
|
return { tags: { operator: Where.LIKE, value: profile } };
|
|
1688
1833
|
if (term)
|
|
1689
|
-
return this.
|
|
1690
|
-
.search(term, 999, this.shop)
|
|
1691
|
-
.then((data) => ({ id: { operator: Where.IN, value: data.
|
|
1834
|
+
return this.productSearch
|
|
1835
|
+
.search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
|
|
1836
|
+
.then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
|
|
1837
|
+
}
|
|
1838
|
+
async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
|
|
1839
|
+
const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
|
|
1840
|
+
const totalResult = await this.productRepository.findCatalog({
|
|
1841
|
+
filters: {
|
|
1842
|
+
id: { operator: Where.IN, value: mostRelevantProductsIds },
|
|
1843
|
+
...this.buildFilterQuery(options?.filters || {}),
|
|
1844
|
+
},
|
|
1845
|
+
orderBy: this.buildSortQuery('best-sellers'),
|
|
1846
|
+
options: {
|
|
1847
|
+
minimal: ['price'],
|
|
1848
|
+
maximum: ['price'],
|
|
1849
|
+
distinct: ['brand'],
|
|
1850
|
+
},
|
|
1851
|
+
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1852
|
+
const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
|
|
1853
|
+
const firstProducts = totalResult.data
|
|
1854
|
+
.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
1855
|
+
.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
|
|
1856
|
+
const lastProducts = totalResult.data
|
|
1857
|
+
.filter((product) => !mostRelevants.includes(product.id))
|
|
1858
|
+
.concat(mostRelevantWithouyStock);
|
|
1859
|
+
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
1860
|
+
const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
|
|
1861
|
+
return {
|
|
1862
|
+
data: resultFinal,
|
|
1863
|
+
count: totalResult.count,
|
|
1864
|
+
maximum: totalResult.maximum,
|
|
1865
|
+
minimal: totalResult.minimal,
|
|
1866
|
+
distinct: totalResult.distinct,
|
|
1867
|
+
};
|
|
1692
1868
|
}
|
|
1693
|
-
async
|
|
1869
|
+
async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
|
|
1694
1870
|
const totalResult = await this.productRepository.findCatalog({
|
|
1695
|
-
fields: ['id', 'stock'],
|
|
1871
|
+
fields: ['id', 'stock', 'gender'],
|
|
1696
1872
|
filters: {
|
|
1697
1873
|
id: { operator: Where.IN, value: productIds },
|
|
1874
|
+
published: { operator: Where.EQUALS, value: true },
|
|
1698
1875
|
...this.buildFilterQuery(options?.filters || {}),
|
|
1699
1876
|
},
|
|
1700
1877
|
options: {
|
|
@@ -1703,10 +1880,17 @@ class CatalogService {
|
|
|
1703
1880
|
distinct: ['brand'],
|
|
1704
1881
|
},
|
|
1705
1882
|
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1883
|
+
const defaultGender = options?.filters?.gender
|
|
1884
|
+
? options?.filters?.gender.at(0)
|
|
1885
|
+
: this.shop === Shops.GLAMSHOP
|
|
1886
|
+
? 'female'
|
|
1887
|
+
: 'male';
|
|
1706
1888
|
const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
|
|
1707
1889
|
const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
|
|
1708
|
-
const
|
|
1709
|
-
const
|
|
1890
|
+
const productIdsStockGender = productIds.filter((product) => stockData.some((result) => result.id === product && (result.gender?.includes(defaultGender) || result.gender?.includes('unisex'))));
|
|
1891
|
+
const productIdsStockNotGender = productIds.filter((product) => stockData.some((result) => result.id === product && !result.gender?.includes(defaultGender) && !result.gender?.includes('unisex')));
|
|
1892
|
+
const productIdsStock = productIdsStockGender.concat(productIdsStockNotGender);
|
|
1893
|
+
const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id === product));
|
|
1710
1894
|
const limitedProductId = productIdsStock
|
|
1711
1895
|
.concat(productIdsStockOut)
|
|
1712
1896
|
.slice(limits.offset, limits.offset + limits.limit);
|
|
@@ -1724,19 +1908,14 @@ class CatalogService {
|
|
|
1724
1908
|
distinct: totalResult.distinct,
|
|
1725
1909
|
};
|
|
1726
1910
|
}
|
|
1727
|
-
async
|
|
1911
|
+
async findCatalogIdsBySearch(term, preview = false) {
|
|
1728
1912
|
if (this.productsByTerm[term])
|
|
1729
1913
|
return this.productsByTerm[term];
|
|
1730
|
-
return (this.productsByTerm[term] = await this.
|
|
1731
|
-
.search(term, 999, this.shop)
|
|
1732
|
-
.then((
|
|
1733
|
-
const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
|
|
1734
|
-
const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
|
|
1735
|
-
const sorted = [...withStock, ...withOutStock];
|
|
1736
|
-
return [...new Set(sorted.map(({ _source }) => _source.id))];
|
|
1737
|
-
}));
|
|
1914
|
+
return (this.productsByTerm[term] = await this.productSearch
|
|
1915
|
+
.search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
|
|
1916
|
+
.then((products) => [...new Set(products.map((product) => product.id))]));
|
|
1738
1917
|
}
|
|
1739
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token:
|
|
1918
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1740
1919
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService }); }
|
|
1741
1920
|
}
|
|
1742
1921
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, decorators: [{
|
|
@@ -1744,6 +1923,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1744
1923
|
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
1745
1924
|
type: Inject,
|
|
1746
1925
|
args: ['ProductRepository']
|
|
1926
|
+
}] }, { type: undefined, decorators: [{
|
|
1927
|
+
type: Inject,
|
|
1928
|
+
args: ['ProductStockNotificationRepository']
|
|
1747
1929
|
}] }, { type: undefined, decorators: [{
|
|
1748
1930
|
type: Inject,
|
|
1749
1931
|
args: ['CategoryRepository']
|
|
@@ -1753,7 +1935,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1753
1935
|
}] }, { type: i1$2.Shops, decorators: [{
|
|
1754
1936
|
type: Inject,
|
|
1755
1937
|
args: [DEFAULT_SHOP]
|
|
1756
|
-
}] }, { type:
|
|
1938
|
+
}] }, { type: undefined, decorators: [{
|
|
1939
|
+
type: Inject,
|
|
1940
|
+
args: ['ProductSearch']
|
|
1941
|
+
}] }] });
|
|
1757
1942
|
|
|
1758
1943
|
class CategoryService {
|
|
1759
1944
|
constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
|
|
@@ -1820,11 +2005,14 @@ __decorate([
|
|
|
1820
2005
|
], CategoryWithTree.prototype, "children", void 0);
|
|
1821
2006
|
|
|
1822
2007
|
class WishlistService {
|
|
1823
|
-
constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository,
|
|
2008
|
+
constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productSearch, logRepository) {
|
|
1824
2009
|
this.wishlistRepository = wishlistRepository;
|
|
1825
2010
|
this.shop = shop;
|
|
2011
|
+
this.productRepository = productRepository;
|
|
2012
|
+
this.productSearch = productSearch;
|
|
2013
|
+
this.logRepository = logRepository;
|
|
1826
2014
|
const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
|
|
1827
|
-
this.catalogService = new CatalogService(productRepository, categoryRepository, categoryStructureAdapter, shop,
|
|
2015
|
+
this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch);
|
|
1828
2016
|
this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
|
|
1829
2017
|
}
|
|
1830
2018
|
getCatalogService() {
|
|
@@ -1833,46 +2021,76 @@ class WishlistService {
|
|
|
1833
2021
|
getCategoryService() {
|
|
1834
2022
|
return this.categoryService;
|
|
1835
2023
|
}
|
|
1836
|
-
async create({ personId, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
|
|
2024
|
+
async create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
|
|
1837
2025
|
const data = {
|
|
1838
2026
|
slug: '',
|
|
1839
2027
|
name: title,
|
|
1840
2028
|
description,
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
2029
|
+
metadatas: [
|
|
2030
|
+
{
|
|
2031
|
+
shop: this.shop,
|
|
2032
|
+
title: `${userFullName} - ${title}`,
|
|
2033
|
+
description: `${userFullName} - ${description}`,
|
|
2034
|
+
},
|
|
2035
|
+
],
|
|
1845
2036
|
shop: this.shop,
|
|
1846
2037
|
shops: [this.shop],
|
|
1847
2038
|
personId,
|
|
1848
2039
|
personName: userFullName,
|
|
1849
2040
|
personPhoto: userPhoto,
|
|
1850
2041
|
brandCategory: false,
|
|
1851
|
-
published
|
|
2042
|
+
published,
|
|
1852
2043
|
theme,
|
|
1853
2044
|
bannerUrl,
|
|
2045
|
+
personType: personType ?? PersonTypes.NONE,
|
|
2046
|
+
personIsSubscriber: personIsSubscriber ?? false,
|
|
1854
2047
|
};
|
|
2048
|
+
const hasWishlist = await this.wishlistRepository
|
|
2049
|
+
.find({
|
|
2050
|
+
filters: {
|
|
2051
|
+
personId,
|
|
2052
|
+
},
|
|
2053
|
+
options: {
|
|
2054
|
+
enableCount: false,
|
|
2055
|
+
},
|
|
2056
|
+
orderBy: {
|
|
2057
|
+
id: 'asc',
|
|
2058
|
+
},
|
|
2059
|
+
})
|
|
2060
|
+
.then((res) => res.data);
|
|
2061
|
+
await this.createWishlistLog(WishlistLogType.CREATE, data);
|
|
2062
|
+
if (hasWishlist.length)
|
|
2063
|
+
return hasWishlist.at(0);
|
|
1855
2064
|
const newWishlist = await this.wishlistRepository.create(data);
|
|
1856
2065
|
await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
|
|
1857
2066
|
return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
|
|
1858
2067
|
}
|
|
1859
|
-
update({ id, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
|
|
2068
|
+
async update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
|
|
1860
2069
|
const data = {
|
|
1861
2070
|
id,
|
|
1862
2071
|
name: title,
|
|
1863
2072
|
description,
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
2073
|
+
published,
|
|
2074
|
+
metadatas: [
|
|
2075
|
+
{
|
|
2076
|
+
shop: this.shop,
|
|
2077
|
+
title: `${userFullName} - ${title}`,
|
|
2078
|
+
description: `${userFullName} - ${description}`,
|
|
2079
|
+
},
|
|
2080
|
+
],
|
|
1868
2081
|
personName: userFullName,
|
|
1869
2082
|
personPhoto: userPhoto,
|
|
1870
2083
|
theme,
|
|
1871
2084
|
bannerUrl,
|
|
2085
|
+
personType: personType ?? PersonTypes.NONE,
|
|
2086
|
+
personIsSubscriber: personIsSubscriber ?? false,
|
|
1872
2087
|
};
|
|
2088
|
+
await this.createWishlistLog(WishlistLogType.UPDATE, data);
|
|
1873
2089
|
return this.wishlistRepository.update(data);
|
|
1874
2090
|
}
|
|
1875
|
-
delete(wishlistId) {
|
|
2091
|
+
async delete(wishlistId) {
|
|
2092
|
+
const wishlist = await this.findById(wishlistId);
|
|
2093
|
+
await this.createWishlistLog(WishlistLogType.DELETE, wishlist);
|
|
1876
2094
|
return this.wishlistRepository.delete({ id: wishlistId });
|
|
1877
2095
|
}
|
|
1878
2096
|
getWishlistBySlug(slug) {
|
|
@@ -1887,6 +2105,9 @@ class WishlistService {
|
|
|
1887
2105
|
async addProduct(wishlistId, productId) {
|
|
1888
2106
|
const wishlist = await this.wishlistRepository.get({ id: wishlistId });
|
|
1889
2107
|
const hasProduct = wishlist.products.some((p) => p == productId);
|
|
2108
|
+
const wishlistData = await this.findById(wishlistId);
|
|
2109
|
+
const productData = await this.findProductById(productId);
|
|
2110
|
+
await this.createWishlistLog(WishlistLogType.ADD_PRODUCT, wishlistData, productData);
|
|
1890
2111
|
if (!hasProduct) {
|
|
1891
2112
|
wishlist.products = [...wishlist.products, productId];
|
|
1892
2113
|
return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
|
|
@@ -1898,13 +2119,90 @@ class WishlistService {
|
|
|
1898
2119
|
const productIndex = wishlist.products.findIndex((p) => p == productId);
|
|
1899
2120
|
if (productIndex != -1) {
|
|
1900
2121
|
wishlist.products.splice(productIndex, 1);
|
|
2122
|
+
const wishlistData = await this.findById(wishlistId);
|
|
2123
|
+
const productData = await this.findProductById(productId);
|
|
2124
|
+
await this.createWishlistLog(WishlistLogType.REMOVE_PRODUCT, wishlistData, productData);
|
|
1901
2125
|
if (!wishlist.products.length)
|
|
1902
2126
|
return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
|
|
1903
2127
|
return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
|
|
1904
2128
|
}
|
|
1905
2129
|
return wishlist;
|
|
1906
2130
|
}
|
|
1907
|
-
|
|
2131
|
+
async findById(id) {
|
|
2132
|
+
return this.wishlistRepository
|
|
2133
|
+
.find({
|
|
2134
|
+
fields: ['id', 'name', 'description', 'personId', 'personIsSubscriber', 'personType', 'personName'],
|
|
2135
|
+
filters: {
|
|
2136
|
+
id,
|
|
2137
|
+
},
|
|
2138
|
+
})
|
|
2139
|
+
.then((res) => res.data.at(0));
|
|
2140
|
+
}
|
|
2141
|
+
async findProductById(id) {
|
|
2142
|
+
return this.productRepository
|
|
2143
|
+
.find({
|
|
2144
|
+
fields: ['id', 'sku', 'EAN', 'name', 'brand'],
|
|
2145
|
+
filters: {
|
|
2146
|
+
id,
|
|
2147
|
+
},
|
|
2148
|
+
})
|
|
2149
|
+
.then((res) => res.data.at(0));
|
|
2150
|
+
}
|
|
2151
|
+
async createWishlistLog(type, wishlist, product) {
|
|
2152
|
+
switch (type) {
|
|
2153
|
+
case WishlistLogType.CREATE:
|
|
2154
|
+
case WishlistLogType.UPDATE:
|
|
2155
|
+
case WishlistLogType.DELETE:
|
|
2156
|
+
await this.logRepository.create({
|
|
2157
|
+
collection: 'wishlist',
|
|
2158
|
+
date: new Date(),
|
|
2159
|
+
operation: WishlistLogType.CREATE ? 'CREATE' : WishlistLogType.UPDATE ? 'UPDATE' : 'DELETE',
|
|
2160
|
+
documentId: wishlist.id,
|
|
2161
|
+
document: {
|
|
2162
|
+
id: wishlist.id,
|
|
2163
|
+
shop: this.shop,
|
|
2164
|
+
name: wishlist.name,
|
|
2165
|
+
description: wishlist.description,
|
|
2166
|
+
published: wishlist.published,
|
|
2167
|
+
type: type,
|
|
2168
|
+
personType: wishlist.personType,
|
|
2169
|
+
personId: wishlist.personId,
|
|
2170
|
+
personName: wishlist.personName,
|
|
2171
|
+
personIsSubscriber: wishlist.personIsSubscriber,
|
|
2172
|
+
},
|
|
2173
|
+
});
|
|
2174
|
+
break;
|
|
2175
|
+
case WishlistLogType.ADD_PRODUCT:
|
|
2176
|
+
case WishlistLogType.REMOVE_PRODUCT:
|
|
2177
|
+
await this.logRepository.create({
|
|
2178
|
+
collection: 'wishlist',
|
|
2179
|
+
date: new Date(),
|
|
2180
|
+
operation: 'UPDATE',
|
|
2181
|
+
documentId: wishlist.id,
|
|
2182
|
+
document: {
|
|
2183
|
+
id: wishlist.id,
|
|
2184
|
+
shop: this.shop,
|
|
2185
|
+
name: wishlist.name,
|
|
2186
|
+
description: wishlist.description,
|
|
2187
|
+
published: wishlist.published,
|
|
2188
|
+
type: type,
|
|
2189
|
+
personType: wishlist.personType,
|
|
2190
|
+
personId: wishlist.personId,
|
|
2191
|
+
personName: wishlist.personName,
|
|
2192
|
+
personIsSubscriber: wishlist.personIsSubscriber,
|
|
2193
|
+
productId: product.id,
|
|
2194
|
+
productEAN: product.EAN,
|
|
2195
|
+
productSKU: product.sku,
|
|
2196
|
+
productName: product.name,
|
|
2197
|
+
productBrand: product.brand,
|
|
2198
|
+
},
|
|
2199
|
+
});
|
|
2200
|
+
break;
|
|
2201
|
+
default:
|
|
2202
|
+
break;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'ProductSearch' }, { token: 'LogRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1908
2206
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService }); }
|
|
1909
2207
|
}
|
|
1910
2208
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, decorators: [{
|
|
@@ -1924,31 +2222,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1924
2222
|
}] }, { type: undefined, decorators: [{
|
|
1925
2223
|
type: Inject,
|
|
1926
2224
|
args: ['CategoryRepository']
|
|
1927
|
-
}] }, { type:
|
|
2225
|
+
}] }, { type: undefined, decorators: [{
|
|
2226
|
+
type: Inject,
|
|
2227
|
+
args: ['ProductStockNotificationRepository']
|
|
2228
|
+
}] }, { type: undefined, decorators: [{
|
|
2229
|
+
type: Inject,
|
|
2230
|
+
args: ['ProductSearch']
|
|
2231
|
+
}] }, { type: undefined, decorators: [{
|
|
2232
|
+
type: Inject,
|
|
2233
|
+
args: ['LogRepository']
|
|
2234
|
+
}] }] });
|
|
1928
2235
|
|
|
1929
2236
|
class CheckoutSubscriptionService {
|
|
1930
|
-
constructor(checkoutSubscriptionRepository,
|
|
2237
|
+
constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
|
|
1931
2238
|
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
1932
|
-
this.
|
|
2239
|
+
this.dataPersistence = dataPersistence;
|
|
1933
2240
|
this.couponService = couponService;
|
|
1934
2241
|
}
|
|
1935
2242
|
getCheckoutSubscription(checkoutData) {
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
return from(this.createCheckoutSubscription(checkoutData));
|
|
1940
|
-
}
|
|
1941
|
-
async createCheckoutSubscription(checkoutData) {
|
|
1942
|
-
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
1943
|
-
createdAt: new Date(),
|
|
1944
|
-
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
1945
|
-
});
|
|
1946
|
-
cookie.set('checkoutSubscriptionId', checkout.id);
|
|
1947
|
-
return checkout;
|
|
2243
|
+
return this.dataPersistence
|
|
2244
|
+
.get('checkoutSubscriptionId')
|
|
2245
|
+
.pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
|
|
1948
2246
|
}
|
|
1949
2247
|
clearCheckoutSubscriptionFromSession() {
|
|
1950
|
-
|
|
1951
|
-
return of();
|
|
2248
|
+
return this.dataPersistence.remove('checkoutSubscriptionId');
|
|
1952
2249
|
}
|
|
1953
2250
|
checkCoupon(nickname, userEmail) {
|
|
1954
2251
|
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
@@ -1958,7 +2255,15 @@ class CheckoutSubscriptionService {
|
|
|
1958
2255
|
calcDiscountSubscription(coupon) {
|
|
1959
2256
|
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
1960
2257
|
}
|
|
1961
|
-
|
|
2258
|
+
async createCheckoutSubscription(checkoutData) {
|
|
2259
|
+
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
2260
|
+
createdAt: new Date(),
|
|
2261
|
+
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
2262
|
+
});
|
|
2263
|
+
await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
|
|
2264
|
+
return checkout;
|
|
2265
|
+
}
|
|
2266
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: PERSISTENCE_PROVIDER }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1962
2267
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService }); }
|
|
1963
2268
|
}
|
|
1964
2269
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
@@ -1968,7 +2273,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1968
2273
|
args: ['CheckoutSubscriptionRepository']
|
|
1969
2274
|
}] }, { type: undefined, decorators: [{
|
|
1970
2275
|
type: Inject,
|
|
1971
|
-
args: [
|
|
2276
|
+
args: [PERSISTENCE_PROVIDER]
|
|
1972
2277
|
}] }, { type: CouponService }] });
|
|
1973
2278
|
|
|
1974
2279
|
class UtilHelper {
|
|
@@ -2053,10 +2358,10 @@ class HomeShopService {
|
|
|
2053
2358
|
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
2054
2359
|
}
|
|
2055
2360
|
getDiscoverProducts(gender) {
|
|
2056
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories,
|
|
2361
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories, this.defaultShop)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
2057
2362
|
}
|
|
2058
2363
|
getFeaturedProducts(gender) {
|
|
2059
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories,
|
|
2364
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories, this.defaultShop)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
2060
2365
|
}
|
|
2061
2366
|
getVerticalProducts(gender) {
|
|
2062
2367
|
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({
|
|
@@ -2226,10 +2531,12 @@ class AngularConnectModule {
|
|
|
2226
2531
|
? OldCategoryStructureAdapter
|
|
2227
2532
|
: NewCategoryStructureAdapter,
|
|
2228
2533
|
},
|
|
2534
|
+
{ provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
|
|
2229
2535
|
...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
|
|
2230
2536
|
...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
|
|
2231
2537
|
...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
|
|
2232
2538
|
...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
|
|
2539
|
+
...(isNil(options?.vertexConfig) ? [] : [{ provide: VERTEX_CONFIG, useValue: options.vertexConfig }]),
|
|
2233
2540
|
...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
|
|
2234
2541
|
...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
|
|
2235
2542
|
...(isNil(options?.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
|
|
@@ -2237,7 +2544,8 @@ class AngularConnectModule {
|
|
|
2237
2544
|
};
|
|
2238
2545
|
}
|
|
2239
2546
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
2240
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, AngularElasticSeachModule,
|
|
2547
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
|
|
2548
|
+
AngularVertexSeachModule,
|
|
2241
2549
|
AngularFirebaseAuthModule,
|
|
2242
2550
|
AngularFirestoreModule,
|
|
2243
2551
|
AngularHasuraGraphQLModule] }); }
|
|
@@ -2260,6 +2568,17 @@ class AngularConnectModule {
|
|
|
2260
2568
|
},
|
|
2261
2569
|
deps: ['UserRepository', 'FileUploaderService'],
|
|
2262
2570
|
},
|
|
2571
|
+
{
|
|
2572
|
+
provide: 'FileUploaderService',
|
|
2573
|
+
useFactory: (storage, baseUrl) => {
|
|
2574
|
+
return new FirebaseFileUploaderService(storage, baseUrl);
|
|
2575
|
+
},
|
|
2576
|
+
deps: [Storage, STORAGE_BASE_URL],
|
|
2577
|
+
},
|
|
2578
|
+
{
|
|
2579
|
+
provide: 'ProductSearch',
|
|
2580
|
+
useExisting: ProductsVertexSearch,
|
|
2581
|
+
},
|
|
2263
2582
|
], imports: [provideFirebaseApp((injector) => {
|
|
2264
2583
|
const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
|
|
2265
2584
|
try {
|
|
@@ -2269,7 +2588,9 @@ class AngularConnectModule {
|
|
|
2269
2588
|
return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
|
|
2270
2589
|
}
|
|
2271
2590
|
}),
|
|
2591
|
+
provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
|
|
2272
2592
|
AngularElasticSeachModule,
|
|
2593
|
+
AngularVertexSeachModule,
|
|
2273
2594
|
AngularFirebaseAuthModule,
|
|
2274
2595
|
AngularFirestoreModule,
|
|
2275
2596
|
AngularHasuraGraphQLModule] }); }
|
|
@@ -2287,7 +2608,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2287
2608
|
return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
|
|
2288
2609
|
}
|
|
2289
2610
|
}),
|
|
2611
|
+
provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
|
|
2290
2612
|
AngularElasticSeachModule,
|
|
2613
|
+
AngularVertexSeachModule,
|
|
2291
2614
|
AngularFirebaseAuthModule,
|
|
2292
2615
|
AngularFirestoreModule,
|
|
2293
2616
|
AngularHasuraGraphQLModule,
|
|
@@ -2311,6 +2634,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2311
2634
|
},
|
|
2312
2635
|
deps: ['UserRepository', 'FileUploaderService'],
|
|
2313
2636
|
},
|
|
2637
|
+
{
|
|
2638
|
+
provide: 'FileUploaderService',
|
|
2639
|
+
useFactory: (storage, baseUrl) => {
|
|
2640
|
+
return new FirebaseFileUploaderService(storage, baseUrl);
|
|
2641
|
+
},
|
|
2642
|
+
deps: [Storage, STORAGE_BASE_URL],
|
|
2643
|
+
},
|
|
2644
|
+
{
|
|
2645
|
+
provide: 'ProductSearch',
|
|
2646
|
+
useExisting: ProductsVertexSearch,
|
|
2647
|
+
},
|
|
2314
2648
|
],
|
|
2315
2649
|
}]
|
|
2316
2650
|
}] });
|
|
@@ -2319,5 +2653,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2319
2653
|
* Generated bundle index. Do not edit.
|
|
2320
2654
|
*/
|
|
2321
2655
|
|
|
2322
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
|
|
2656
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
|
|
2323
2657
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|