@infrab4a/connect-angular 5.0.0-beta.78 → 5.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/angular-connect.module.d.ts +9 -17
- package/angular-firestore.module.d.ts +2 -1
- package/angular-hasura-graphql.module.d.ts +1 -1
- package/consts/firebase-const.d.ts +0 -1
- package/consts/index.d.ts +0 -2
- package/esm2022/angular-connect.module.mjs +10 -86
- package/esm2022/angular-elastic-search.module.mjs +1 -1
- package/esm2022/angular-firebase-auth.module.mjs +4 -30
- package/esm2022/angular-firestore.module.mjs +28 -53
- package/esm2022/angular-hasura-graphql.module.mjs +8 -74
- 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 -2
- package/esm2022/consts/hasura-options.const.mjs +1 -1
- package/esm2022/consts/index.mjs +1 -3
- package/esm2022/consts/storage-base-url.const.mjs +1 -1
- package/esm2022/helpers/index.mjs +1 -1
- package/esm2022/helpers/mobile-operation-system-checker.helper.mjs +1 -1
- package/esm2022/index.mjs +1 -2
- package/esm2022/services/auth.service.mjs +1 -1
- package/esm2022/services/cart.service.mjs +32 -44
- 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 +4 -6
- package/esm2022/services/catalog/adapters/old-category-structure.adapter.mjs +1 -1
- package/esm2022/services/catalog/catalog.service.mjs +48 -158
- package/esm2022/services/catalog/category.service.mjs +4 -4
- 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 +22 -142
- package/esm2022/services/checkout-subscription.service.mjs +21 -18
- package/esm2022/services/checkout.service.mjs +16 -13
- package/esm2022/services/coupon.service.mjs +30 -79
- 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 +210 -743
- package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
- package/index.d.ts +0 -1
- package/package.json +6 -6
- package/services/cart.service.d.ts +0 -1
- package/services/catalog/catalog.service.d.ts +4 -11
- package/services/catalog/category.service.d.ts +1 -6
- package/services/catalog/wishlist.service.d.ts +4 -16
- package/services/checkout-subscription.service.d.ts +4 -5
- package/services/checkout.service.d.ts +4 -8
- package/services/coupon.service.d.ts +2 -6
- package/angular-vertex-search.module.d.ts +0 -9
- package/consts/persistence.const.d.ts +0 -1
- package/consts/vertex-config.const.d.ts +0 -1
- package/esm2022/angular-vertex-search.module.mjs +0 -34
- package/esm2022/consts/persistence.const.mjs +0 -2
- package/esm2022/consts/vertex-config.const.mjs +0 -2
- package/esm2022/persistence/cookie-data-persistence.mjs +0 -22
- package/esm2022/persistence/data-persistence.mjs +0 -2
- package/esm2022/persistence/index.mjs +0 -3
- package/persistence/cookie-data-persistence.d.ts +0 -10
- package/persistence/data-persistence.d.ts +0 -6
- package/persistence/index.d.ts +0 -2
|
@@ -2,20 +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/app-check';
|
|
6
|
-
import { provideAppCheck, initializeAppCheck } from '@angular/fire/app-check';
|
|
7
|
-
import * as i3 from '@angular/fire/storage';
|
|
8
|
-
import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
|
|
9
5
|
import * as i1$2 from '@infrab4a/connect';
|
|
10
|
-
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword,
|
|
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, FirebaseFileUploaderService, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage } from '@infrab4a/connect';
|
|
11
7
|
import * as i1 from '@angular/fire/auth';
|
|
12
|
-
import { Auth, provideAuth,
|
|
8
|
+
import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
13
9
|
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
|
|
14
10
|
import * as i1$1 from '@angular/fire/firestore';
|
|
15
|
-
import { Firestore, provideFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
11
|
+
import { Firestore, provideFirestore, getFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
|
|
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';
|
|
18
15
|
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
16
|
+
import cookie from 'js-cookie';
|
|
19
17
|
import { __decorate, __metadata } from 'tslib';
|
|
20
18
|
import { Type } from 'class-transformer';
|
|
21
19
|
import * as i1$3 from '@angular/common/http';
|
|
@@ -60,14 +58,9 @@ const DEFAULT_SHOP = 'DEFAULT_SHOP';
|
|
|
60
58
|
|
|
61
59
|
const FIREBASE_APP_NAME = new InjectionToken('firebaseAppName');
|
|
62
60
|
const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
|
|
63
|
-
const APP_CHECK_PROVIDER = new InjectionToken('appCheckProvider');
|
|
64
61
|
|
|
65
62
|
const HASURA_OPTIONS = 'HASURA_OPTIONS';
|
|
66
63
|
|
|
67
|
-
const PERSISTENCE_PROVIDER = 'PERSISTENCE_PROVIDER';
|
|
68
|
-
|
|
69
|
-
const VERTEX_CONFIG = 'VERTEX_CONFIG';
|
|
70
|
-
|
|
71
64
|
class AngularFirebaseAuthModule {
|
|
72
65
|
static initializeApp(options, nameOrConfig) {
|
|
73
66
|
return {
|
|
@@ -123,38 +116,12 @@ class AngularFirebaseAuthModule {
|
|
|
123
116
|
},
|
|
124
117
|
deps: ['AuthenticationService'],
|
|
125
118
|
},
|
|
126
|
-
], imports: [provideAuth((injector) =>
|
|
127
|
-
const app = injector.get(FirebaseApp);
|
|
128
|
-
try {
|
|
129
|
-
return initializeAuth(app, {
|
|
130
|
-
persistence: [indexedDBLocalPersistence, browserLocalPersistence],
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
if (error instanceof Error)
|
|
135
|
-
console.error('Error initializing auth', error.message);
|
|
136
|
-
return getAuth(app);
|
|
137
|
-
}
|
|
138
|
-
})] }); }
|
|
119
|
+
], imports: [provideAuth((injector) => getAuth(injector.get(FirebaseApp)))] }); }
|
|
139
120
|
}
|
|
140
121
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
|
|
141
122
|
type: NgModule,
|
|
142
123
|
args: [{
|
|
143
|
-
imports: [
|
|
144
|
-
provideAuth((injector) => {
|
|
145
|
-
const app = injector.get(FirebaseApp);
|
|
146
|
-
try {
|
|
147
|
-
return initializeAuth(app, {
|
|
148
|
-
persistence: [indexedDBLocalPersistence, browserLocalPersistence],
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
if (error instanceof Error)
|
|
153
|
-
console.error('Error initializing auth', error.message);
|
|
154
|
-
return getAuth(app);
|
|
155
|
-
}
|
|
156
|
-
}),
|
|
157
|
-
],
|
|
124
|
+
imports: [provideAuth((injector) => getAuth(injector.get(FirebaseApp)))],
|
|
158
125
|
providers: [
|
|
159
126
|
{
|
|
160
127
|
provide: 'Authentication',
|
|
@@ -202,6 +169,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
202
169
|
}]
|
|
203
170
|
}] });
|
|
204
171
|
|
|
172
|
+
const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
|
|
173
|
+
|
|
205
174
|
class MobileOperationSystemCheckerHelper {
|
|
206
175
|
static isAppleDevice() {
|
|
207
176
|
return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator?.platform) ||
|
|
@@ -221,12 +190,12 @@ class AngularFirestoreModule {
|
|
|
221
190
|
};
|
|
222
191
|
}
|
|
223
192
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
224
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule] }); }
|
|
193
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule, i2.StorageModule] }); }
|
|
225
194
|
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, providers: [
|
|
226
195
|
{
|
|
227
196
|
provide: 'FirestoreOptions',
|
|
228
197
|
useFactory: (firestore, platformId) => ({
|
|
229
|
-
firestore
|
|
198
|
+
firestore,
|
|
230
199
|
interceptors: {
|
|
231
200
|
request: (request) => {
|
|
232
201
|
if (isPlatformBrowser(platformId))
|
|
@@ -435,40 +404,26 @@ class AngularFirestoreModule {
|
|
|
435
404
|
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
436
405
|
},
|
|
437
406
|
{
|
|
438
|
-
provide: '
|
|
439
|
-
useFactory: (
|
|
440
|
-
return new
|
|
441
|
-
},
|
|
442
|
-
deps: ['FirestoreOptions'],
|
|
443
|
-
},
|
|
444
|
-
{
|
|
445
|
-
provide: 'LogRepository',
|
|
446
|
-
useFactory: (options) => {
|
|
447
|
-
return new LogFirestoreRepository(options);
|
|
448
|
-
},
|
|
449
|
-
deps: ['FirestoreOptions'],
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
provide: 'SequenceRepository',
|
|
453
|
-
useFactory: (options) => {
|
|
454
|
-
return new SequenceFirestoreRepository(options);
|
|
407
|
+
provide: 'FileUploaderService',
|
|
408
|
+
useFactory: (storage, baseUrl) => {
|
|
409
|
+
return new FirebaseFileUploaderService(storage, baseUrl);
|
|
455
410
|
},
|
|
456
|
-
deps: [
|
|
411
|
+
deps: [Storage, STORAGE_BASE_URL],
|
|
457
412
|
},
|
|
458
413
|
], imports: [AngularElasticSeachModule,
|
|
459
414
|
provideFirestore((injector) => {
|
|
460
415
|
const platformId = injector.get(PLATFORM_ID);
|
|
461
|
-
if (isPlatformServer(platformId)
|
|
462
|
-
return
|
|
463
|
-
|
|
464
|
-
|
|
416
|
+
if (isPlatformServer(platformId))
|
|
417
|
+
return getFirestore(injector.get(FirebaseApp));
|
|
418
|
+
if (!MobileOperationSystemCheckerHelper.isAppleDevice())
|
|
419
|
+
return getFirestore(injector.get(FirebaseApp));
|
|
465
420
|
const firestore = initializeFirestore(injector.get(FirebaseApp), {
|
|
466
421
|
experimentalForceLongPolling: true,
|
|
467
|
-
ignoreUndefinedProperties: true,
|
|
468
422
|
localCache: memoryLocalCache(),
|
|
469
423
|
});
|
|
470
424
|
return firestore;
|
|
471
|
-
})
|
|
425
|
+
}),
|
|
426
|
+
provideStorage(() => getStorage())] }); }
|
|
472
427
|
}
|
|
473
428
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, decorators: [{
|
|
474
429
|
type: NgModule,
|
|
@@ -477,23 +432,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
477
432
|
AngularElasticSeachModule,
|
|
478
433
|
provideFirestore((injector) => {
|
|
479
434
|
const platformId = injector.get(PLATFORM_ID);
|
|
480
|
-
if (isPlatformServer(platformId)
|
|
481
|
-
return
|
|
482
|
-
|
|
483
|
-
|
|
435
|
+
if (isPlatformServer(platformId))
|
|
436
|
+
return getFirestore(injector.get(FirebaseApp));
|
|
437
|
+
if (!MobileOperationSystemCheckerHelper.isAppleDevice())
|
|
438
|
+
return getFirestore(injector.get(FirebaseApp));
|
|
484
439
|
const firestore = initializeFirestore(injector.get(FirebaseApp), {
|
|
485
440
|
experimentalForceLongPolling: true,
|
|
486
|
-
ignoreUndefinedProperties: true,
|
|
487
441
|
localCache: memoryLocalCache(),
|
|
488
442
|
});
|
|
489
443
|
return firestore;
|
|
490
444
|
}),
|
|
445
|
+
provideStorage(() => getStorage()),
|
|
491
446
|
],
|
|
492
447
|
providers: [
|
|
493
448
|
{
|
|
494
449
|
provide: 'FirestoreOptions',
|
|
495
450
|
useFactory: (firestore, platformId) => ({
|
|
496
|
-
firestore
|
|
451
|
+
firestore,
|
|
497
452
|
interceptors: {
|
|
498
453
|
request: (request) => {
|
|
499
454
|
if (isPlatformBrowser(platformId))
|
|
@@ -702,25 +657,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
702
657
|
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
703
658
|
},
|
|
704
659
|
{
|
|
705
|
-
provide: '
|
|
706
|
-
useFactory: (
|
|
707
|
-
return new
|
|
708
|
-
},
|
|
709
|
-
deps: ['FirestoreOptions'],
|
|
710
|
-
},
|
|
711
|
-
{
|
|
712
|
-
provide: 'LogRepository',
|
|
713
|
-
useFactory: (options) => {
|
|
714
|
-
return new LogFirestoreRepository(options);
|
|
715
|
-
},
|
|
716
|
-
deps: ['FirestoreOptions'],
|
|
717
|
-
},
|
|
718
|
-
{
|
|
719
|
-
provide: 'SequenceRepository',
|
|
720
|
-
useFactory: (options) => {
|
|
721
|
-
return new SequenceFirestoreRepository(options);
|
|
660
|
+
provide: 'FileUploaderService',
|
|
661
|
+
useFactory: (storage, baseUrl) => {
|
|
662
|
+
return new FirebaseFileUploaderService(storage, baseUrl);
|
|
722
663
|
},
|
|
723
|
-
deps: [
|
|
664
|
+
deps: [Storage, STORAGE_BASE_URL],
|
|
724
665
|
},
|
|
725
666
|
],
|
|
726
667
|
}]
|
|
@@ -803,17 +744,6 @@ class AngularHasuraGraphQLModule {
|
|
|
803
744
|
},
|
|
804
745
|
deps: ['HasuraConfig'],
|
|
805
746
|
},
|
|
806
|
-
{
|
|
807
|
-
provide: 'ProductStockNotificationRepository',
|
|
808
|
-
useExisting: ProductStockNotificationHasuraGraphQLRepository,
|
|
809
|
-
},
|
|
810
|
-
{
|
|
811
|
-
provide: ProductStockNotificationHasuraGraphQLRepository,
|
|
812
|
-
useFactory: (hasuraConfig) => {
|
|
813
|
-
return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
|
|
814
|
-
},
|
|
815
|
-
deps: ['HasuraConfig'],
|
|
816
|
-
},
|
|
817
747
|
{
|
|
818
748
|
provide: 'CategoryFilterRepository',
|
|
819
749
|
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
@@ -856,39 +786,17 @@ class AngularHasuraGraphQLModule {
|
|
|
856
786
|
provide: 'CategoryCollectionChildrenRepository',
|
|
857
787
|
useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
|
|
858
788
|
},
|
|
859
|
-
{
|
|
860
|
-
provide: CategoryProductHasuraGraphQLRepository,
|
|
861
|
-
useFactory: (options) => {
|
|
862
|
-
return new CategoryProductHasuraGraphQLRepository(options);
|
|
863
|
-
},
|
|
864
|
-
deps: ['HasuraConfig'],
|
|
865
|
-
},
|
|
866
|
-
{
|
|
867
|
-
provide: 'CategoryProductRepository',
|
|
868
|
-
useExisting: CategoryProductHasuraGraphQLRepository,
|
|
869
|
-
},
|
|
870
789
|
{
|
|
871
790
|
provide: WishlistHasuraGraphQLRepository,
|
|
872
|
-
useFactory: (options,
|
|
873
|
-
return new WishlistHasuraGraphQLRepository(options,
|
|
791
|
+
useFactory: (options, categoryFilterRepository) => {
|
|
792
|
+
return new WishlistHasuraGraphQLRepository(options, categoryFilterRepository);
|
|
874
793
|
},
|
|
875
|
-
deps: ['HasuraConfig',
|
|
794
|
+
deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
|
|
876
795
|
},
|
|
877
796
|
{
|
|
878
797
|
provide: 'WishlistRepository',
|
|
879
798
|
useExisting: WishlistHasuraGraphQLRepository,
|
|
880
799
|
},
|
|
881
|
-
{
|
|
882
|
-
provide: ProductErrorsHasuraGraphQLRepository,
|
|
883
|
-
useFactory: (options) => {
|
|
884
|
-
return new ProductErrorsHasuraGraphQLRepository(options);
|
|
885
|
-
},
|
|
886
|
-
deps: ['HasuraConfig'],
|
|
887
|
-
},
|
|
888
|
-
{
|
|
889
|
-
provide: 'ProductErrorsRepository',
|
|
890
|
-
useExisting: ProductErrorsHasuraGraphQLRepository,
|
|
891
|
-
},
|
|
892
800
|
] }); }
|
|
893
801
|
}
|
|
894
802
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
|
|
@@ -962,17 +870,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
962
870
|
},
|
|
963
871
|
deps: ['HasuraConfig'],
|
|
964
872
|
},
|
|
965
|
-
{
|
|
966
|
-
provide: 'ProductStockNotificationRepository',
|
|
967
|
-
useExisting: ProductStockNotificationHasuraGraphQLRepository,
|
|
968
|
-
},
|
|
969
|
-
{
|
|
970
|
-
provide: ProductStockNotificationHasuraGraphQLRepository,
|
|
971
|
-
useFactory: (hasuraConfig) => {
|
|
972
|
-
return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
|
|
973
|
-
},
|
|
974
|
-
deps: ['HasuraConfig'],
|
|
975
|
-
},
|
|
976
873
|
{
|
|
977
874
|
provide: 'CategoryFilterRepository',
|
|
978
875
|
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
@@ -1015,92 +912,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1015
912
|
provide: 'CategoryCollectionChildrenRepository',
|
|
1016
913
|
useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
|
|
1017
914
|
},
|
|
1018
|
-
{
|
|
1019
|
-
provide: CategoryProductHasuraGraphQLRepository,
|
|
1020
|
-
useFactory: (options) => {
|
|
1021
|
-
return new CategoryProductHasuraGraphQLRepository(options);
|
|
1022
|
-
},
|
|
1023
|
-
deps: ['HasuraConfig'],
|
|
1024
|
-
},
|
|
1025
|
-
{
|
|
1026
|
-
provide: 'CategoryProductRepository',
|
|
1027
|
-
useExisting: CategoryProductHasuraGraphQLRepository,
|
|
1028
|
-
},
|
|
1029
915
|
{
|
|
1030
916
|
provide: WishlistHasuraGraphQLRepository,
|
|
1031
|
-
useFactory: (options,
|
|
1032
|
-
return new WishlistHasuraGraphQLRepository(options,
|
|
917
|
+
useFactory: (options, categoryFilterRepository) => {
|
|
918
|
+
return new WishlistHasuraGraphQLRepository(options, categoryFilterRepository);
|
|
1033
919
|
},
|
|
1034
|
-
deps: ['HasuraConfig',
|
|
920
|
+
deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
|
|
1035
921
|
},
|
|
1036
922
|
{
|
|
1037
923
|
provide: 'WishlistRepository',
|
|
1038
924
|
useExisting: WishlistHasuraGraphQLRepository,
|
|
1039
925
|
},
|
|
1040
|
-
{
|
|
1041
|
-
provide: ProductErrorsHasuraGraphQLRepository,
|
|
1042
|
-
useFactory: (options) => {
|
|
1043
|
-
return new ProductErrorsHasuraGraphQLRepository(options);
|
|
1044
|
-
},
|
|
1045
|
-
deps: ['HasuraConfig'],
|
|
1046
|
-
},
|
|
1047
|
-
{
|
|
1048
|
-
provide: 'ProductErrorsRepository',
|
|
1049
|
-
useExisting: ProductErrorsHasuraGraphQLRepository,
|
|
1050
|
-
},
|
|
1051
926
|
],
|
|
1052
927
|
}]
|
|
1053
928
|
}] });
|
|
1054
929
|
|
|
1055
|
-
class AngularVertexSeachModule {
|
|
1056
|
-
static initializeApp(options) {
|
|
1057
|
-
return {
|
|
1058
|
-
ngModule: AngularVertexSeachModule,
|
|
1059
|
-
providers: [{ provide: VERTEX_CONFIG, useValue: options }],
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1063
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule }); }
|
|
1064
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, providers: [
|
|
1065
|
-
{
|
|
1066
|
-
provide: ProductsVertexSearch,
|
|
1067
|
-
useFactory: (configuration) => new ProductsVertexSearch(new VertexAxiosAdapter(configuration)),
|
|
1068
|
-
deps: [VERTEX_CONFIG],
|
|
1069
|
-
},
|
|
1070
|
-
] }); }
|
|
1071
|
-
}
|
|
1072
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, decorators: [{
|
|
1073
|
-
type: NgModule,
|
|
1074
|
-
args: [{
|
|
1075
|
-
providers: [
|
|
1076
|
-
{
|
|
1077
|
-
provide: ProductsVertexSearch,
|
|
1078
|
-
useFactory: (configuration) => new ProductsVertexSearch(new VertexAxiosAdapter(configuration)),
|
|
1079
|
-
deps: [VERTEX_CONFIG],
|
|
1080
|
-
},
|
|
1081
|
-
],
|
|
1082
|
-
}]
|
|
1083
|
-
}] });
|
|
1084
|
-
|
|
1085
|
-
const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
|
|
1086
|
-
|
|
1087
|
-
class CookieDataPersistence {
|
|
1088
|
-
get(key) {
|
|
1089
|
-
return of(cookie.get(key));
|
|
1090
|
-
}
|
|
1091
|
-
remove(key) {
|
|
1092
|
-
return of(cookie.remove(key));
|
|
1093
|
-
}
|
|
1094
|
-
set(key, value) {
|
|
1095
|
-
return from(cookie.set(key, value)).pipe(map(() => { }));
|
|
1096
|
-
}
|
|
1097
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1098
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence }); }
|
|
1099
|
-
}
|
|
1100
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, decorators: [{
|
|
1101
|
-
type: Injectable
|
|
1102
|
-
}] });
|
|
1103
|
-
|
|
1104
930
|
class AuthService {
|
|
1105
931
|
constructor(angularFireAuth, userRepository) {
|
|
1106
932
|
this.angularFireAuth = angularFireAuth;
|
|
@@ -1181,11 +1007,11 @@ class CouponService {
|
|
|
1181
1007
|
throw 'Limite de uso atingido';
|
|
1182
1008
|
}
|
|
1183
1009
|
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
1184
|
-
const
|
|
1185
|
-
if (!couponUseLimits.unlimited && couponUseLimits.total &&
|
|
1010
|
+
const orders = await this.getOrdersWithCoupon(coupon);
|
|
1011
|
+
if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
|
|
1186
1012
|
throw 'Limite de uso atingido.';
|
|
1187
1013
|
if (couponUseLimits.limitedPerUser) {
|
|
1188
|
-
const ordersWithUser = this.countOrdersWithUser(
|
|
1014
|
+
const ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
|
|
1189
1015
|
if (ordersWithUser > 0)
|
|
1190
1016
|
throw 'Limite de uso por usuário atingido.';
|
|
1191
1017
|
}
|
|
@@ -1194,12 +1020,8 @@ class CouponService {
|
|
|
1194
1020
|
if (!hasProductCategories)
|
|
1195
1021
|
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
1196
1022
|
const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
|
|
1197
|
-
if (!hasMinSubTotal)
|
|
1198
|
-
|
|
1199
|
-
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.`;
|
|
1200
|
-
}
|
|
1201
|
-
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido.`;
|
|
1202
|
-
}
|
|
1023
|
+
if (!hasMinSubTotal)
|
|
1024
|
+
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`;
|
|
1203
1025
|
return coupon;
|
|
1204
1026
|
}
|
|
1205
1027
|
calcDiscountSubscription(coupon, checkout) {
|
|
@@ -1211,53 +1033,45 @@ class CouponService {
|
|
|
1211
1033
|
return of(discount);
|
|
1212
1034
|
}
|
|
1213
1035
|
async calcDiscountShopping(coupon, checkout) {
|
|
1214
|
-
let
|
|
1036
|
+
let discount = 0;
|
|
1215
1037
|
if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
|
|
1216
|
-
|
|
1038
|
+
discount = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
|
|
1217
1039
|
}
|
|
1218
1040
|
else {
|
|
1219
|
-
|
|
1041
|
+
discount = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
|
|
1220
1042
|
}
|
|
1221
|
-
return
|
|
1043
|
+
return discount;
|
|
1222
1044
|
}
|
|
1223
1045
|
async calcDiscountByType(type, value, categories, checkout) {
|
|
1224
1046
|
let discount = 0;
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
const discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
|
|
1228
|
-
return { discount, lineItems: checkout.lineItems };
|
|
1229
|
-
}
|
|
1230
|
-
const lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
|
|
1231
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
|
|
1047
|
+
let lineItensDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
|
|
1048
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
|
|
1232
1049
|
if (type == CouponTypes.ABSOLUTE) {
|
|
1233
1050
|
discount = value > subTotal ? subTotal : value;
|
|
1234
1051
|
}
|
|
1235
1052
|
else {
|
|
1236
|
-
discount =
|
|
1053
|
+
discount = subTotal * (value / 100);
|
|
1237
1054
|
}
|
|
1238
|
-
|
|
1239
|
-
return { discount, lineItems };
|
|
1055
|
+
return discount;
|
|
1240
1056
|
}
|
|
1241
1057
|
async hasMinSubTotal(coupon, checkout) {
|
|
1242
1058
|
if (!coupon.minSubTotalValue)
|
|
1243
1059
|
return true;
|
|
1244
|
-
|
|
1245
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
1060
|
+
let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
1061
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
|
|
1246
1062
|
if (coupon.minSubTotalValue <= subTotal)
|
|
1247
1063
|
return true;
|
|
1248
1064
|
return false;
|
|
1249
1065
|
}
|
|
1250
1066
|
async hasProductCategories(coupon, checkout) {
|
|
1251
|
-
if (!coupon.productsCategories || !coupon.productsCategories
|
|
1067
|
+
if (!coupon.productsCategories || !coupon.productsCategories.length) {
|
|
1252
1068
|
return true;
|
|
1253
1069
|
}
|
|
1254
1070
|
const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
|
|
1255
|
-
const hasCategories = checkout.lineItems?.filter((
|
|
1256
|
-
if (
|
|
1257
|
-
return false;
|
|
1258
|
-
if (!item.categories || !item.categories?.length)
|
|
1071
|
+
const hasCategories = checkout.lineItems?.filter((i) => {
|
|
1072
|
+
if (!i.categories || !i.categories?.length)
|
|
1259
1073
|
return true;
|
|
1260
|
-
return
|
|
1074
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
1261
1075
|
});
|
|
1262
1076
|
return hasCategories.length ? true : false;
|
|
1263
1077
|
}
|
|
@@ -1300,24 +1114,20 @@ class CouponService {
|
|
|
1300
1114
|
let lineItensDiscount = [];
|
|
1301
1115
|
const couponCategories = await this.getCouponCategoriesId(productsCategories);
|
|
1302
1116
|
if (productsCategories && productsCategories.length) {
|
|
1303
|
-
lineItensDiscount = checkout.lineItems?.filter((
|
|
1304
|
-
if (
|
|
1305
|
-
return
|
|
1306
|
-
if (item.categories?.length) {
|
|
1307
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
1117
|
+
lineItensDiscount = checkout.lineItems?.filter((i) => {
|
|
1118
|
+
if (i.categories?.length) {
|
|
1119
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
1308
1120
|
}
|
|
1309
1121
|
return true;
|
|
1310
1122
|
});
|
|
1311
1123
|
}
|
|
1312
1124
|
else {
|
|
1313
|
-
lineItensDiscount = checkout.lineItems
|
|
1125
|
+
lineItensDiscount = checkout.lineItems;
|
|
1314
1126
|
}
|
|
1315
1127
|
return lineItensDiscount;
|
|
1316
1128
|
}
|
|
1317
|
-
calcCheckoutSubtotal(lineItens, user) {
|
|
1318
|
-
return (lineItens
|
|
1319
|
-
?.filter((item) => !item.isGift)
|
|
1320
|
-
.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
|
|
1129
|
+
calcCheckoutSubtotal(lineItens, user, shop) {
|
|
1130
|
+
return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
|
|
1321
1131
|
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
1322
1132
|
: acc + curr.pricePaid * curr.quantity, 0) || 0);
|
|
1323
1133
|
}
|
|
@@ -1326,7 +1136,7 @@ class CouponService {
|
|
|
1326
1136
|
.find({
|
|
1327
1137
|
filters: {
|
|
1328
1138
|
coupon: { id: coupon.id },
|
|
1329
|
-
|
|
1139
|
+
payment: { status: 'paid' },
|
|
1330
1140
|
},
|
|
1331
1141
|
})
|
|
1332
1142
|
.then((result) => result.data);
|
|
@@ -1336,7 +1146,7 @@ class CouponService {
|
|
|
1336
1146
|
.find({
|
|
1337
1147
|
filters: {
|
|
1338
1148
|
user: { email: { operator: Where.EQUALS, value: email } },
|
|
1339
|
-
|
|
1149
|
+
payment: { status: 'paid' },
|
|
1340
1150
|
},
|
|
1341
1151
|
})
|
|
1342
1152
|
.then((result) => result.data);
|
|
@@ -1347,46 +1157,13 @@ class CouponService {
|
|
|
1347
1157
|
getCouponUseLimits(coupon, checkoutType, user) {
|
|
1348
1158
|
let couponUseLimits;
|
|
1349
1159
|
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
1350
|
-
|
|
1351
|
-
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
1352
|
-
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
1353
|
-
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
1354
|
-
else
|
|
1355
|
-
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
1160
|
+
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
1356
1161
|
}
|
|
1357
1162
|
else {
|
|
1358
1163
|
couponUseLimits = coupon.useLimits.subscription;
|
|
1359
1164
|
}
|
|
1360
1165
|
return couponUseLimits;
|
|
1361
1166
|
}
|
|
1362
|
-
calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
|
|
1363
|
-
let lineItemsDiscount = [];
|
|
1364
|
-
if (type === CouponTypes.ABSOLUTE) {
|
|
1365
|
-
const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
|
|
1366
|
-
lineItemsDiscount = lineItems.map((item) => {
|
|
1367
|
-
if (item.isGift)
|
|
1368
|
-
return item;
|
|
1369
|
-
const totalItemPercentage = item.pricePaid / subTotal;
|
|
1370
|
-
const discountItem = couponDiscountMax * totalItemPercentage;
|
|
1371
|
-
return {
|
|
1372
|
-
...item,
|
|
1373
|
-
discount: Number(discountItem.toFixed(2)),
|
|
1374
|
-
};
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
else {
|
|
1378
|
-
lineItemsDiscount = lineItems.map((item) => {
|
|
1379
|
-
if (item.isGift)
|
|
1380
|
-
return item;
|
|
1381
|
-
const discountItem = item.pricePaid * (couponDiscount / 100);
|
|
1382
|
-
return {
|
|
1383
|
-
...item,
|
|
1384
|
-
discount: Number(discountItem.toFixed(2)),
|
|
1385
|
-
};
|
|
1386
|
-
});
|
|
1387
|
-
}
|
|
1388
|
-
return lineItemsDiscount;
|
|
1389
|
-
}
|
|
1390
1167
|
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 }); }
|
|
1391
1168
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, providedIn: 'root' }); }
|
|
1392
1169
|
}
|
|
@@ -1410,17 +1187,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1410
1187
|
}] }] });
|
|
1411
1188
|
|
|
1412
1189
|
class CheckoutService {
|
|
1413
|
-
constructor(couponService, checkoutRepository, userRepository, defaultShop
|
|
1190
|
+
constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
|
|
1414
1191
|
this.couponService = couponService;
|
|
1415
1192
|
this.checkoutRepository = checkoutRepository;
|
|
1193
|
+
this.orderRepository = orderRepository;
|
|
1416
1194
|
this.userRepository = userRepository;
|
|
1417
1195
|
this.defaultShop = defaultShop;
|
|
1418
|
-
this.dataPersistence = dataPersistence;
|
|
1419
1196
|
}
|
|
1420
1197
|
getCheckout(checkoutData) {
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1198
|
+
const checkoutId = cookie.get('checkoutId');
|
|
1199
|
+
if (!isNil(checkoutId))
|
|
1200
|
+
return from(this.checkoutRepository.get({ id: checkoutId }));
|
|
1201
|
+
return from(this.createCheckout(checkoutData));
|
|
1424
1202
|
}
|
|
1425
1203
|
getUserByCheckout(checkoutId) {
|
|
1426
1204
|
return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => checkout?.user?.id ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id }))), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
|
|
@@ -1432,7 +1210,8 @@ class CheckoutService {
|
|
|
1432
1210
|
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
|
|
1433
1211
|
}
|
|
1434
1212
|
clearCheckoutFromSession() {
|
|
1435
|
-
|
|
1213
|
+
cookie.remove('checkoutId');
|
|
1214
|
+
return of();
|
|
1436
1215
|
}
|
|
1437
1216
|
calcDiscount(coupon) {
|
|
1438
1217
|
return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
|
|
@@ -1446,10 +1225,10 @@ class CheckoutService {
|
|
|
1446
1225
|
...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
1447
1226
|
shop: checkoutData?.shop || this.defaultShop,
|
|
1448
1227
|
});
|
|
1449
|
-
|
|
1228
|
+
cookie.set('checkoutId', checkout.id);
|
|
1450
1229
|
return checkout;
|
|
1451
1230
|
}
|
|
1452
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: '
|
|
1231
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1453
1232
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService }); }
|
|
1454
1233
|
}
|
|
1455
1234
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, decorators: [{
|
|
@@ -1457,15 +1236,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1457
1236
|
}], ctorParameters: () => [{ type: CouponService }, { type: undefined, decorators: [{
|
|
1458
1237
|
type: Inject,
|
|
1459
1238
|
args: ['CheckoutRepository']
|
|
1239
|
+
}] }, { type: undefined, decorators: [{
|
|
1240
|
+
type: Inject,
|
|
1241
|
+
args: ['OrderRepository']
|
|
1460
1242
|
}] }, { type: undefined, decorators: [{
|
|
1461
1243
|
type: Inject,
|
|
1462
1244
|
args: ['UserRepository']
|
|
1463
1245
|
}] }, { type: i1$2.Shops, decorators: [{
|
|
1464
1246
|
type: Inject,
|
|
1465
1247
|
args: [DEFAULT_SHOP]
|
|
1466
|
-
}] }, { type: undefined, decorators: [{
|
|
1467
|
-
type: Inject,
|
|
1468
|
-
args: [PERSISTENCE_PROVIDER]
|
|
1469
1248
|
}] }] });
|
|
1470
1249
|
|
|
1471
1250
|
class CartService {
|
|
@@ -1481,11 +1260,9 @@ class CartService {
|
|
|
1481
1260
|
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
1482
1261
|
const items = [];
|
|
1483
1262
|
const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
1484
|
-
const isGift = checkoutLoaded.lineItems?.[index]?.isGift;
|
|
1485
1263
|
if (index > -1) {
|
|
1486
1264
|
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
1487
|
-
checkoutLoaded.lineItems[index].pricePaid =
|
|
1488
|
-
checkoutLoaded.lineItems[index].price = lineItem.price;
|
|
1265
|
+
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
1489
1266
|
}
|
|
1490
1267
|
else
|
|
1491
1268
|
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
@@ -1503,20 +1280,17 @@ class CartService {
|
|
|
1503
1280
|
this.buildLineItem = async ({ checkout, item, quantity, }) => {
|
|
1504
1281
|
const product = await this.getProductData(item.id);
|
|
1505
1282
|
item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
|
|
1506
|
-
if (this.checkMaxStock(
|
|
1507
|
-
throw new Error('Desculpe! Temos apenas ' +
|
|
1283
|
+
if (this.checkMaxStock(item, quantity || 0))
|
|
1284
|
+
throw new Error('Desculpe! Temos apenas ' + item.stock?.quantity + ' em estoque.');
|
|
1508
1285
|
const image = item.image || item.images?.shift();
|
|
1509
|
-
const { id, name, EAN, slug, weight, sku, type } = item;
|
|
1510
|
-
const isGift = item
|
|
1511
|
-
const pricePaid =
|
|
1512
|
-
|
|
1513
|
-
: this.
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
isSubscriber: checkout.user?.isSubscriber,
|
|
1517
|
-
});
|
|
1286
|
+
const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
|
|
1287
|
+
const isGift = item.isGift || null;
|
|
1288
|
+
const pricePaid = this.getProductPrice({
|
|
1289
|
+
product: item,
|
|
1290
|
+
shop: checkout.shop || this.defaultShop,
|
|
1291
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1292
|
+
});
|
|
1518
1293
|
RoundProductPricesHelper.roundProductPrices(item);
|
|
1519
|
-
RoundProductPricesHelper.roundProductPrices(product);
|
|
1520
1294
|
return {
|
|
1521
1295
|
checkout,
|
|
1522
1296
|
lineItem: LineItem.toInstance({
|
|
@@ -1526,19 +1300,16 @@ class CartService {
|
|
|
1526
1300
|
brand: product.brand,
|
|
1527
1301
|
slug: slug ?? product.slug,
|
|
1528
1302
|
sku: sku ?? product.sku,
|
|
1529
|
-
stock
|
|
1530
|
-
price: this.roundPrice(
|
|
1303
|
+
stock,
|
|
1304
|
+
price: this.roundPrice(price),
|
|
1531
1305
|
image,
|
|
1532
1306
|
weight: weight ?? product.weight,
|
|
1533
1307
|
quantity: (item.quantity || 0) + (quantity || 0),
|
|
1534
1308
|
pricePaid,
|
|
1535
|
-
|
|
1536
|
-
categories: product.categories || product.category?.id ? [product.category?.id, ...product.categories] : [],
|
|
1537
|
-
category: product.category,
|
|
1309
|
+
categories: product.categories ?? [],
|
|
1538
1310
|
isGift: isGift ?? null,
|
|
1539
|
-
costPrice:
|
|
1311
|
+
costPrice: product.costPrice ?? 0,
|
|
1540
1312
|
type,
|
|
1541
|
-
label: product.label,
|
|
1542
1313
|
}),
|
|
1543
1314
|
};
|
|
1544
1315
|
};
|
|
@@ -1550,10 +1321,10 @@ class CartService {
|
|
|
1550
1321
|
? Number(info.subscriberPrice.toFixed(2))
|
|
1551
1322
|
: Number(info.price.toFixed(2));
|
|
1552
1323
|
};
|
|
1553
|
-
this.checkMaxStock = (
|
|
1554
|
-
const maxStock =
|
|
1555
|
-
const currentItemAmount =
|
|
1556
|
-
return currentItemAmount +
|
|
1324
|
+
this.checkMaxStock = (item, quantity) => {
|
|
1325
|
+
const maxStock = item.stock?.quantity || 0;
|
|
1326
|
+
const currentItemAmount = item.quantity || 0;
|
|
1327
|
+
return currentItemAmount + quantity > maxStock;
|
|
1557
1328
|
};
|
|
1558
1329
|
}
|
|
1559
1330
|
addItem(item, quantity = 1) {
|
|
@@ -1586,14 +1357,14 @@ class CartService {
|
|
|
1586
1357
|
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1587
1358
|
}
|
|
1588
1359
|
updateUserCart(user) {
|
|
1589
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) =>
|
|
1360
|
+
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => this.checkoutService
|
|
1590
1361
|
.updateCheckoutLineItems(Checkout.toInstance({
|
|
1591
1362
|
...checkout.toPlain(),
|
|
1592
1363
|
lineItems: checkout.lineItems?.length
|
|
1593
1364
|
? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
|
|
1594
1365
|
: [],
|
|
1595
1366
|
}))
|
|
1596
|
-
.toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) =>
|
|
1367
|
+
.toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1597
1368
|
}
|
|
1598
1369
|
clearCart() {
|
|
1599
1370
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
@@ -1638,13 +1409,15 @@ class CartService {
|
|
|
1638
1409
|
const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
|
|
1639
1410
|
if (!notGiftItems.length)
|
|
1640
1411
|
return { ...checkout, lineItems: [] };
|
|
1412
|
+
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
1641
1413
|
const campaigns = await this.buy2WinRepository
|
|
1642
1414
|
.find({
|
|
1643
1415
|
filters: {
|
|
1644
1416
|
active: { operator: Where.EQUALS, value: true },
|
|
1417
|
+
shop: { operator: Where.EQUALS, value: this.defaultShop },
|
|
1645
1418
|
},
|
|
1646
1419
|
})
|
|
1647
|
-
.then((data) => data.data
|
|
1420
|
+
.then((data) => data.data);
|
|
1648
1421
|
if (!campaigns.length)
|
|
1649
1422
|
return { ...checkout, lineItems: notGiftItems };
|
|
1650
1423
|
const elegibleCampaigns = [];
|
|
@@ -1660,27 +1433,22 @@ class CartService {
|
|
|
1660
1433
|
categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
|
|
1661
1434
|
}
|
|
1662
1435
|
const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
|
|
1663
|
-
const filterProductsCategories =
|
|
1436
|
+
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
1664
1437
|
if (!l.categories || !l.categories?.length)
|
|
1665
1438
|
return true;
|
|
1666
1439
|
return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
|
|
1667
1440
|
});
|
|
1668
1441
|
if (filterProductsCategories.length) {
|
|
1669
|
-
const
|
|
1670
|
-
|
|
1671
|
-
const hasMinValue = campaign.cartValueMin && cartValuelWithCategories >= campaign.cartValueMin;
|
|
1672
|
-
const hasMinQuantity = campaign.cartItensQuantityMin && cartItensQuantityWithCategories >= campaign.cartItensQuantityMin;
|
|
1673
|
-
if (hasMinQuantity || hasMinValue)
|
|
1442
|
+
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
1443
|
+
if (cartTotalCategories >= campaign.cartValueMin)
|
|
1674
1444
|
elegibleCampaigns.push(campaign);
|
|
1675
1445
|
}
|
|
1676
1446
|
}
|
|
1677
1447
|
else {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
if (hasMinQuantity || hasMinValue)
|
|
1683
|
-
elegibleCampaigns.push(campaign);
|
|
1448
|
+
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
1449
|
+
if (campaign.cartValue <= cartTotal)
|
|
1450
|
+
elegibleCampaigns.push(campaign);
|
|
1451
|
+
}
|
|
1684
1452
|
}
|
|
1685
1453
|
}
|
|
1686
1454
|
if (!elegibleCampaigns.length)
|
|
@@ -1707,12 +1475,11 @@ class CartService {
|
|
|
1707
1475
|
}
|
|
1708
1476
|
giftToLineItems(items) {
|
|
1709
1477
|
return items.map((item) => {
|
|
1710
|
-
const { brand, categories,
|
|
1478
|
+
const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
1711
1479
|
const image = item?.miniatures?.length ? item.miniatures[0] : item.images[0];
|
|
1712
1480
|
return LineItem.toInstance({
|
|
1713
1481
|
brand,
|
|
1714
1482
|
categories,
|
|
1715
|
-
category,
|
|
1716
1483
|
id: id.toString(),
|
|
1717
1484
|
name,
|
|
1718
1485
|
price,
|
|
@@ -1774,11 +1541,9 @@ class NewCategoryStructureAdapter {
|
|
|
1774
1541
|
.then((categories) => categories.map((category) => category.id.toString()));
|
|
1775
1542
|
}
|
|
1776
1543
|
async getCategory(category) {
|
|
1777
|
-
|
|
1778
|
-
(
|
|
1779
|
-
category
|
|
1780
|
-
category.brandCategory;
|
|
1781
|
-
return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
|
|
1544
|
+
return isNil(category.isCollection) || (category.isCollection && !category.products?.length)
|
|
1545
|
+
? this.categoryRepository.get({ id: category.id })
|
|
1546
|
+
: category;
|
|
1782
1547
|
}
|
|
1783
1548
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1784
1549
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter }); }
|
|
@@ -1811,15 +1576,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
1811
1576
|
}] }] });
|
|
1812
1577
|
|
|
1813
1578
|
class CatalogService {
|
|
1814
|
-
constructor(productRepository,
|
|
1579
|
+
constructor(productRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
|
|
1815
1580
|
this.productRepository = productRepository;
|
|
1816
|
-
this.productStockNotificationRepository = productStockNotificationRepository;
|
|
1817
1581
|
this.categoryRepository = categoryRepository;
|
|
1818
1582
|
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
1819
1583
|
this.shop = shop;
|
|
1820
|
-
this.
|
|
1584
|
+
this.productIndex = productIndex;
|
|
1821
1585
|
this.productsByTerm = {};
|
|
1822
|
-
this.brandsList = {};
|
|
1823
1586
|
this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
|
|
1824
1587
|
const filters = {};
|
|
1825
1588
|
if (clubDiscount?.length)
|
|
@@ -1830,7 +1593,7 @@ class CatalogService {
|
|
|
1830
1593
|
filters.gender = { operator: Where.IN, value: gender };
|
|
1831
1594
|
if (prices?.min || prices?.max)
|
|
1832
1595
|
set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
|
|
1833
|
-
...(prices.min ? [{ operator: Where.GTE, value: Math.
|
|
1596
|
+
...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
|
|
1834
1597
|
...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
|
|
1835
1598
|
]);
|
|
1836
1599
|
if (rate)
|
|
@@ -1845,22 +1608,17 @@ class CatalogService {
|
|
|
1845
1608
|
if (!sort || sort === 'most-relevant')
|
|
1846
1609
|
return {};
|
|
1847
1610
|
if (sort === 'best-sellers')
|
|
1848
|
-
return {
|
|
1849
|
-
shoppingCount: 'desc',
|
|
1850
|
-
rate: 'desc',
|
|
1851
|
-
stock: 'desc',
|
|
1852
|
-
name: 'asc',
|
|
1853
|
-
};
|
|
1611
|
+
return { shoppingCount: 'desc' };
|
|
1854
1612
|
if (sort === 'biggest-price')
|
|
1855
|
-
return { subscriberPrice: 'desc'
|
|
1613
|
+
return { subscriberPrice: 'desc' };
|
|
1856
1614
|
if (sort === 'lowest-price')
|
|
1857
|
-
return { subscriberPrice: 'asc'
|
|
1615
|
+
return { subscriberPrice: 'asc' };
|
|
1858
1616
|
if (sort === 'best-rating')
|
|
1859
|
-
return { rate: 'desc'
|
|
1617
|
+
return { rate: 'desc' };
|
|
1860
1618
|
if (sort === 'news')
|
|
1861
1619
|
return { createdAt: 'desc' };
|
|
1862
1620
|
if (sort === 'biggest-discount')
|
|
1863
|
-
return { subscriberDiscountPercentage: 'desc'
|
|
1621
|
+
return { subscriberDiscountPercentage: 'desc' };
|
|
1864
1622
|
};
|
|
1865
1623
|
this.buildLimitQuery = (options) => {
|
|
1866
1624
|
const limit = options?.perPage || 20;
|
|
@@ -1872,15 +1630,6 @@ class CatalogService {
|
|
|
1872
1630
|
this.hasProfile = (options) => 'profile' in options;
|
|
1873
1631
|
this.hasTerm = (options) => 'term' in options;
|
|
1874
1632
|
this.hasCategory = (options) => 'category' in options;
|
|
1875
|
-
this.buildIndexBrands = (options) => {
|
|
1876
|
-
if (this.hasCategory(options))
|
|
1877
|
-
return `category-${options.category.id}`;
|
|
1878
|
-
if (this.hasTerm(options))
|
|
1879
|
-
return `term-${options.term}`;
|
|
1880
|
-
if (this.hasProfile(options))
|
|
1881
|
-
return `profile-${options.profile.join(',')}`;
|
|
1882
|
-
return '';
|
|
1883
|
-
};
|
|
1884
1633
|
}
|
|
1885
1634
|
async fetchProducts(options) {
|
|
1886
1635
|
const limits = this.buildLimitQuery(options);
|
|
@@ -1890,42 +1639,29 @@ class CatalogService {
|
|
|
1890
1639
|
throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
|
|
1891
1640
|
if (this.hasTerm(options) && options.filters?.customOptions)
|
|
1892
1641
|
throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
|
|
1893
|
-
return await this.findCatalog(options, limits).then(
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
min: +minimal?.price?.subscriberPrice?.toFixed(2),
|
|
1902
|
-
max: +maximum?.price?.subscriberPrice?.toFixed(2),
|
|
1903
|
-
},
|
|
1642
|
+
return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
|
|
1643
|
+
products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
|
|
1644
|
+
pages: Math.ceil(total / limits.limit),
|
|
1645
|
+
prices: {
|
|
1646
|
+
price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
|
|
1647
|
+
subscriberPrice: {
|
|
1648
|
+
min: +minimal?.price?.subscriberPrice?.toFixed(2),
|
|
1649
|
+
max: +maximum?.price?.subscriberPrice?.toFixed(2),
|
|
1904
1650
|
},
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
});
|
|
1908
|
-
}
|
|
1909
|
-
async addCustomerToStockNotification(shop, productId, name, email) {
|
|
1910
|
-
return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
|
|
1651
|
+
},
|
|
1652
|
+
brands: distinct?.brand,
|
|
1653
|
+
}));
|
|
1911
1654
|
}
|
|
1912
1655
|
async findCatalog(options, limits) {
|
|
1913
1656
|
if (this.hasTerm(options) && options.sort === 'most-relevant') {
|
|
1914
|
-
const productsIds = await this.
|
|
1915
|
-
return this.
|
|
1657
|
+
const productsIds = await this.findCatalogIdsByElasticSearch(options.term);
|
|
1658
|
+
return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
|
|
1916
1659
|
}
|
|
1917
1660
|
if (this.hasCategory(options) && options.sort === 'most-relevant') {
|
|
1918
|
-
const
|
|
1919
|
-
|
|
1920
|
-
.
|
|
1921
|
-
|
|
1922
|
-
filters: {
|
|
1923
|
-
...(await this.buildMainFilter(options)),
|
|
1924
|
-
...this.buildFilterQuery(options?.filters || {}),
|
|
1925
|
-
},
|
|
1926
|
-
})
|
|
1927
|
-
.then((products) => products.data.map((product) => product.id));
|
|
1928
|
-
return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
|
|
1661
|
+
const productsIds = options.category.products?.length
|
|
1662
|
+
? options.category.products
|
|
1663
|
+
: await this.categoryRepository.get({ id: options.category.id }).then((categoryFound) => categoryFound.products);
|
|
1664
|
+
return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
|
|
1929
1665
|
}
|
|
1930
1666
|
const repoParams = {
|
|
1931
1667
|
filters: {
|
|
@@ -1937,9 +1673,7 @@ class CatalogService {
|
|
|
1937
1673
|
options: {
|
|
1938
1674
|
minimal: ['price'],
|
|
1939
1675
|
maximum: ['price'],
|
|
1940
|
-
...(!this.
|
|
1941
|
-
? { distinct: ['brand'] }
|
|
1942
|
-
: {}),
|
|
1676
|
+
...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
|
|
1943
1677
|
},
|
|
1944
1678
|
};
|
|
1945
1679
|
if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
|
|
@@ -1952,72 +1686,27 @@ class CatalogService {
|
|
|
1952
1686
|
if (profile)
|
|
1953
1687
|
return { tags: { operator: Where.LIKE, value: profile } };
|
|
1954
1688
|
if (term)
|
|
1955
|
-
return this.
|
|
1956
|
-
.search(term, 999, this.shop
|
|
1957
|
-
.then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
|
|
1958
|
-
}
|
|
1959
|
-
async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
|
|
1960
|
-
const brandsList = this.brandsList[this.buildIndexBrands(options)];
|
|
1961
|
-
const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
|
|
1962
|
-
const totalResult = await this.productRepository.findCatalog({
|
|
1963
|
-
filters: {
|
|
1964
|
-
id: { operator: Where.IN, value: mostRelevantProductsIds },
|
|
1965
|
-
...this.buildFilterQuery(options?.filters || {}),
|
|
1966
|
-
},
|
|
1967
|
-
orderBy: this.buildSortQuery('best-sellers'),
|
|
1968
|
-
options: {
|
|
1969
|
-
minimal: ['price'],
|
|
1970
|
-
maximum: ['price'],
|
|
1971
|
-
...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
|
|
1972
|
-
},
|
|
1973
|
-
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1974
|
-
const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
|
|
1975
|
-
const firstProducts = totalResult.data
|
|
1976
|
-
.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
1977
|
-
.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
|
|
1978
|
-
const lastProducts = totalResult.data
|
|
1979
|
-
.filter((product) => !mostRelevants.includes(product.id))
|
|
1980
|
-
.concat(mostRelevantWithouyStock);
|
|
1981
|
-
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
1982
|
-
const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
|
|
1983
|
-
await this.setBrandsList(options, totalResult.distinct?.brand);
|
|
1984
|
-
return {
|
|
1985
|
-
data: resultFinal,
|
|
1986
|
-
count: totalResult.count,
|
|
1987
|
-
maximum: totalResult.maximum,
|
|
1988
|
-
minimal: totalResult.minimal,
|
|
1989
|
-
distinct: {
|
|
1990
|
-
...totalResult.distinct,
|
|
1991
|
-
brand: this.brandsList[this.buildIndexBrands(options)],
|
|
1992
|
-
},
|
|
1993
|
-
};
|
|
1689
|
+
return this.productIndex
|
|
1690
|
+
.search(term, 999, this.shop)
|
|
1691
|
+
.then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
|
|
1994
1692
|
}
|
|
1995
|
-
async
|
|
1996
|
-
const brandsList = this.brandsList[this.buildIndexBrands(options)];
|
|
1693
|
+
async findCatalogAndSortByMostRevelant(productIds, options, limits) {
|
|
1997
1694
|
const totalResult = await this.productRepository.findCatalog({
|
|
1998
|
-
fields: ['id', 'stock'
|
|
1695
|
+
fields: ['id', 'stock'],
|
|
1999
1696
|
filters: {
|
|
2000
1697
|
id: { operator: Where.IN, value: productIds },
|
|
2001
|
-
published: { operator: Where.EQUALS, value: true },
|
|
2002
1698
|
...this.buildFilterQuery(options?.filters || {}),
|
|
2003
1699
|
},
|
|
2004
1700
|
options: {
|
|
2005
1701
|
minimal: ['price'],
|
|
2006
1702
|
maximum: ['price'],
|
|
2007
|
-
|
|
1703
|
+
distinct: ['brand'],
|
|
2008
1704
|
},
|
|
2009
1705
|
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
2010
|
-
const defaultGender = options?.filters?.gender
|
|
2011
|
-
? options?.filters?.gender.at(0)
|
|
2012
|
-
: this.shop === Shops.GLAMSHOP
|
|
2013
|
-
? 'female'
|
|
2014
|
-
: 'male';
|
|
2015
1706
|
const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
|
|
2016
1707
|
const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
|
|
2017
|
-
const
|
|
2018
|
-
const
|
|
2019
|
-
const productIdsStock = productIdsStockGender.concat(productIdsStockNotGender);
|
|
2020
|
-
const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id === product));
|
|
1708
|
+
const productIdsStock = productIds.filter((product) => stockData.some((result) => result.id == product));
|
|
1709
|
+
const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id == product));
|
|
2021
1710
|
const limitedProductId = productIdsStock
|
|
2022
1711
|
.concat(productIdsStockOut)
|
|
2023
1712
|
.slice(limits.offset, limits.offset + limits.limit);
|
|
@@ -2027,55 +1716,27 @@ class CatalogService {
|
|
|
2027
1716
|
id: { operator: Where.IN, value: orderedId },
|
|
2028
1717
|
},
|
|
2029
1718
|
});
|
|
2030
|
-
await this.setBrandsList(options, totalResult.distinct?.brand);
|
|
2031
1719
|
return {
|
|
2032
1720
|
data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
|
|
2033
1721
|
count: totalResult.count,
|
|
2034
1722
|
maximum: totalResult.maximum,
|
|
2035
1723
|
minimal: totalResult.minimal,
|
|
2036
|
-
distinct:
|
|
2037
|
-
...totalResult.distinct,
|
|
2038
|
-
brand: this.brandsList[this.buildIndexBrands(options)],
|
|
2039
|
-
},
|
|
1724
|
+
distinct: totalResult.distinct,
|
|
2040
1725
|
};
|
|
2041
1726
|
}
|
|
2042
|
-
async
|
|
1727
|
+
async findCatalogIdsByElasticSearch(term) {
|
|
2043
1728
|
if (this.productsByTerm[term])
|
|
2044
1729
|
return this.productsByTerm[term];
|
|
2045
|
-
return (this.productsByTerm[term] = await this.
|
|
2046
|
-
.search(term, 999, this.shop
|
|
2047
|
-
.then((
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
.
|
|
2052
|
-
|
|
2053
|
-
filters: {
|
|
2054
|
-
...(!isEmpty(productIds) ? { id: { operator: Where.IN, value: productIds } } : {}),
|
|
2055
|
-
published: { operator: Where.EQUALS, value: true },
|
|
2056
|
-
...this.buildFilterQuery(options?.filters || {}),
|
|
2057
|
-
},
|
|
2058
|
-
options: {
|
|
2059
|
-
distinct: ['brand'],
|
|
2060
|
-
},
|
|
2061
|
-
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
|
|
2062
|
-
.then((result) => {
|
|
2063
|
-
return result.distinct.brand;
|
|
2064
|
-
});
|
|
2065
|
-
}
|
|
2066
|
-
async setBrandsList(options, brands) {
|
|
2067
|
-
const filterBrands = options.filters?.brands;
|
|
2068
|
-
if (isEmpty(brands))
|
|
2069
|
-
delete options.filters?.brands;
|
|
2070
|
-
this.brandsList[this.buildIndexBrands(options)] =
|
|
2071
|
-
this.brandsList[this.buildIndexBrands(options)] || brands || (await this.fetchBrandsOnly(options));
|
|
2072
|
-
this.brandsList[this.buildIndexBrands(options)] = this.brandsList[this.buildIndexBrands(options)].filter(Boolean);
|
|
2073
|
-
options.filters = {
|
|
2074
|
-
...options.filters,
|
|
2075
|
-
brands: filterBrands,
|
|
2076
|
-
};
|
|
1730
|
+
return (this.productsByTerm[term] = await this.productIndex
|
|
1731
|
+
.search(term, 999, this.shop)
|
|
1732
|
+
.then(({ hits: products }) => {
|
|
1733
|
+
const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
|
|
1734
|
+
const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
|
|
1735
|
+
const sorted = [...withStock, ...withOutStock];
|
|
1736
|
+
return [...new Set(sorted.map(({ _source }) => _source.id))];
|
|
1737
|
+
}));
|
|
2077
1738
|
}
|
|
2078
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: '
|
|
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: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2079
1740
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService }); }
|
|
2080
1741
|
}
|
|
2081
1742
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, decorators: [{
|
|
@@ -2083,9 +1744,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2083
1744
|
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
2084
1745
|
type: Inject,
|
|
2085
1746
|
args: ['ProductRepository']
|
|
2086
|
-
}] }, { type: undefined, decorators: [{
|
|
2087
|
-
type: Inject,
|
|
2088
|
-
args: ['ProductStockNotificationRepository']
|
|
2089
1747
|
}] }, { type: undefined, decorators: [{
|
|
2090
1748
|
type: Inject,
|
|
2091
1749
|
args: ['CategoryRepository']
|
|
@@ -2095,10 +1753,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2095
1753
|
}] }, { type: i1$2.Shops, decorators: [{
|
|
2096
1754
|
type: Inject,
|
|
2097
1755
|
args: [DEFAULT_SHOP]
|
|
2098
|
-
}] }, { type:
|
|
2099
|
-
type: Inject,
|
|
2100
|
-
args: ['ProductSearch']
|
|
2101
|
-
}] }] });
|
|
1756
|
+
}] }, { type: i1$2.ProductsIndex }] });
|
|
2102
1757
|
|
|
2103
1758
|
class CategoryService {
|
|
2104
1759
|
constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
|
|
@@ -2108,15 +1763,15 @@ class CategoryService {
|
|
|
2108
1763
|
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
2109
1764
|
this.shop = shop;
|
|
2110
1765
|
}
|
|
2111
|
-
async fetchBrands(category,
|
|
1766
|
+
async fetchBrands(category, mainGender) {
|
|
2112
1767
|
const brands = await this.productRepository
|
|
2113
1768
|
.findCatalog({
|
|
2114
1769
|
filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
|
|
2115
1770
|
fields: ['brand'],
|
|
2116
|
-
},
|
|
1771
|
+
}, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
|
|
2117
1772
|
.then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
|
|
2118
1773
|
return this.categoryRepository
|
|
2119
|
-
.find({ filters: { brandCategory: true, shop:
|
|
1774
|
+
.find({ filters: { brandCategory: true, shop: this.shop }, orderBy: { name: 'asc' } })
|
|
2120
1775
|
.then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
|
|
2121
1776
|
}
|
|
2122
1777
|
async fetchFilterOptions(category) {
|
|
@@ -2165,14 +1820,11 @@ __decorate([
|
|
|
2165
1820
|
], CategoryWithTree.prototype, "children", void 0);
|
|
2166
1821
|
|
|
2167
1822
|
class WishlistService {
|
|
2168
|
-
constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository,
|
|
1823
|
+
constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productIndex) {
|
|
2169
1824
|
this.wishlistRepository = wishlistRepository;
|
|
2170
1825
|
this.shop = shop;
|
|
2171
|
-
this.productRepository = productRepository;
|
|
2172
|
-
this.productSearch = productSearch;
|
|
2173
|
-
this.logRepository = logRepository;
|
|
2174
1826
|
const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
|
|
2175
|
-
this.catalogService = new CatalogService(productRepository,
|
|
1827
|
+
this.catalogService = new CatalogService(productRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
|
|
2176
1828
|
this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
|
|
2177
1829
|
}
|
|
2178
1830
|
getCatalogService() {
|
|
@@ -2181,76 +1833,46 @@ class WishlistService {
|
|
|
2181
1833
|
getCategoryService() {
|
|
2182
1834
|
return this.categoryService;
|
|
2183
1835
|
}
|
|
2184
|
-
async create({ personId, title, description,
|
|
1836
|
+
async create({ personId, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
|
|
2185
1837
|
const data = {
|
|
2186
1838
|
slug: '',
|
|
2187
1839
|
name: title,
|
|
2188
1840
|
description,
|
|
2189
|
-
|
|
2190
|
-
{
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
description: `${userFullName} - ${description}`,
|
|
2194
|
-
},
|
|
2195
|
-
],
|
|
1841
|
+
metadata: {
|
|
1842
|
+
title: `${userFullName} - ${title}`,
|
|
1843
|
+
description: `${userFullName} - ${description}`,
|
|
1844
|
+
},
|
|
2196
1845
|
shop: this.shop,
|
|
2197
1846
|
shops: [this.shop],
|
|
2198
1847
|
personId,
|
|
2199
1848
|
personName: userFullName,
|
|
2200
1849
|
personPhoto: userPhoto,
|
|
2201
1850
|
brandCategory: false,
|
|
2202
|
-
published,
|
|
1851
|
+
published: true,
|
|
2203
1852
|
theme,
|
|
2204
1853
|
bannerUrl,
|
|
2205
|
-
personType: personType ?? PersonTypes.NONE,
|
|
2206
|
-
personIsSubscriber: personIsSubscriber ?? false,
|
|
2207
1854
|
};
|
|
2208
|
-
const hasWishlist = await this.wishlistRepository
|
|
2209
|
-
.find({
|
|
2210
|
-
filters: {
|
|
2211
|
-
personId,
|
|
2212
|
-
},
|
|
2213
|
-
options: {
|
|
2214
|
-
enableCount: false,
|
|
2215
|
-
},
|
|
2216
|
-
orderBy: {
|
|
2217
|
-
id: 'asc',
|
|
2218
|
-
},
|
|
2219
|
-
})
|
|
2220
|
-
.then((res) => res.data);
|
|
2221
|
-
await this.createWishlistLog(WishlistLogType.CREATE, data);
|
|
2222
|
-
if (hasWishlist.length)
|
|
2223
|
-
return hasWishlist.at(0);
|
|
2224
1855
|
const newWishlist = await this.wishlistRepository.create(data);
|
|
2225
1856
|
await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
|
|
2226
1857
|
return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
|
|
2227
1858
|
}
|
|
2228
|
-
|
|
1859
|
+
update({ id, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
|
|
2229
1860
|
const data = {
|
|
2230
1861
|
id,
|
|
2231
1862
|
name: title,
|
|
2232
1863
|
description,
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
{
|
|
2236
|
-
|
|
2237
|
-
title: `${userFullName} - ${title}`,
|
|
2238
|
-
description: `${userFullName} - ${description}`,
|
|
2239
|
-
},
|
|
2240
|
-
],
|
|
1864
|
+
metadata: {
|
|
1865
|
+
title: `${userFullName} - ${title}`,
|
|
1866
|
+
description: `${userFullName} - ${description}`,
|
|
1867
|
+
},
|
|
2241
1868
|
personName: userFullName,
|
|
2242
1869
|
personPhoto: userPhoto,
|
|
2243
1870
|
theme,
|
|
2244
1871
|
bannerUrl,
|
|
2245
|
-
personType: personType ?? PersonTypes.NONE,
|
|
2246
|
-
personIsSubscriber: personIsSubscriber ?? false,
|
|
2247
1872
|
};
|
|
2248
|
-
await this.createWishlistLog(WishlistLogType.UPDATE, data);
|
|
2249
1873
|
return this.wishlistRepository.update(data);
|
|
2250
1874
|
}
|
|
2251
|
-
|
|
2252
|
-
const wishlist = await this.findById(wishlistId);
|
|
2253
|
-
await this.createWishlistLog(WishlistLogType.DELETE, wishlist);
|
|
1875
|
+
delete(wishlistId) {
|
|
2254
1876
|
return this.wishlistRepository.delete({ id: wishlistId });
|
|
2255
1877
|
}
|
|
2256
1878
|
getWishlistBySlug(slug) {
|
|
@@ -2265,12 +1887,9 @@ class WishlistService {
|
|
|
2265
1887
|
async addProduct(wishlistId, productId) {
|
|
2266
1888
|
const wishlist = await this.wishlistRepository.get({ id: wishlistId });
|
|
2267
1889
|
const hasProduct = wishlist.products.some((p) => p == productId);
|
|
2268
|
-
const wishlistData = await this.findById(wishlistId);
|
|
2269
|
-
const productData = await this.findProductById(productId);
|
|
2270
|
-
await this.createWishlistLog(WishlistLogType.ADD_PRODUCT, wishlistData, productData);
|
|
2271
1890
|
if (!hasProduct) {
|
|
2272
1891
|
wishlist.products = [...wishlist.products, productId];
|
|
2273
|
-
|
|
1892
|
+
return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
|
|
2274
1893
|
}
|
|
2275
1894
|
return wishlist;
|
|
2276
1895
|
}
|
|
@@ -2279,88 +1898,13 @@ class WishlistService {
|
|
|
2279
1898
|
const productIndex = wishlist.products.findIndex((p) => p == productId);
|
|
2280
1899
|
if (productIndex != -1) {
|
|
2281
1900
|
wishlist.products.splice(productIndex, 1);
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
await this.wishlistRepository.removeProduct(wishlistId, productId);
|
|
1901
|
+
if (!wishlist.products.length)
|
|
1902
|
+
return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
|
|
1903
|
+
return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
|
|
2286
1904
|
}
|
|
2287
1905
|
return wishlist;
|
|
2288
1906
|
}
|
|
2289
|
-
|
|
2290
|
-
return this.wishlistRepository
|
|
2291
|
-
.find({
|
|
2292
|
-
fields: ['id', 'name', 'description', 'personId', 'personIsSubscriber', 'personType', 'personName'],
|
|
2293
|
-
filters: {
|
|
2294
|
-
id,
|
|
2295
|
-
},
|
|
2296
|
-
})
|
|
2297
|
-
.then((res) => res.data.at(0));
|
|
2298
|
-
}
|
|
2299
|
-
async findProductById(id) {
|
|
2300
|
-
return this.productRepository
|
|
2301
|
-
.find({
|
|
2302
|
-
fields: ['id', 'sku', 'EAN', 'name', 'brand'],
|
|
2303
|
-
filters: {
|
|
2304
|
-
id,
|
|
2305
|
-
},
|
|
2306
|
-
})
|
|
2307
|
-
.then((res) => res.data.at(0));
|
|
2308
|
-
}
|
|
2309
|
-
async createWishlistLog(type, wishlist, product) {
|
|
2310
|
-
switch (type) {
|
|
2311
|
-
case WishlistLogType.CREATE:
|
|
2312
|
-
case WishlistLogType.UPDATE:
|
|
2313
|
-
case WishlistLogType.DELETE:
|
|
2314
|
-
await this.logRepository.create({
|
|
2315
|
-
collection: 'wishlist',
|
|
2316
|
-
date: new Date(),
|
|
2317
|
-
operation: WishlistLogType.CREATE ? 'CREATE' : WishlistLogType.UPDATE ? 'UPDATE' : 'DELETE',
|
|
2318
|
-
documentId: wishlist.id,
|
|
2319
|
-
document: {
|
|
2320
|
-
id: wishlist.id,
|
|
2321
|
-
shop: this.shop,
|
|
2322
|
-
name: wishlist.name,
|
|
2323
|
-
description: wishlist.description,
|
|
2324
|
-
published: wishlist.published,
|
|
2325
|
-
type: type,
|
|
2326
|
-
personType: wishlist.personType,
|
|
2327
|
-
personId: wishlist.personId,
|
|
2328
|
-
personName: wishlist.personName,
|
|
2329
|
-
personIsSubscriber: wishlist.personIsSubscriber,
|
|
2330
|
-
},
|
|
2331
|
-
});
|
|
2332
|
-
break;
|
|
2333
|
-
case WishlistLogType.ADD_PRODUCT:
|
|
2334
|
-
case WishlistLogType.REMOVE_PRODUCT:
|
|
2335
|
-
await this.logRepository.create({
|
|
2336
|
-
collection: 'wishlist',
|
|
2337
|
-
date: new Date(),
|
|
2338
|
-
operation: 'UPDATE',
|
|
2339
|
-
documentId: wishlist.id,
|
|
2340
|
-
document: {
|
|
2341
|
-
id: wishlist.id,
|
|
2342
|
-
shop: this.shop,
|
|
2343
|
-
name: wishlist.name,
|
|
2344
|
-
description: wishlist.description,
|
|
2345
|
-
published: wishlist.published,
|
|
2346
|
-
type: type,
|
|
2347
|
-
personType: wishlist.personType,
|
|
2348
|
-
personId: wishlist.personId,
|
|
2349
|
-
personName: wishlist.personName,
|
|
2350
|
-
personIsSubscriber: wishlist.personIsSubscriber,
|
|
2351
|
-
productId: product.id,
|
|
2352
|
-
productEAN: product.EAN,
|
|
2353
|
-
productSKU: product.sku,
|
|
2354
|
-
productName: product.name,
|
|
2355
|
-
productBrand: product.brand,
|
|
2356
|
-
},
|
|
2357
|
-
});
|
|
2358
|
-
break;
|
|
2359
|
-
default:
|
|
2360
|
-
break;
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
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 }); }
|
|
1907
|
+
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: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2364
1908
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService }); }
|
|
2365
1909
|
}
|
|
2366
1910
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, decorators: [{
|
|
@@ -2380,30 +1924,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2380
1924
|
}] }, { type: undefined, decorators: [{
|
|
2381
1925
|
type: Inject,
|
|
2382
1926
|
args: ['CategoryRepository']
|
|
2383
|
-
}] }, { type:
|
|
2384
|
-
type: Inject,
|
|
2385
|
-
args: ['ProductStockNotificationRepository']
|
|
2386
|
-
}] }, { type: undefined, decorators: [{
|
|
2387
|
-
type: Inject,
|
|
2388
|
-
args: ['ProductSearch']
|
|
2389
|
-
}] }, { type: undefined, decorators: [{
|
|
2390
|
-
type: Inject,
|
|
2391
|
-
args: ['LogRepository']
|
|
2392
|
-
}] }] });
|
|
1927
|
+
}] }, { type: i1$2.ProductsIndex }] });
|
|
2393
1928
|
|
|
2394
1929
|
class CheckoutSubscriptionService {
|
|
2395
|
-
constructor(checkoutSubscriptionRepository,
|
|
1930
|
+
constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
|
|
2396
1931
|
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
2397
|
-
this.
|
|
1932
|
+
this.subscriptionRepository = subscriptionRepository;
|
|
2398
1933
|
this.couponService = couponService;
|
|
2399
1934
|
}
|
|
2400
1935
|
getCheckoutSubscription(checkoutData) {
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
1936
|
+
const checkoutId = cookie.get('checkoutSubscriptionId');
|
|
1937
|
+
if (!isNil(checkoutId))
|
|
1938
|
+
return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
|
|
1939
|
+
return from(this.createCheckoutSubscription(checkoutData));
|
|
1940
|
+
}
|
|
1941
|
+
async createCheckoutSubscription(checkoutData) {
|
|
1942
|
+
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
1943
|
+
createdAt: new Date(),
|
|
1944
|
+
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
1945
|
+
});
|
|
1946
|
+
cookie.set('checkoutSubscriptionId', checkout.id);
|
|
1947
|
+
return checkout;
|
|
2404
1948
|
}
|
|
2405
1949
|
clearCheckoutSubscriptionFromSession() {
|
|
2406
|
-
|
|
1950
|
+
cookie.remove('checkoutSubscriptionId');
|
|
1951
|
+
return of();
|
|
2407
1952
|
}
|
|
2408
1953
|
checkCoupon(nickname, userEmail) {
|
|
2409
1954
|
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
@@ -2413,15 +1958,7 @@ class CheckoutSubscriptionService {
|
|
|
2413
1958
|
calcDiscountSubscription(coupon) {
|
|
2414
1959
|
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
2415
1960
|
}
|
|
2416
|
-
|
|
2417
|
-
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
2418
|
-
createdAt: new Date(),
|
|
2419
|
-
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
2420
|
-
});
|
|
2421
|
-
await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
|
|
2422
|
-
return checkout;
|
|
2423
|
-
}
|
|
2424
|
-
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 }); }
|
|
1961
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2425
1962
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService }); }
|
|
2426
1963
|
}
|
|
2427
1964
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
@@ -2431,7 +1968,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2431
1968
|
args: ['CheckoutSubscriptionRepository']
|
|
2432
1969
|
}] }, { type: undefined, decorators: [{
|
|
2433
1970
|
type: Inject,
|
|
2434
|
-
args: [
|
|
1971
|
+
args: ['SubscriptionRepository']
|
|
2435
1972
|
}] }, { type: CouponService }] });
|
|
2436
1973
|
|
|
2437
1974
|
class UtilHelper {
|
|
@@ -2516,10 +2053,10 @@ class HomeShopService {
|
|
|
2516
2053
|
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
2517
2054
|
}
|
|
2518
2055
|
getDiscoverProducts(gender) {
|
|
2519
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories,
|
|
2056
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
2520
2057
|
}
|
|
2521
2058
|
getFeaturedProducts(gender) {
|
|
2522
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories,
|
|
2059
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
2523
2060
|
}
|
|
2524
2061
|
getVerticalProducts(gender) {
|
|
2525
2062
|
return this.getHomeConfiguration().pipe(concatMap((home) => forkJoin(home.verticalCarousels.filter(Boolean).map((id) => from(this.categoryRepository.get({ id })).pipe(concatMap((category) => from(this.productRepository.find({
|
|
@@ -2683,19 +2220,16 @@ class AngularConnectModule {
|
|
|
2683
2220
|
return {
|
|
2684
2221
|
ngModule: AngularConnectModule,
|
|
2685
2222
|
providers: [
|
|
2686
|
-
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
2687
|
-
{ provide: APP_CHECK_PROVIDER, useValue: options.appCheckProvider },
|
|
2688
2223
|
{
|
|
2689
2224
|
provide: CATEGORY_STRUCTURE,
|
|
2690
2225
|
useClass: isNil(options?.oldCategoryStructure) || options?.oldCategoryStructure
|
|
2691
2226
|
? OldCategoryStructureAdapter
|
|
2692
2227
|
: NewCategoryStructureAdapter,
|
|
2693
2228
|
},
|
|
2694
|
-
{ provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
|
|
2695
2229
|
...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
|
|
2696
2230
|
...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
|
|
2231
|
+
...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
|
|
2697
2232
|
...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
|
|
2698
|
-
...(isNil(options?.vertexConfig) ? [] : [{ provide: VERTEX_CONFIG, useValue: options.vertexConfig }]),
|
|
2699
2233
|
...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
|
|
2700
2234
|
...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
|
|
2701
2235
|
...(isNil(options?.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
|
|
@@ -2703,8 +2237,7 @@ class AngularConnectModule {
|
|
|
2703
2237
|
};
|
|
2704
2238
|
}
|
|
2705
2239
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
2706
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule,
|
|
2707
|
-
AngularVertexSeachModule,
|
|
2240
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, AngularElasticSeachModule,
|
|
2708
2241
|
AngularFirebaseAuthModule,
|
|
2709
2242
|
AngularFirestoreModule,
|
|
2710
2243
|
AngularHasuraGraphQLModule] }); }
|
|
@@ -2727,49 +2260,16 @@ class AngularConnectModule {
|
|
|
2727
2260
|
},
|
|
2728
2261
|
deps: ['UserRepository', 'FileUploaderService'],
|
|
2729
2262
|
},
|
|
2730
|
-
{
|
|
2731
|
-
provide: 'FileUploaderService',
|
|
2732
|
-
useFactory: (storage, baseUrl) => {
|
|
2733
|
-
return new FirebaseFileUploaderService(storage, baseUrl);
|
|
2734
|
-
},
|
|
2735
|
-
deps: [Storage, STORAGE_BASE_URL],
|
|
2736
|
-
},
|
|
2737
|
-
{
|
|
2738
|
-
provide: 'ProductSearch',
|
|
2739
|
-
useExisting: ProductsVertexSearch,
|
|
2740
|
-
},
|
|
2741
2263
|
], imports: [provideFirebaseApp((injector) => {
|
|
2742
|
-
const appName = injector.get(FIREBASE_APP_NAME);
|
|
2264
|
+
const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
|
|
2743
2265
|
try {
|
|
2744
|
-
|
|
2745
|
-
return app;
|
|
2266
|
+
return getApp(appName);
|
|
2746
2267
|
}
|
|
2747
2268
|
catch (error) {
|
|
2748
|
-
console.warn('Firebase app not found, initializing new app');
|
|
2749
|
-
if (error instanceof Error)
|
|
2750
|
-
console.error(error.message);
|
|
2751
2269
|
return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
|
|
2752
2270
|
}
|
|
2753
2271
|
}),
|
|
2754
|
-
provideAppCheck((injector) => {
|
|
2755
|
-
const app = injector.get(FirebaseApp);
|
|
2756
|
-
try {
|
|
2757
|
-
const provider = injector.get(APP_CHECK_PROVIDER);
|
|
2758
|
-
if (provider)
|
|
2759
|
-
return initializeAppCheck(app, {
|
|
2760
|
-
provider,
|
|
2761
|
-
isTokenAutoRefreshEnabled: true,
|
|
2762
|
-
});
|
|
2763
|
-
}
|
|
2764
|
-
catch (error) {
|
|
2765
|
-
if (error instanceof Error)
|
|
2766
|
-
console.error(error.message);
|
|
2767
|
-
return;
|
|
2768
|
-
}
|
|
2769
|
-
}),
|
|
2770
|
-
provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
|
|
2771
2272
|
AngularElasticSeachModule,
|
|
2772
|
-
AngularVertexSeachModule,
|
|
2773
2273
|
AngularFirebaseAuthModule,
|
|
2774
2274
|
AngularFirestoreModule,
|
|
2775
2275
|
AngularHasuraGraphQLModule] }); }
|
|
@@ -2779,37 +2279,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2779
2279
|
args: [{
|
|
2780
2280
|
imports: [
|
|
2781
2281
|
provideFirebaseApp((injector) => {
|
|
2782
|
-
const appName = injector.get(FIREBASE_APP_NAME);
|
|
2282
|
+
const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
|
|
2783
2283
|
try {
|
|
2784
|
-
|
|
2785
|
-
return app;
|
|
2284
|
+
return getApp(appName);
|
|
2786
2285
|
}
|
|
2787
2286
|
catch (error) {
|
|
2788
|
-
console.warn('Firebase app not found, initializing new app');
|
|
2789
|
-
if (error instanceof Error)
|
|
2790
|
-
console.error(error.message);
|
|
2791
2287
|
return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
|
|
2792
2288
|
}
|
|
2793
2289
|
}),
|
|
2794
|
-
provideAppCheck((injector) => {
|
|
2795
|
-
const app = injector.get(FirebaseApp);
|
|
2796
|
-
try {
|
|
2797
|
-
const provider = injector.get(APP_CHECK_PROVIDER);
|
|
2798
|
-
if (provider)
|
|
2799
|
-
return initializeAppCheck(app, {
|
|
2800
|
-
provider,
|
|
2801
|
-
isTokenAutoRefreshEnabled: true,
|
|
2802
|
-
});
|
|
2803
|
-
}
|
|
2804
|
-
catch (error) {
|
|
2805
|
-
if (error instanceof Error)
|
|
2806
|
-
console.error(error.message);
|
|
2807
|
-
return;
|
|
2808
|
-
}
|
|
2809
|
-
}),
|
|
2810
|
-
provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
|
|
2811
2290
|
AngularElasticSeachModule,
|
|
2812
|
-
AngularVertexSeachModule,
|
|
2813
2291
|
AngularFirebaseAuthModule,
|
|
2814
2292
|
AngularFirestoreModule,
|
|
2815
2293
|
AngularHasuraGraphQLModule,
|
|
@@ -2833,17 +2311,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2833
2311
|
},
|
|
2834
2312
|
deps: ['UserRepository', 'FileUploaderService'],
|
|
2835
2313
|
},
|
|
2836
|
-
{
|
|
2837
|
-
provide: 'FileUploaderService',
|
|
2838
|
-
useFactory: (storage, baseUrl) => {
|
|
2839
|
-
return new FirebaseFileUploaderService(storage, baseUrl);
|
|
2840
|
-
},
|
|
2841
|
-
deps: [Storage, STORAGE_BASE_URL],
|
|
2842
|
-
},
|
|
2843
|
-
{
|
|
2844
|
-
provide: 'ProductSearch',
|
|
2845
|
-
useExisting: ProductsVertexSearch,
|
|
2846
|
-
},
|
|
2847
2314
|
],
|
|
2848
2315
|
}]
|
|
2849
2316
|
}] });
|
|
@@ -2852,5 +2319,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
|
|
|
2852
2319
|
* Generated bundle index. Do not edit.
|
|
2853
2320
|
*/
|
|
2854
2321
|
|
|
2855
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService,
|
|
2322
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
|
|
2856
2323
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|