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