@infrab4a/connect-angular 4.0.0-beta.27 → 4.0.0-beta.29
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/esm2020/angular-connect.module.mjs +6 -2
- package/esm2020/index.mjs +3 -3
- package/esm2020/services/catalog/catalog.service.mjs +26 -0
- package/esm2020/services/catalog/category.service.mjs +9 -0
- package/esm2020/services/catalog/enums/index.mjs +2 -0
- package/esm2020/services/catalog/enums/product-sorts.enum.mjs +10 -0
- package/esm2020/services/catalog/index.mjs +6 -0
- package/esm2020/services/catalog/models/category-with-tree.model.mjs +10 -0
- package/esm2020/services/catalog/models/index.mjs +2 -0
- package/esm2020/services/catalog/types/index.mjs +2 -0
- package/esm2020/services/catalog/types/product-sort.type.mjs +2 -0
- package/esm2020/services/index.mjs +2 -1
- package/fesm2015/infrab4a-connect-angular.mjs +1323 -1266
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +1569 -1511
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/index.d.ts +2 -2
- package/package.json +1 -1
- package/services/catalog/catalog.service.d.ts +16 -0
- package/services/catalog/category.service.d.ts +6 -0
- package/services/catalog/enums/index.d.ts +1 -0
- package/services/catalog/enums/product-sorts.enum.d.ts +8 -0
- package/services/catalog/index.d.ts +5 -0
- package/services/catalog/models/category-with-tree.model.d.ts +4 -0
- package/services/catalog/models/index.d.ts +1 -0
- package/services/catalog/types/index.d.ts +1 -0
- package/services/catalog/types/product-sort.type.d.ts +2 -0
- package/services/index.d.ts +1 -0
|
@@ -1,52 +1,23 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import * as i1 from '@angular/fire/auth';
|
|
4
|
-
import { getIdToken, authState, Auth, provideAuth, getAuth } from '@angular/fire/auth';
|
|
5
|
-
import { combineLatest, from, of, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
6
|
-
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
2
|
+
import { InjectionToken, NgModule, PLATFORM_ID, Injectable, Inject } from '@angular/core';
|
|
7
3
|
import * as i3 from '@infrab4a/connect';
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import { CustomError } from 'ts-custom-error';
|
|
11
|
-
import * as i1$1 from '@angular/fire/firestore';
|
|
12
|
-
import { docSnapshots, doc, Firestore, provideFirestore } from '@angular/fire/firestore';
|
|
13
|
-
import * as i1$2 from '@angular/common/http';
|
|
14
|
-
import * as i1$3 from '@angular/fire/app';
|
|
4
|
+
import { Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
|
|
5
|
+
import * as i1 from '@angular/fire/app';
|
|
15
6
|
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
7
|
+
import * as i1$1 from '@angular/fire/auth';
|
|
8
|
+
import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
16
9
|
import { isPlatformBrowser } from '@angular/common';
|
|
10
|
+
import * as i1$2 from '@angular/fire/firestore';
|
|
11
|
+
import { Firestore, provideFirestore, docSnapshots, doc } from '@angular/fire/firestore';
|
|
17
12
|
import { initializeApp as initializeApp$1 } from 'firebase/app';
|
|
18
13
|
import { getFirestore } from 'firebase/firestore';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const observables = [this.getFireUser(), this.getUser()];
|
|
27
|
-
return combineLatest(observables).pipe(map(([fireUser, user]) => ({
|
|
28
|
-
user,
|
|
29
|
-
isAnonymous: fireUser?.isAnonymous,
|
|
30
|
-
})));
|
|
31
|
-
}
|
|
32
|
-
getUser() {
|
|
33
|
-
return this.getFireUser().pipe(map((user) => user?.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
|
|
34
|
-
}
|
|
35
|
-
getTokenId() {
|
|
36
|
-
return from(getIdToken(this.angularFireAuth.currentUser));
|
|
37
|
-
}
|
|
38
|
-
getFireUser() {
|
|
39
|
-
return authState(this.angularFireAuth).pipe(catchError(() => of(null)));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
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 });
|
|
43
|
-
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService });
|
|
44
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, decorators: [{
|
|
45
|
-
type: Injectable
|
|
46
|
-
}], ctorParameters: function () { return [{ type: i1.Auth }, { type: undefined, decorators: [{
|
|
47
|
-
type: Inject,
|
|
48
|
-
args: ['UserRepository']
|
|
49
|
-
}] }]; } });
|
|
14
|
+
import { combineLatest, from, of, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
15
|
+
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
16
|
+
import cookie from 'js-cookie';
|
|
17
|
+
import { CustomError } from 'ts-custom-error';
|
|
18
|
+
import { __decorate, __metadata } from 'tslib';
|
|
19
|
+
import { Type } from 'class-transformer';
|
|
20
|
+
import * as i1$3 from '@angular/common/http';
|
|
50
21
|
|
|
51
22
|
const BACKEND_URL = 'BACKEND_URL';
|
|
52
23
|
|
|
@@ -59,985 +30,609 @@ const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
|
|
|
59
30
|
|
|
60
31
|
const HASURA_OPTIONS = 'HASURA_OPTIONS';
|
|
61
32
|
|
|
62
|
-
class
|
|
63
|
-
|
|
64
|
-
|
|
33
|
+
class AngularFirebaseAuthModule {
|
|
34
|
+
static initializeApp(options, nameOrConfig) {
|
|
35
|
+
return {
|
|
36
|
+
ngModule: AngularFirebaseAuthModule,
|
|
37
|
+
providers: [
|
|
38
|
+
{ provide: FIREBASE_OPTIONS, useValue: options },
|
|
39
|
+
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
40
|
+
],
|
|
41
|
+
};
|
|
65
42
|
}
|
|
66
43
|
}
|
|
44
|
+
AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
45
|
+
AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1.FirebaseAppModule, i1$1.AuthModule] });
|
|
46
|
+
AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
|
|
47
|
+
{
|
|
48
|
+
provide: 'Authentication',
|
|
49
|
+
useFactory: (authenticationService, userRepository) => {
|
|
50
|
+
return new Authentication(authenticationService, userRepository);
|
|
51
|
+
},
|
|
52
|
+
deps: ['AuthenticationService', 'UserRepository'],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
provide: 'AuthenticationService',
|
|
56
|
+
useFactory: (angularFireAuth) => {
|
|
57
|
+
return new AuthenticationFirebaseAuthService(angularFireAuth);
|
|
58
|
+
},
|
|
59
|
+
deps: [Auth],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
provide: 'Register',
|
|
63
|
+
useFactory: (registerService, userRepository) => {
|
|
64
|
+
return new Register(registerService, userRepository);
|
|
65
|
+
},
|
|
66
|
+
deps: ['RegisterService', 'UserRepository'],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
provide: 'RegisterService',
|
|
70
|
+
useFactory: (angularFireAuth) => {
|
|
71
|
+
return new RegisterFirebaseAuthService(angularFireAuth);
|
|
72
|
+
},
|
|
73
|
+
deps: [Auth],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
provide: 'SignOut',
|
|
77
|
+
useFactory: (authenticationService) => {
|
|
78
|
+
return new SignOut(authenticationService);
|
|
79
|
+
},
|
|
80
|
+
deps: ['AuthenticationService'],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
provide: 'RecoveryPassword',
|
|
84
|
+
useFactory: (authenticationService) => {
|
|
85
|
+
return new RecoveryPassword(authenticationService);
|
|
86
|
+
},
|
|
87
|
+
deps: ['AuthenticationService'],
|
|
88
|
+
},
|
|
89
|
+
], imports: [provideFirebaseApp((injector) => {
|
|
90
|
+
const appName = injector.get(FIREBASE_APP_NAME);
|
|
91
|
+
return appName
|
|
92
|
+
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
93
|
+
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
94
|
+
}),
|
|
95
|
+
provideAuth(() => getAuth())] });
|
|
96
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
|
|
97
|
+
type: NgModule,
|
|
98
|
+
args: [{
|
|
99
|
+
imports: [
|
|
100
|
+
provideFirebaseApp((injector) => {
|
|
101
|
+
const appName = injector.get(FIREBASE_APP_NAME);
|
|
102
|
+
return appName
|
|
103
|
+
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
104
|
+
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
105
|
+
}),
|
|
106
|
+
provideAuth(() => getAuth()),
|
|
107
|
+
],
|
|
108
|
+
providers: [
|
|
109
|
+
{
|
|
110
|
+
provide: 'Authentication',
|
|
111
|
+
useFactory: (authenticationService, userRepository) => {
|
|
112
|
+
return new Authentication(authenticationService, userRepository);
|
|
113
|
+
},
|
|
114
|
+
deps: ['AuthenticationService', 'UserRepository'],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
provide: 'AuthenticationService',
|
|
118
|
+
useFactory: (angularFireAuth) => {
|
|
119
|
+
return new AuthenticationFirebaseAuthService(angularFireAuth);
|
|
120
|
+
},
|
|
121
|
+
deps: [Auth],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
provide: 'Register',
|
|
125
|
+
useFactory: (registerService, userRepository) => {
|
|
126
|
+
return new Register(registerService, userRepository);
|
|
127
|
+
},
|
|
128
|
+
deps: ['RegisterService', 'UserRepository'],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
provide: 'RegisterService',
|
|
132
|
+
useFactory: (angularFireAuth) => {
|
|
133
|
+
return new RegisterFirebaseAuthService(angularFireAuth);
|
|
134
|
+
},
|
|
135
|
+
deps: [Auth],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
provide: 'SignOut',
|
|
139
|
+
useFactory: (authenticationService) => {
|
|
140
|
+
return new SignOut(authenticationService);
|
|
141
|
+
},
|
|
142
|
+
deps: ['AuthenticationService'],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
provide: 'RecoveryPassword',
|
|
146
|
+
useFactory: (authenticationService) => {
|
|
147
|
+
return new RecoveryPassword(authenticationService);
|
|
148
|
+
},
|
|
149
|
+
deps: ['AuthenticationService'],
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
}]
|
|
153
|
+
}] });
|
|
67
154
|
|
|
68
|
-
class
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
155
|
+
class AngularElasticSeachModule {
|
|
156
|
+
static initializeApp(options) {
|
|
157
|
+
return {
|
|
158
|
+
ngModule: AngularElasticSeachModule,
|
|
159
|
+
providers: [{ provide: ES_CONFIG, useValue: options }],
|
|
160
|
+
};
|
|
72
161
|
}
|
|
73
162
|
}
|
|
163
|
+
AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
164
|
+
AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule });
|
|
165
|
+
AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
|
|
166
|
+
{
|
|
167
|
+
provide: ProductsIndex,
|
|
168
|
+
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
169
|
+
deps: [ES_CONFIG],
|
|
170
|
+
},
|
|
171
|
+
] });
|
|
172
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
|
|
173
|
+
type: NgModule,
|
|
174
|
+
args: [{
|
|
175
|
+
providers: [
|
|
176
|
+
{
|
|
177
|
+
provide: ProductsIndex,
|
|
178
|
+
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
179
|
+
deps: [ES_CONFIG],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
}]
|
|
183
|
+
}] });
|
|
74
184
|
|
|
75
|
-
class
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
185
|
+
class AngularFirestoreModule {
|
|
186
|
+
static initializeApp(options, nameOrConfig) {
|
|
187
|
+
return {
|
|
188
|
+
ngModule: AngularFirestoreModule,
|
|
189
|
+
providers: [
|
|
190
|
+
{ provide: FIREBASE_OPTIONS, useValue: options.firebase },
|
|
191
|
+
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
192
|
+
{ provide: ES_CONFIG, useValue: options.elasticSearch },
|
|
193
|
+
],
|
|
194
|
+
};
|
|
82
195
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
196
|
+
}
|
|
197
|
+
AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
198
|
+
AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1.FirebaseAppModule, i1$2.FirestoreModule] });
|
|
199
|
+
AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, providers: [
|
|
200
|
+
{
|
|
201
|
+
provide: 'FirestoreOptions',
|
|
202
|
+
useFactory: (firestore, platformId) => ({
|
|
203
|
+
firestore,
|
|
204
|
+
interceptors: {
|
|
205
|
+
request: (request) => {
|
|
206
|
+
if (isPlatformBrowser(platformId))
|
|
207
|
+
return request;
|
|
208
|
+
const interval = setInterval(() => { }, 100);
|
|
209
|
+
request.interval = interval;
|
|
210
|
+
return request;
|
|
211
|
+
},
|
|
212
|
+
response: (response, request) => {
|
|
213
|
+
if (isPlatformBrowser(platformId))
|
|
214
|
+
return response;
|
|
215
|
+
clearInterval(request.interval);
|
|
216
|
+
return response;
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
}),
|
|
220
|
+
deps: [Firestore, PLATFORM_ID],
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
provide: 'BeautyProfileRepository',
|
|
224
|
+
useFactory: (config, userRepository) => {
|
|
225
|
+
return new UserBeautyProfileFirestoreRepository(config, userRepository);
|
|
88
226
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
// Get Primeiro Cupom (o find do repository retorna um array)
|
|
97
|
-
const coupon = coupons.data.shift();
|
|
98
|
-
// Verifica se o cupom é aplicavel na loja
|
|
99
|
-
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
100
|
-
// Cupon não aplicavel a loja retorna erro
|
|
101
|
-
if (!isInShop)
|
|
102
|
-
return throwError('Cupom inválido para loja.');
|
|
103
|
-
// Verifica se o coupon é aplicado no checkout que está sendo realizado
|
|
104
|
-
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
105
|
-
// Cupon não aplicavel ao checkout retorna erro
|
|
106
|
-
if (!isCheckoutType)
|
|
107
|
-
return throwError('Cupom inválido. Erro de checkout.');
|
|
108
|
-
// Verifica se o cupom é ou pode ser aplicado para subscription
|
|
109
|
-
if (checkoutType === CheckoutTypes.ALL || checkoutType === CheckoutTypes.SUBSCRIPTION) {
|
|
110
|
-
// Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
|
|
111
|
-
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
112
|
-
return throwError('Cupom inválido para sua assinatura.');
|
|
113
|
-
}
|
|
114
|
-
if (isSubscription)
|
|
115
|
-
return of(coupon);
|
|
116
|
-
// Verifica se possui o valor minimo de compra para utilização do cupom
|
|
117
|
-
const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
|
|
118
|
-
// Se não tem valor mínimo atingido, retorna erro
|
|
119
|
-
if (!hasMinSubTotal)
|
|
120
|
-
return throwError(`Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`);
|
|
121
|
-
return of(coupon);
|
|
122
|
-
}
|
|
123
|
-
isValidCoupon(coupon, userEmail) {
|
|
124
|
-
// Verifica a data de inicio de validade do cupom
|
|
125
|
-
if (coupon?.beginAt > new Date())
|
|
126
|
-
throw new InvalidCouponError('Cupom ainda não liberado.');
|
|
127
|
-
// Verifica a data de validade do cupom
|
|
128
|
-
if (coupon?.expiresIn < new Date())
|
|
129
|
-
throw new InvalidCouponError('Cupom expirado.');
|
|
130
|
-
return coupon;
|
|
131
|
-
}
|
|
132
|
-
async checkCouponUseAndLimit(coupon, userEmail, checkout) {
|
|
133
|
-
const orders = await this.orderRepository.find({
|
|
134
|
-
filters: {
|
|
135
|
-
coupon: { id: coupon.id },
|
|
136
|
-
payment: { status: 'paid' },
|
|
137
|
-
...(coupon.influencerEmail ? { user: { email: userEmail } } : {}),
|
|
227
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
provide: 'Buy2WinRepository',
|
|
231
|
+
useFactory: (options) => {
|
|
232
|
+
return new Buy2WinFirestoreRepository(options);
|
|
138
233
|
},
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const ordersUserCoupon = orders.data.filter((o) => o.user.email == userEmail);
|
|
142
|
-
// Verifica o limite de uso de cupom por usuario
|
|
143
|
-
if (coupon.useLimitPerUser && ordersUserCoupon.length)
|
|
144
|
-
throw new InvalidCouponError('Limite de uso por usuário atingido.');
|
|
145
|
-
// Verifica o limite de uso geral por usuario
|
|
146
|
-
if (coupon.useLimit && orders.data.length >= coupon.useLimit)
|
|
147
|
-
throw new InvalidCouponError('Limite de uso atingido.');
|
|
148
|
-
const validUser = this.userValidationAndSubscriptionStatus(coupon, checkout?.user);
|
|
149
|
-
if (!validUser)
|
|
150
|
-
throw new InvalidCouponError('Usuário não elegível.');
|
|
151
|
-
const hasProductCategories = await this.hasProductCategories(coupon, checkout);
|
|
152
|
-
if (!hasProductCategories)
|
|
153
|
-
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
154
|
-
return coupon;
|
|
155
|
-
}
|
|
156
|
-
calcDiscountSubscription(coupon, checkout) {
|
|
157
|
-
//
|
|
158
|
-
let discount = 0;
|
|
159
|
-
if (coupon.type === CouponTypes.ABSOLUTE)
|
|
160
|
-
discount = coupon.discount;
|
|
161
|
-
else if (coupon.type === CouponTypes.PERCENTAGE)
|
|
162
|
-
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount / 100);
|
|
163
|
-
return of(discount);
|
|
164
|
-
}
|
|
165
|
-
async calcDiscountShopping(coupon, checkout) {
|
|
166
|
-
let discount = 0;
|
|
167
|
-
switch (coupon.type) {
|
|
168
|
-
case CouponTypes.ABSOLUTE: {
|
|
169
|
-
discount = coupon.discount;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case CouponTypes.PERCENTAGE: {
|
|
173
|
-
discount = await this.calcShoppingPercentageDiscount(coupon, checkout);
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return discount;
|
|
178
|
-
}
|
|
179
|
-
async calcShoppingPercentageDiscount(coupon, checkout) {
|
|
180
|
-
let discount = 0;
|
|
181
|
-
const shop = checkout.shop;
|
|
182
|
-
let lineItensDiscount = [];
|
|
183
|
-
const couponCategories = await this.getCouponCategoriesId(coupon);
|
|
184
|
-
if (coupon.productsCategories && coupon.productsCategories.length) {
|
|
185
|
-
lineItensDiscount = checkout.lineItems?.filter((i) => {
|
|
186
|
-
if (i.categories?.length) {
|
|
187
|
-
return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
|
|
188
|
-
}
|
|
189
|
-
return true;
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
lineItensDiscount = checkout.lineItems;
|
|
194
|
-
}
|
|
195
|
-
const subTotal = lineItensDiscount.reduce((acc, curr) => checkout.user?.isSubscriber && curr.price?.subscriberPrice
|
|
196
|
-
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
197
|
-
: acc + curr.pricePaid * curr.quantity, 0) || 0;
|
|
198
|
-
discount = subTotal * (coupon.discount / 100);
|
|
199
|
-
return discount;
|
|
200
|
-
}
|
|
201
|
-
hasMinSubTotal(coupon, checkout) {
|
|
202
|
-
if (!coupon.minSubTotalValue)
|
|
203
|
-
return true;
|
|
204
|
-
const shop = checkout.shop;
|
|
205
|
-
let subTotal = checkout.lineItems?.reduce((acc, curr) => checkout.user?.isSubscriber && curr.price?.subscriberPrice
|
|
206
|
-
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
207
|
-
: acc + curr.pricePaid * curr.quantity, 0) || 0;
|
|
208
|
-
if (coupon.minSubTotalValue <= subTotal)
|
|
209
|
-
return true;
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
async hasProductCategories(coupon, checkout) {
|
|
213
|
-
if (!coupon.productsCategories || !coupon.productsCategories.length) {
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
const couponCategories = await this.getCouponCategoriesId(coupon);
|
|
217
|
-
const hasCategories = checkout.lineItems?.filter((i) => {
|
|
218
|
-
if (!i.categories || !i.categories?.length)
|
|
219
|
-
return true;
|
|
220
|
-
return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
|
|
221
|
-
});
|
|
222
|
-
return hasCategories.length ? true : false;
|
|
223
|
-
}
|
|
224
|
-
userValidationAndSubscriptionStatus(coupon, user) {
|
|
225
|
-
if (coupon.exclusivityType === Exclusivities.ALL_USERS)
|
|
226
|
-
return true;
|
|
227
|
-
if (!user)
|
|
228
|
-
return true;
|
|
229
|
-
// Verifica se o email do usuário é coorporativo
|
|
230
|
-
if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
|
|
231
|
-
throw new InvalidCouponError('Você não é colaborador.');
|
|
232
|
-
// Verifica se o email do usuário é associado ao cupom de uso por usuario
|
|
233
|
-
if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== user.email)
|
|
234
|
-
throw new InvalidCouponError('Cupom não é válido para este usuário.');
|
|
235
|
-
switch (coupon.exclusivityType) {
|
|
236
|
-
case Exclusivities.ACTIVE_SUBSCRIBER:
|
|
237
|
-
return user.isSubscriber ? true : false;
|
|
238
|
-
case Exclusivities.INACTIVE_SUBSCRIBER:
|
|
239
|
-
return user.isSubscriber ? false : true;
|
|
240
|
-
case Exclusivities.NON_SUBSCRIBER:
|
|
241
|
-
return user.isSubscriber ? false : true;
|
|
242
|
-
}
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
async getCouponCategoriesId(coupon) {
|
|
246
|
-
let couponCategories = [];
|
|
247
|
-
for (let index = 0; index < coupon.productsCategories.length; index++) {
|
|
248
|
-
let c = await this.categoryRepository.get({
|
|
249
|
-
id: coupon.productsCategories[index],
|
|
250
|
-
});
|
|
251
|
-
couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
|
|
252
|
-
}
|
|
253
|
-
return couponCategories;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
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 });
|
|
257
|
-
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
258
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
259
|
-
type: Injectable,
|
|
260
|
-
args: [{
|
|
261
|
-
providedIn: 'root',
|
|
262
|
-
}]
|
|
263
|
-
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
264
|
-
type: Inject,
|
|
265
|
-
args: ['CouponRepository']
|
|
266
|
-
}] }, { type: i3.Shops, decorators: [{
|
|
267
|
-
type: Inject,
|
|
268
|
-
args: [DEFAULT_SHOP]
|
|
269
|
-
}] }, { type: undefined, decorators: [{
|
|
270
|
-
type: Inject,
|
|
271
|
-
args: ['OrderRepository']
|
|
272
|
-
}] }, { type: undefined, decorators: [{
|
|
273
|
-
type: Inject,
|
|
274
|
-
args: ['CategoryRepository']
|
|
275
|
-
}] }]; } });
|
|
276
|
-
|
|
277
|
-
class CheckoutService {
|
|
278
|
-
constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
|
|
279
|
-
this.couponService = couponService;
|
|
280
|
-
this.checkoutRepository = checkoutRepository;
|
|
281
|
-
this.orderRepository = orderRepository;
|
|
282
|
-
this.userRepository = userRepository;
|
|
283
|
-
this.defaultShop = defaultShop;
|
|
284
|
-
}
|
|
285
|
-
getCheckout(checkoutData) {
|
|
286
|
-
const checkoutId = cookie.get('checkoutId');
|
|
287
|
-
if (!isNil(checkoutId))
|
|
288
|
-
return from(this.checkoutRepository.get({ id: checkoutId }));
|
|
289
|
-
return from(this.createCheckout(checkoutData));
|
|
290
|
-
}
|
|
291
|
-
getUserByCheckout(checkoutId) {
|
|
292
|
-
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'))));
|
|
293
|
-
}
|
|
294
|
-
updateCheckoutLineItems(checkout) {
|
|
295
|
-
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
|
|
296
|
-
}
|
|
297
|
-
updateCheckoutUser(checkout) {
|
|
298
|
-
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
|
|
299
|
-
}
|
|
300
|
-
clearCheckoutFromSession() {
|
|
301
|
-
cookie.remove('checkoutId');
|
|
302
|
-
return of();
|
|
303
|
-
}
|
|
304
|
-
calcDiscount(coupon) {
|
|
305
|
-
return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
|
|
306
|
-
}
|
|
307
|
-
checkCoupon(nickname, checkoutType) {
|
|
308
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.couponService
|
|
309
|
-
.checkCoupon(nickname, checkout.user?.email, CheckoutTypes.ECOMMERCE, checkout.user.subscriptionPlan, checkout, false)
|
|
310
|
-
.pipe()));
|
|
311
|
-
}
|
|
312
|
-
async createCheckout(checkoutData) {
|
|
313
|
-
const checkout = await this.checkoutRepository.create({
|
|
314
|
-
createdAt: new Date(),
|
|
315
|
-
...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
316
|
-
shop: checkoutData?.shop || this.defaultShop,
|
|
317
|
-
});
|
|
318
|
-
cookie.set('checkoutId', checkout.id);
|
|
319
|
-
return checkout;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
323
|
-
CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
|
|
324
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
|
|
325
|
-
type: Injectable
|
|
326
|
-
}], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
|
|
327
|
-
type: Inject,
|
|
328
|
-
args: ['CheckoutRepository']
|
|
329
|
-
}] }, { type: undefined, decorators: [{
|
|
330
|
-
type: Inject,
|
|
331
|
-
args: ['OrderRepository']
|
|
332
|
-
}] }, { type: undefined, decorators: [{
|
|
333
|
-
type: Inject,
|
|
334
|
-
args: ['UserRepository']
|
|
335
|
-
}] }, { type: i3.Shops, decorators: [{
|
|
336
|
-
type: Inject,
|
|
337
|
-
args: [DEFAULT_SHOP]
|
|
338
|
-
}] }]; } });
|
|
339
|
-
|
|
340
|
-
class CartService {
|
|
341
|
-
constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
|
|
342
|
-
this.authService = authService;
|
|
343
|
-
this.checkoutService = checkoutService;
|
|
344
|
-
this.defaultShop = defaultShop;
|
|
345
|
-
this.productRepository = productRepository;
|
|
346
|
-
this.categoryRepository = categoryRepository;
|
|
347
|
-
this.variantRepository = variantRepository;
|
|
348
|
-
this.buy2WinRepository = buy2WinRepository;
|
|
349
|
-
this.cartSubject = new Subject();
|
|
350
|
-
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
351
|
-
const items = [];
|
|
352
|
-
const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
353
|
-
if (index > -1) {
|
|
354
|
-
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
355
|
-
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
356
|
-
}
|
|
357
|
-
else
|
|
358
|
-
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
359
|
-
return this.checkoutService
|
|
360
|
-
.updateCheckoutLineItems(checkoutLoaded)
|
|
361
|
-
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
362
|
-
}));
|
|
363
|
-
this.generateCartObject = (items) => items?.reduce((cart, item) => ({
|
|
364
|
-
...cart,
|
|
365
|
-
[item.id]: LineItem.toInstance({
|
|
366
|
-
...(cart[item.id] || item),
|
|
367
|
-
quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
|
|
368
|
-
}),
|
|
369
|
-
}), {}) || {};
|
|
370
|
-
this.buildLineItem = async ({ checkout, item, quantity, }) => {
|
|
371
|
-
const product = await this.getProductData(item.id);
|
|
372
|
-
item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
|
|
373
|
-
if (this.checkMaxStock(item, quantity || 0))
|
|
374
|
-
throw new Error('Desculpe! Temos apenas ' + item.stock?.quantity + ' em estoque.');
|
|
375
|
-
const image = item.image || item.images?.shift();
|
|
376
|
-
const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
|
|
377
|
-
const isGift = item.isGift || null;
|
|
378
|
-
const pricePaid = this.getProductPrice({
|
|
379
|
-
product: item,
|
|
380
|
-
shop: checkout.shop || this.defaultShop,
|
|
381
|
-
isSubscriber: checkout.user?.isSubscriber,
|
|
382
|
-
});
|
|
383
|
-
RoundProductPricesHelper.roundProductPrices(item);
|
|
384
|
-
return {
|
|
385
|
-
checkout,
|
|
386
|
-
lineItem: LineItem.toInstance({
|
|
387
|
-
id,
|
|
388
|
-
name: name ?? product.name,
|
|
389
|
-
EAN: EAN ?? product.EAN,
|
|
390
|
-
brand: product.brand,
|
|
391
|
-
slug: slug ?? product.slug,
|
|
392
|
-
sku: sku ?? product.sku,
|
|
393
|
-
stock,
|
|
394
|
-
price: this.roundPrice(price),
|
|
395
|
-
image,
|
|
396
|
-
weight: weight ?? product.weight,
|
|
397
|
-
quantity: (item.quantity || 0) + (quantity || 0),
|
|
398
|
-
pricePaid,
|
|
399
|
-
categories: product.categories ?? [],
|
|
400
|
-
isGift: isGift ?? null,
|
|
401
|
-
costPrice: product.costPrice ?? 0,
|
|
402
|
-
type,
|
|
403
|
-
}),
|
|
404
|
-
};
|
|
405
|
-
};
|
|
406
|
-
this.getProductPrice = ({ product, isSubscriber, }) => {
|
|
407
|
-
const info = product.price;
|
|
408
|
-
if (product.isGift)
|
|
409
|
-
return 0;
|
|
410
|
-
return isSubscriber && info.subscriberPrice > 0
|
|
411
|
-
? Number(info.subscriberPrice.toFixed(2))
|
|
412
|
-
: Number(info.price.toFixed(2));
|
|
413
|
-
};
|
|
414
|
-
this.checkMaxStock = (item, quantity) => {
|
|
415
|
-
const maxStock = item.stock?.quantity || 0;
|
|
416
|
-
const currentItemAmount = item.quantity || 0;
|
|
417
|
-
return currentItemAmount + quantity > maxStock;
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
addItem(item, quantity = 1) {
|
|
421
|
-
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)));
|
|
422
|
-
}
|
|
423
|
-
decreaseItem(item) {
|
|
424
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
425
|
-
const checkoutItem = checkout.lineItems?.find((lineItem) => lineItem.id === item.id);
|
|
426
|
-
if (!isNil(checkoutItem))
|
|
427
|
-
checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
|
|
428
|
-
return checkout;
|
|
429
|
-
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
430
|
-
}
|
|
431
|
-
getCart(checkout) {
|
|
432
|
-
this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
|
|
433
|
-
return this.cartSubject;
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* @deprecated The method should not be used
|
|
437
|
-
*/
|
|
438
|
-
getVariantPriceDiscount(item) {
|
|
439
|
-
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)));
|
|
440
|
-
}
|
|
441
|
-
removeItem(item) {
|
|
442
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
443
|
-
const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
|
|
444
|
-
if (index >= 0)
|
|
445
|
-
checkout.lineItems.splice(index, 1);
|
|
446
|
-
return checkout;
|
|
447
|
-
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
448
|
-
}
|
|
449
|
-
updateUserCart(user) {
|
|
450
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => this.checkoutService
|
|
451
|
-
.updateCheckoutLineItems(Checkout.toInstance({
|
|
452
|
-
...checkout.toPlain(),
|
|
453
|
-
lineItems: checkout.lineItems?.length
|
|
454
|
-
? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
|
|
455
|
-
: [],
|
|
456
|
-
}))
|
|
457
|
-
.toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
458
|
-
}
|
|
459
|
-
clearCart() {
|
|
460
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
461
|
-
this.checkoutService.clearCheckoutFromSession();
|
|
462
|
-
return checkout;
|
|
463
|
-
}), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
|
|
464
|
-
}
|
|
465
|
-
buildCartFromCheckout(checkoutData) {
|
|
466
|
-
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
467
|
-
}
|
|
468
|
-
roundPrice(productPrice) {
|
|
469
|
-
const { price, fullPrice, subscriberPrice } = productPrice;
|
|
470
|
-
return {
|
|
471
|
-
...productPrice,
|
|
472
|
-
price: Number(price.toFixed(2)),
|
|
473
|
-
fullPrice: Number(fullPrice.toFixed(2)),
|
|
474
|
-
...(subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }),
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
async getProductData(productId) {
|
|
478
|
-
let product;
|
|
479
|
-
let variant;
|
|
480
|
-
try {
|
|
481
|
-
product = await this.productRepository.get({ id: productId });
|
|
482
|
-
}
|
|
483
|
-
catch (error) {
|
|
484
|
-
if (!(error instanceof NotFoundError))
|
|
485
|
-
throw error;
|
|
486
|
-
const { data: variants } = await this.variantRepository.find({ filters: { id: productId } });
|
|
487
|
-
variant = variants.shift();
|
|
488
|
-
if (!variant)
|
|
489
|
-
throw error;
|
|
490
|
-
product = await this.productRepository.get({ id: variant.productId });
|
|
491
|
-
}
|
|
492
|
-
return {
|
|
493
|
-
...product.toPlain(),
|
|
494
|
-
...(variant && { ...variant.toPlain() }),
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
getGifts() {
|
|
498
|
-
return this.checkoutService.getCheckout().pipe(mergeMap(async (checkout) => {
|
|
499
|
-
const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
|
|
500
|
-
if (!notGiftItems.length)
|
|
501
|
-
return { ...checkout, lineItems: [] };
|
|
502
|
-
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
503
|
-
const campaigns = await this.buy2WinRepository
|
|
504
|
-
.find({
|
|
505
|
-
filters: {
|
|
506
|
-
active: { operator: Where.EQUALS, value: true },
|
|
507
|
-
shop: { operator: Where.EQUALS, value: this.defaultShop },
|
|
508
|
-
},
|
|
509
|
-
})
|
|
510
|
-
.then((data) => data.data);
|
|
511
|
-
if (!campaigns.length)
|
|
512
|
-
return { ...checkout, lineItems: notGiftItems };
|
|
513
|
-
const elegibleCampaigns = [];
|
|
514
|
-
for (const campaign of campaigns) {
|
|
515
|
-
const today = new Date();
|
|
516
|
-
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
517
|
-
continue;
|
|
518
|
-
if (campaign.activeCategory) {
|
|
519
|
-
const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
|
|
520
|
-
const categoriesCampaingFullTree = [];
|
|
521
|
-
for (const id of categoriesCampaing) {
|
|
522
|
-
const children = await this.categoryRepository.getChildren(parseInt(id));
|
|
523
|
-
categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
|
|
524
|
-
}
|
|
525
|
-
const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
|
|
526
|
-
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
527
|
-
if (!l.categories || !l.categories?.length)
|
|
528
|
-
return true;
|
|
529
|
-
return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
|
|
530
|
-
});
|
|
531
|
-
if (filterProductsCategories.length) {
|
|
532
|
-
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
533
|
-
if (cartTotalCategories >= campaign.cartValueMin)
|
|
534
|
-
elegibleCampaigns.push(campaign);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
539
|
-
if (campaign.cartValue <= cartTotal)
|
|
540
|
-
elegibleCampaigns.push(campaign);
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
if (!elegibleCampaigns.length)
|
|
545
|
-
return { ...checkout, lineItems: notGiftItems };
|
|
546
|
-
const campaingnProducts = [];
|
|
547
|
-
for (const campaign of elegibleCampaigns) {
|
|
548
|
-
let elegibleProducts = [];
|
|
549
|
-
for (const product of campaign.products) {
|
|
550
|
-
const { data: productData } = await this.productRepository.find({ filters: { sku: product } });
|
|
551
|
-
if (!productData.length)
|
|
552
|
-
continue;
|
|
553
|
-
const gift = productData.shift();
|
|
554
|
-
if (gift.stock.quantity < 1)
|
|
555
|
-
continue;
|
|
556
|
-
elegibleProducts.push(gift);
|
|
557
|
-
}
|
|
558
|
-
campaingnProducts.push(elegibleProducts);
|
|
559
|
-
}
|
|
560
|
-
if (!campaingnProducts.length)
|
|
561
|
-
return { ...checkout, lineItems: notGiftItems };
|
|
562
|
-
const gifts = this.giftToLineItems([].concat(...campaingnProducts));
|
|
563
|
-
return { ...checkout, lineItems: notGiftItems.concat(gifts) };
|
|
564
|
-
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
565
|
-
}
|
|
566
|
-
giftToLineItems(items) {
|
|
567
|
-
return items.map((item) => {
|
|
568
|
-
const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
569
|
-
const image = item?.miniatures?.length ? item.miniatures[0] : item.images[0];
|
|
570
|
-
return LineItem.toInstance({
|
|
571
|
-
brand,
|
|
572
|
-
categories,
|
|
573
|
-
id: id.toString(),
|
|
574
|
-
name,
|
|
575
|
-
price,
|
|
576
|
-
sku,
|
|
577
|
-
slug,
|
|
578
|
-
stock,
|
|
579
|
-
weight,
|
|
580
|
-
EAN,
|
|
581
|
-
image,
|
|
582
|
-
pricePaid: 0,
|
|
583
|
-
quantity: 1,
|
|
584
|
-
isGift: true,
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
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 });
|
|
590
|
-
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
591
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
592
|
-
type: Injectable
|
|
593
|
-
}], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
|
|
594
|
-
type: Inject,
|
|
595
|
-
args: [DEFAULT_SHOP]
|
|
596
|
-
}] }, { type: undefined, decorators: [{
|
|
597
|
-
type: Inject,
|
|
598
|
-
args: ['ProductRepository']
|
|
599
|
-
}] }, { type: undefined, decorators: [{
|
|
600
|
-
type: Inject,
|
|
601
|
-
args: ['CategoryRepository']
|
|
602
|
-
}] }, { type: undefined, decorators: [{
|
|
603
|
-
type: Inject,
|
|
604
|
-
args: ['VariantRepository']
|
|
605
|
-
}] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
|
|
606
|
-
type: Inject,
|
|
607
|
-
args: ['Buy2WinRepository']
|
|
608
|
-
}] }]; } });
|
|
609
|
-
|
|
610
|
-
class CheckoutSubscriptionService {
|
|
611
|
-
constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
|
|
612
|
-
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
613
|
-
this.subscriptionRepository = subscriptionRepository;
|
|
614
|
-
this.couponService = couponService;
|
|
615
|
-
}
|
|
616
|
-
getCheckoutSubscription(checkoutData) {
|
|
617
|
-
const checkoutId = cookie.get('checkoutSubscriptionId');
|
|
618
|
-
if (!isNil(checkoutId))
|
|
619
|
-
return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
|
|
620
|
-
return from(this.createCheckoutSubscription(checkoutData));
|
|
621
|
-
}
|
|
622
|
-
async createCheckoutSubscription(checkoutData) {
|
|
623
|
-
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
624
|
-
createdAt: new Date(),
|
|
625
|
-
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
626
|
-
});
|
|
627
|
-
cookie.set('checkoutSubscriptionId', checkout.id);
|
|
628
|
-
return checkout;
|
|
629
|
-
}
|
|
630
|
-
clearCheckoutSubscriptionFromSession() {
|
|
631
|
-
cookie.remove('checkoutSubscriptionId');
|
|
632
|
-
return of();
|
|
633
|
-
}
|
|
634
|
-
checkCoupon(nickname, userEmail) {
|
|
635
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
636
|
-
.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
|
|
637
|
-
.pipe()));
|
|
638
|
-
}
|
|
639
|
-
calcDiscountSubscription(coupon) {
|
|
640
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
644
|
-
CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
|
|
645
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
646
|
-
type: Injectable
|
|
647
|
-
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
648
|
-
type: Inject,
|
|
649
|
-
args: ['CheckoutSubscriptionRepository']
|
|
650
|
-
}] }, { type: undefined, decorators: [{
|
|
651
|
-
type: Inject,
|
|
652
|
-
args: ['SubscriptionRepository']
|
|
653
|
-
}] }, { type: CouponService }]; } });
|
|
654
|
-
|
|
655
|
-
class HomeShopService {
|
|
656
|
-
constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
|
|
657
|
-
this.categoryRepository = categoryRepository;
|
|
658
|
-
this.homeRepository = homeRepository;
|
|
659
|
-
this.productRepository = productRepository;
|
|
660
|
-
this.defaultShop = defaultShop;
|
|
661
|
-
this.buildCategoryGroupWithRequiredData = (group) => ({
|
|
662
|
-
category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
|
|
663
|
-
products: group?.products?.map((product) => Product.toInstance(pick(product?.toPlain() || {}, [
|
|
664
|
-
'id',
|
|
665
|
-
'price',
|
|
666
|
-
'reviews',
|
|
667
|
-
'hasVariants',
|
|
668
|
-
'slug',
|
|
669
|
-
'sku',
|
|
670
|
-
'stock',
|
|
671
|
-
'costPrice',
|
|
672
|
-
'images',
|
|
673
|
-
'miniatures',
|
|
674
|
-
'name',
|
|
675
|
-
'weight',
|
|
676
|
-
'rate',
|
|
677
|
-
'type',
|
|
678
|
-
]))) || [],
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
|
-
get homeId() {
|
|
682
|
-
if (this.defaultShop === Shops.GLAMSHOP)
|
|
683
|
-
return 'glamshop';
|
|
684
|
-
if (this.defaultShop === Shops.MENSMARKET)
|
|
685
|
-
return 'mens_market';
|
|
686
|
-
return null;
|
|
687
|
-
}
|
|
688
|
-
getHomeData() {
|
|
689
|
-
return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
|
|
690
|
-
? of(home)
|
|
691
|
-
: forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
|
|
692
|
-
discoverProducts,
|
|
693
|
-
featuredProducts,
|
|
694
|
-
verticalProducts,
|
|
695
|
-
})), concatMap((data) => this.saveHomeData(data)))));
|
|
696
|
-
}
|
|
697
|
-
getBanners(type) {
|
|
698
|
-
return this.getHomeConfiguration().pipe(map((home) => {
|
|
699
|
-
if (type === 'brand')
|
|
700
|
-
return home.brandsCarousel;
|
|
701
|
-
if (type === 'buyToWin')
|
|
702
|
-
return [home.buyToWinBanner];
|
|
703
|
-
if (type === 'block')
|
|
704
|
-
return home.blockBanners;
|
|
705
|
-
if (type === 'blog')
|
|
706
|
-
return [home.blogBanner];
|
|
707
|
-
return [];
|
|
708
|
-
}));
|
|
709
|
-
}
|
|
710
|
-
getMinValueForFreeShipping() {
|
|
711
|
-
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
712
|
-
}
|
|
713
|
-
getDiscoverProducts() {
|
|
714
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
715
|
-
}
|
|
716
|
-
getFeaturedProducts() {
|
|
717
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
718
|
-
}
|
|
719
|
-
getVerticalProducts() {
|
|
720
|
-
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({
|
|
721
|
-
filters: { categories: { operator: Where.IN, value: [category.id] } },
|
|
722
|
-
limits: { limit: 12 },
|
|
723
|
-
})).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
|
|
724
|
-
}
|
|
725
|
-
getHomeConfiguration() {
|
|
726
|
-
return of(this.homeConfiguration).pipe(concatMap((home) => home
|
|
727
|
-
? of(home)
|
|
728
|
-
: !this.homeId
|
|
729
|
-
? throwError(new RequiredArgumentError(['homeId']))
|
|
730
|
-
: from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
|
|
731
|
-
}
|
|
732
|
-
saveHomeData(homeData) {
|
|
733
|
-
const data = {
|
|
734
|
-
createdAt: new Date(),
|
|
735
|
-
expiresAt: add(new Date(), { hours: 1 }),
|
|
736
|
-
data: homeData,
|
|
737
|
-
};
|
|
738
|
-
return from(this.homeRepository.update({
|
|
739
|
-
id: this.homeId,
|
|
740
|
-
data,
|
|
741
|
-
})).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
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 });
|
|
745
|
-
HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
|
|
746
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
|
|
747
|
-
type: Injectable
|
|
748
|
-
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
749
|
-
type: Inject,
|
|
750
|
-
args: ['CategoryRepository']
|
|
751
|
-
}] }, { type: undefined, decorators: [{
|
|
752
|
-
type: Inject,
|
|
753
|
-
args: ['HomeRepository']
|
|
754
|
-
}] }, { type: undefined, decorators: [{
|
|
755
|
-
type: Inject,
|
|
756
|
-
args: ['ProductRepository']
|
|
757
|
-
}] }, { type: i3.Shops, decorators: [{
|
|
758
|
-
type: Inject,
|
|
759
|
-
args: [DEFAULT_SHOP]
|
|
760
|
-
}] }]; } });
|
|
761
|
-
|
|
762
|
-
class OrderService {
|
|
763
|
-
constructor(angularFirestore, orderRepository) {
|
|
764
|
-
this.angularFirestore = angularFirestore;
|
|
765
|
-
this.orderRepository = orderRepository;
|
|
766
|
-
this.orderSubject = new Subject();
|
|
767
|
-
}
|
|
768
|
-
getOrder(id) {
|
|
769
|
-
docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
|
|
770
|
-
.pipe(map((doc) => Order.toInstance(doc.data())))
|
|
771
|
-
.subscribe((doc) => this.orderSubject.next(doc));
|
|
772
|
-
return this.orderSubject;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
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 });
|
|
776
|
-
OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
|
|
777
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
778
|
-
type: Injectable
|
|
779
|
-
}], ctorParameters: function () { return [{ type: i1$1.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
|
|
780
|
-
type: Inject,
|
|
781
|
-
args: ['OrderRepository']
|
|
782
|
-
}] }]; } });
|
|
783
|
-
|
|
784
|
-
class ShippingService {
|
|
785
|
-
constructor(http, apiUrl, homeService) {
|
|
786
|
-
this.http = http;
|
|
787
|
-
this.apiUrl = apiUrl;
|
|
788
|
-
this.homeService = homeService;
|
|
789
|
-
}
|
|
790
|
-
getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
|
|
791
|
-
return combineLatest([
|
|
792
|
-
this.homeService.getHomeData(),
|
|
793
|
-
this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
|
|
794
|
-
]).pipe(map(([datas, shippingMethodsResponse]) => {
|
|
795
|
-
let shippingMethods = shippingMethodsResponse.result;
|
|
796
|
-
if (!shippingMethods.length)
|
|
797
|
-
return [];
|
|
798
|
-
shippingMethods = shippingMethods.map((shippingMethod) => {
|
|
799
|
-
if (shippingMethod.ShippingCompanyName == 'Same Day EG')
|
|
800
|
-
shippingMethod.ShippingCompanyName = 'Same Day';
|
|
801
|
-
return shippingMethod;
|
|
802
|
-
});
|
|
803
|
-
const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
|
|
804
|
-
if (this.isHolidays(datasSameDayNotAvaliable)) {
|
|
805
|
-
shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
|
|
806
|
-
}
|
|
807
|
-
if (totalPrice >= 200) {
|
|
808
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
809
|
-
if (s.serviceName !== 'Same Day')
|
|
810
|
-
return { ...s, totalPrice: 0 };
|
|
811
|
-
else
|
|
812
|
-
return s;
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
if (shop == Shops.GLAMSHOP)
|
|
816
|
-
return shippingMethods;
|
|
817
|
-
if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
|
|
818
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
819
|
-
if (s.serviceName == 'Same Day')
|
|
820
|
-
return { ...s, totalPrice: s.totalPrice / 2 };
|
|
821
|
-
else
|
|
822
|
-
return { ...s, totalPrice: 0 };
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
|
|
826
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
827
|
-
return { ...s, totalPrice: s.totalPrice / 2 };
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
return shippingMethods;
|
|
831
|
-
}));
|
|
832
|
-
}
|
|
833
|
-
isFreeShippingBySubscription(shop, subscriptionPlan) {
|
|
834
|
-
if (!subscriptionPlan)
|
|
835
|
-
return false;
|
|
836
|
-
if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
|
|
837
|
-
return true;
|
|
838
|
-
return false;
|
|
839
|
-
}
|
|
840
|
-
isHalfShippingBySubscription(shop, subscriptionPlan) {
|
|
841
|
-
if (!subscriptionPlan)
|
|
842
|
-
return false;
|
|
843
|
-
if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
|
|
844
|
-
return true;
|
|
845
|
-
}
|
|
846
|
-
return false;
|
|
847
|
-
}
|
|
848
|
-
isHolidays(datas) {
|
|
849
|
-
const today = new Date();
|
|
850
|
-
for (const key in datas) {
|
|
851
|
-
let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
|
|
852
|
-
let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
|
|
853
|
-
if (start > end)
|
|
854
|
-
end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
|
|
855
|
-
if (today >= start && today <= end)
|
|
856
|
-
return true;
|
|
857
|
-
}
|
|
858
|
-
return false;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i1$2.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
862
|
-
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
|
|
863
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
|
|
864
|
-
type: Injectable
|
|
865
|
-
}], ctorParameters: function () { return [{ type: i1$2.HttpClient }, { type: undefined, decorators: [{
|
|
866
|
-
type: Inject,
|
|
867
|
-
args: [BACKEND_URL]
|
|
868
|
-
}] }, { type: HomeShopService }]; } });
|
|
869
|
-
|
|
870
|
-
class AngularFirebaseAuthModule {
|
|
871
|
-
static initializeApp(options, nameOrConfig) {
|
|
872
|
-
return {
|
|
873
|
-
ngModule: AngularFirebaseAuthModule,
|
|
874
|
-
providers: [
|
|
875
|
-
{ provide: FIREBASE_OPTIONS, useValue: options },
|
|
876
|
-
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
877
|
-
],
|
|
878
|
-
};
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
882
|
-
AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1$3.FirebaseAppModule, i1.AuthModule] });
|
|
883
|
-
AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
|
|
234
|
+
deps: ['FirestoreOptions'],
|
|
235
|
+
},
|
|
884
236
|
{
|
|
885
|
-
provide:
|
|
886
|
-
useFactory: (
|
|
887
|
-
return new
|
|
237
|
+
provide: CategoryFirestoreRepository,
|
|
238
|
+
useFactory: (options) => {
|
|
239
|
+
return new CategoryFirestoreRepository(options);
|
|
888
240
|
},
|
|
889
|
-
deps: ['
|
|
241
|
+
deps: ['FirestoreOptions'],
|
|
890
242
|
},
|
|
891
243
|
{
|
|
892
|
-
provide: '
|
|
893
|
-
useFactory: (
|
|
894
|
-
return new
|
|
244
|
+
provide: 'CheckoutRepository',
|
|
245
|
+
useFactory: (options) => {
|
|
246
|
+
return new CheckoutFirestoreRepository(options);
|
|
895
247
|
},
|
|
896
|
-
deps: [
|
|
248
|
+
deps: ['FirestoreOptions'],
|
|
897
249
|
},
|
|
898
250
|
{
|
|
899
|
-
provide: '
|
|
900
|
-
useFactory: (
|
|
901
|
-
return new
|
|
251
|
+
provide: 'CheckoutSubscriptionRepository',
|
|
252
|
+
useFactory: (options) => {
|
|
253
|
+
return new CheckoutSubscriptionFirestoreRepository(options);
|
|
902
254
|
},
|
|
903
|
-
deps: ['
|
|
255
|
+
deps: ['FirestoreOptions'],
|
|
904
256
|
},
|
|
905
257
|
{
|
|
906
|
-
provide: '
|
|
907
|
-
useFactory: (
|
|
908
|
-
return new
|
|
258
|
+
provide: 'CouponRepository',
|
|
259
|
+
useFactory: (options) => {
|
|
260
|
+
return new CouponFirestoreRepository(options);
|
|
909
261
|
},
|
|
910
|
-
deps: [
|
|
262
|
+
deps: ['FirestoreOptions'],
|
|
911
263
|
},
|
|
912
264
|
{
|
|
913
|
-
provide: '
|
|
914
|
-
useFactory: (
|
|
915
|
-
return new
|
|
265
|
+
provide: 'CampaignHashtagRepository',
|
|
266
|
+
useFactory: (options) => {
|
|
267
|
+
return new CampaignHashtagFirestoreRepository(options);
|
|
916
268
|
},
|
|
917
|
-
deps: ['
|
|
269
|
+
deps: ['FirestoreOptions'],
|
|
918
270
|
},
|
|
919
271
|
{
|
|
920
|
-
provide: '
|
|
921
|
-
useFactory: (
|
|
922
|
-
return new
|
|
272
|
+
provide: 'CampaignDashboardRepository',
|
|
273
|
+
useFactory: (options) => {
|
|
274
|
+
return new CampaignDashboardFirestoreRepository(options);
|
|
923
275
|
},
|
|
924
|
-
deps: ['
|
|
276
|
+
deps: ['FirestoreOptions'],
|
|
925
277
|
},
|
|
926
|
-
|
|
278
|
+
{
|
|
279
|
+
provide: 'EditionRepository',
|
|
280
|
+
useFactory: (options, subscriptionRepository) => {
|
|
281
|
+
return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
|
|
282
|
+
},
|
|
283
|
+
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
provide: 'HomeRepository',
|
|
287
|
+
useFactory: (options) => {
|
|
288
|
+
return new HomeFirestoreRepository(options);
|
|
289
|
+
},
|
|
290
|
+
deps: ['FirestoreOptions'],
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
provide: 'LeadRepository',
|
|
294
|
+
useFactory: (options) => {
|
|
295
|
+
return new LeadFirestoreRepository(options);
|
|
296
|
+
},
|
|
297
|
+
deps: ['FirestoreOptions'],
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
provide: 'LegacyOrderRepository',
|
|
301
|
+
useFactory: (options) => {
|
|
302
|
+
return new LegacyOrderFirestoreRepository(options);
|
|
303
|
+
},
|
|
304
|
+
deps: ['FirestoreOptions'],
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
provide: 'ShopMenuRepository',
|
|
308
|
+
useFactory: (options) => {
|
|
309
|
+
return new ShopMenuFirestoreRepository(options);
|
|
310
|
+
},
|
|
311
|
+
deps: ['FirestoreOptions'],
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
provide: 'OrderRepository',
|
|
315
|
+
useFactory: (options) => {
|
|
316
|
+
return new OrderFirestoreRepository(options);
|
|
317
|
+
},
|
|
318
|
+
deps: ['FirestoreOptions'],
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
provide: 'PaymentRepository',
|
|
322
|
+
useFactory: (options) => {
|
|
323
|
+
return new PaymentFirestoreRepository(options);
|
|
324
|
+
},
|
|
325
|
+
deps: ['FirestoreOptions'],
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
provide: ProductFirestoreRepository,
|
|
329
|
+
useFactory: (options) => {
|
|
330
|
+
return new ProductFirestoreRepository(options);
|
|
331
|
+
},
|
|
332
|
+
deps: ['FirestoreOptions'],
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
provide: 'ShopSettingsRepository',
|
|
336
|
+
useFactory: (options) => {
|
|
337
|
+
return new ShopSettingsFirestoreRepository(options);
|
|
338
|
+
},
|
|
339
|
+
deps: ['FirestoreOptions'],
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
provide: 'SubscriptionPaymentRepository',
|
|
343
|
+
useFactory: (options, subscriptionRepository) => {
|
|
344
|
+
return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
|
|
345
|
+
},
|
|
346
|
+
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
provide: 'SubscriptionPlanRepository',
|
|
350
|
+
useFactory: (options) => {
|
|
351
|
+
return new SubscriptionPlanFirestoreRepository(options);
|
|
352
|
+
},
|
|
353
|
+
deps: ['FirestoreOptions'],
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
provide: 'SubscriptionProductRepository',
|
|
357
|
+
useFactory: (options) => {
|
|
358
|
+
return new SubscriptionProductFirestoreRepository(options);
|
|
359
|
+
},
|
|
360
|
+
deps: ['FirestoreOptions'],
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
provide: 'SubscriptionRepository',
|
|
364
|
+
useFactory: (options) => {
|
|
365
|
+
return new SubscriptionFirestoreRepository(options);
|
|
366
|
+
},
|
|
367
|
+
deps: ['FirestoreOptions'],
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
provide: 'UserRepository',
|
|
371
|
+
useFactory: (options) => {
|
|
372
|
+
return new UserFirestoreRepository(options);
|
|
373
|
+
},
|
|
374
|
+
deps: ['FirestoreOptions'],
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
provide: 'UserAddressRepository',
|
|
378
|
+
useFactory: (options, userRepository) => {
|
|
379
|
+
return new UserAddressFirestoreRepository(options, userRepository);
|
|
380
|
+
},
|
|
381
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
provide: 'UserPaymentMethodRepository',
|
|
385
|
+
useFactory: (options, userRepository) => {
|
|
386
|
+
return new UserPaymentMethodFirestoreRepository(options, userRepository);
|
|
387
|
+
},
|
|
388
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
provide: ProductVariantFirestoreRepository,
|
|
392
|
+
useFactory: (options, productRepository) => {
|
|
393
|
+
return new ProductVariantFirestoreRepository(options, productRepository);
|
|
394
|
+
},
|
|
395
|
+
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
396
|
+
},
|
|
397
|
+
], imports: [AngularElasticSeachModule,
|
|
398
|
+
provideFirebaseApp((injector) => {
|
|
927
399
|
const appName = injector.get(FIREBASE_APP_NAME);
|
|
928
400
|
return appName
|
|
929
|
-
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
930
|
-
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
931
|
-
}),
|
|
932
|
-
|
|
933
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type:
|
|
401
|
+
? initializeApp$1(injector.get(FIREBASE_OPTIONS), appName)
|
|
402
|
+
: initializeApp$1(injector.get(FIREBASE_OPTIONS));
|
|
403
|
+
}),
|
|
404
|
+
provideFirestore(() => getFirestore())] });
|
|
405
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, decorators: [{
|
|
934
406
|
type: NgModule,
|
|
935
407
|
args: [{
|
|
936
408
|
imports: [
|
|
409
|
+
AngularElasticSeachModule,
|
|
937
410
|
provideFirebaseApp((injector) => {
|
|
938
411
|
const appName = injector.get(FIREBASE_APP_NAME);
|
|
939
412
|
return appName
|
|
940
|
-
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
941
|
-
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
413
|
+
? initializeApp$1(injector.get(FIREBASE_OPTIONS), appName)
|
|
414
|
+
: initializeApp$1(injector.get(FIREBASE_OPTIONS));
|
|
942
415
|
}),
|
|
943
|
-
|
|
416
|
+
provideFirestore(() => getFirestore()),
|
|
944
417
|
],
|
|
945
418
|
providers: [
|
|
946
419
|
{
|
|
947
|
-
provide: '
|
|
948
|
-
useFactory: (
|
|
949
|
-
|
|
420
|
+
provide: 'FirestoreOptions',
|
|
421
|
+
useFactory: (firestore, platformId) => ({
|
|
422
|
+
firestore,
|
|
423
|
+
interceptors: {
|
|
424
|
+
request: (request) => {
|
|
425
|
+
if (isPlatformBrowser(platformId))
|
|
426
|
+
return request;
|
|
427
|
+
const interval = setInterval(() => { }, 100);
|
|
428
|
+
request.interval = interval;
|
|
429
|
+
return request;
|
|
430
|
+
},
|
|
431
|
+
response: (response, request) => {
|
|
432
|
+
if (isPlatformBrowser(platformId))
|
|
433
|
+
return response;
|
|
434
|
+
clearInterval(request.interval);
|
|
435
|
+
return response;
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
}),
|
|
439
|
+
deps: [Firestore, PLATFORM_ID],
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
provide: 'BeautyProfileRepository',
|
|
443
|
+
useFactory: (config, userRepository) => {
|
|
444
|
+
return new UserBeautyProfileFirestoreRepository(config, userRepository);
|
|
950
445
|
},
|
|
951
|
-
deps: ['
|
|
446
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
952
447
|
},
|
|
953
448
|
{
|
|
954
|
-
provide: '
|
|
955
|
-
useFactory: (
|
|
956
|
-
return new
|
|
449
|
+
provide: 'Buy2WinRepository',
|
|
450
|
+
useFactory: (options) => {
|
|
451
|
+
return new Buy2WinFirestoreRepository(options);
|
|
957
452
|
},
|
|
958
|
-
deps: [
|
|
453
|
+
deps: ['FirestoreOptions'],
|
|
959
454
|
},
|
|
960
455
|
{
|
|
961
|
-
provide:
|
|
962
|
-
useFactory: (
|
|
963
|
-
return new
|
|
456
|
+
provide: CategoryFirestoreRepository,
|
|
457
|
+
useFactory: (options) => {
|
|
458
|
+
return new CategoryFirestoreRepository(options);
|
|
964
459
|
},
|
|
965
|
-
deps: ['
|
|
460
|
+
deps: ['FirestoreOptions'],
|
|
966
461
|
},
|
|
967
462
|
{
|
|
968
|
-
provide: '
|
|
969
|
-
useFactory: (
|
|
970
|
-
return new
|
|
463
|
+
provide: 'CheckoutRepository',
|
|
464
|
+
useFactory: (options) => {
|
|
465
|
+
return new CheckoutFirestoreRepository(options);
|
|
971
466
|
},
|
|
972
|
-
deps: [
|
|
467
|
+
deps: ['FirestoreOptions'],
|
|
973
468
|
},
|
|
974
469
|
{
|
|
975
|
-
provide: '
|
|
976
|
-
useFactory: (
|
|
977
|
-
return new
|
|
470
|
+
provide: 'CheckoutSubscriptionRepository',
|
|
471
|
+
useFactory: (options) => {
|
|
472
|
+
return new CheckoutSubscriptionFirestoreRepository(options);
|
|
978
473
|
},
|
|
979
|
-
deps: ['
|
|
474
|
+
deps: ['FirestoreOptions'],
|
|
980
475
|
},
|
|
981
476
|
{
|
|
982
|
-
provide: '
|
|
983
|
-
useFactory: (
|
|
984
|
-
return new
|
|
477
|
+
provide: 'CouponRepository',
|
|
478
|
+
useFactory: (options) => {
|
|
479
|
+
return new CouponFirestoreRepository(options);
|
|
985
480
|
},
|
|
986
|
-
deps: ['
|
|
481
|
+
deps: ['FirestoreOptions'],
|
|
987
482
|
},
|
|
988
|
-
],
|
|
989
|
-
}]
|
|
990
|
-
}] });
|
|
991
|
-
|
|
992
|
-
class AngularElasticSeachModule {
|
|
993
|
-
static initializeApp(options) {
|
|
994
|
-
return {
|
|
995
|
-
ngModule: AngularElasticSeachModule,
|
|
996
|
-
providers: [{ provide: ES_CONFIG, useValue: options }],
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1001
|
-
AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule });
|
|
1002
|
-
AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
|
|
1003
|
-
{
|
|
1004
|
-
provide: ProductsIndex,
|
|
1005
|
-
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
1006
|
-
deps: [ES_CONFIG],
|
|
1007
|
-
},
|
|
1008
|
-
] });
|
|
1009
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
|
|
1010
|
-
type: NgModule,
|
|
1011
|
-
args: [{
|
|
1012
|
-
providers: [
|
|
1013
483
|
{
|
|
1014
|
-
provide:
|
|
1015
|
-
useFactory: (
|
|
1016
|
-
|
|
484
|
+
provide: 'CampaignHashtagRepository',
|
|
485
|
+
useFactory: (options) => {
|
|
486
|
+
return new CampaignHashtagFirestoreRepository(options);
|
|
487
|
+
},
|
|
488
|
+
deps: ['FirestoreOptions'],
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
provide: 'CampaignDashboardRepository',
|
|
492
|
+
useFactory: (options) => {
|
|
493
|
+
return new CampaignDashboardFirestoreRepository(options);
|
|
494
|
+
},
|
|
495
|
+
deps: ['FirestoreOptions'],
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
provide: 'EditionRepository',
|
|
499
|
+
useFactory: (options, subscriptionRepository) => {
|
|
500
|
+
return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
|
|
501
|
+
},
|
|
502
|
+
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
provide: 'HomeRepository',
|
|
506
|
+
useFactory: (options) => {
|
|
507
|
+
return new HomeFirestoreRepository(options);
|
|
508
|
+
},
|
|
509
|
+
deps: ['FirestoreOptions'],
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
provide: 'LeadRepository',
|
|
513
|
+
useFactory: (options) => {
|
|
514
|
+
return new LeadFirestoreRepository(options);
|
|
515
|
+
},
|
|
516
|
+
deps: ['FirestoreOptions'],
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
provide: 'LegacyOrderRepository',
|
|
520
|
+
useFactory: (options) => {
|
|
521
|
+
return new LegacyOrderFirestoreRepository(options);
|
|
522
|
+
},
|
|
523
|
+
deps: ['FirestoreOptions'],
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
provide: 'ShopMenuRepository',
|
|
527
|
+
useFactory: (options) => {
|
|
528
|
+
return new ShopMenuFirestoreRepository(options);
|
|
529
|
+
},
|
|
530
|
+
deps: ['FirestoreOptions'],
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
provide: 'OrderRepository',
|
|
534
|
+
useFactory: (options) => {
|
|
535
|
+
return new OrderFirestoreRepository(options);
|
|
536
|
+
},
|
|
537
|
+
deps: ['FirestoreOptions'],
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
provide: 'PaymentRepository',
|
|
541
|
+
useFactory: (options) => {
|
|
542
|
+
return new PaymentFirestoreRepository(options);
|
|
543
|
+
},
|
|
544
|
+
deps: ['FirestoreOptions'],
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
provide: ProductFirestoreRepository,
|
|
548
|
+
useFactory: (options) => {
|
|
549
|
+
return new ProductFirestoreRepository(options);
|
|
550
|
+
},
|
|
551
|
+
deps: ['FirestoreOptions'],
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
provide: 'ShopSettingsRepository',
|
|
555
|
+
useFactory: (options) => {
|
|
556
|
+
return new ShopSettingsFirestoreRepository(options);
|
|
557
|
+
},
|
|
558
|
+
deps: ['FirestoreOptions'],
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
provide: 'SubscriptionPaymentRepository',
|
|
562
|
+
useFactory: (options, subscriptionRepository) => {
|
|
563
|
+
return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
|
|
564
|
+
},
|
|
565
|
+
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
provide: 'SubscriptionPlanRepository',
|
|
569
|
+
useFactory: (options) => {
|
|
570
|
+
return new SubscriptionPlanFirestoreRepository(options);
|
|
571
|
+
},
|
|
572
|
+
deps: ['FirestoreOptions'],
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
provide: 'SubscriptionProductRepository',
|
|
576
|
+
useFactory: (options) => {
|
|
577
|
+
return new SubscriptionProductFirestoreRepository(options);
|
|
578
|
+
},
|
|
579
|
+
deps: ['FirestoreOptions'],
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
provide: 'SubscriptionRepository',
|
|
583
|
+
useFactory: (options) => {
|
|
584
|
+
return new SubscriptionFirestoreRepository(options);
|
|
585
|
+
},
|
|
586
|
+
deps: ['FirestoreOptions'],
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
provide: 'UserRepository',
|
|
590
|
+
useFactory: (options) => {
|
|
591
|
+
return new UserFirestoreRepository(options);
|
|
592
|
+
},
|
|
593
|
+
deps: ['FirestoreOptions'],
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
provide: 'UserAddressRepository',
|
|
597
|
+
useFactory: (options, userRepository) => {
|
|
598
|
+
return new UserAddressFirestoreRepository(options, userRepository);
|
|
599
|
+
},
|
|
600
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
provide: 'UserPaymentMethodRepository',
|
|
604
|
+
useFactory: (options, userRepository) => {
|
|
605
|
+
return new UserPaymentMethodFirestoreRepository(options, userRepository);
|
|
606
|
+
},
|
|
607
|
+
deps: ['FirestoreOptions', 'UserRepository'],
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
provide: ProductVariantFirestoreRepository,
|
|
611
|
+
useFactory: (options, productRepository) => {
|
|
612
|
+
return new ProductVariantFirestoreRepository(options, productRepository);
|
|
613
|
+
},
|
|
614
|
+
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
1017
615
|
},
|
|
1018
616
|
],
|
|
1019
617
|
}]
|
|
1020
618
|
}] });
|
|
1021
619
|
|
|
1022
|
-
class
|
|
1023
|
-
static initializeApp(options
|
|
620
|
+
class AngularHasuraGraphQLModule {
|
|
621
|
+
static initializeApp(options) {
|
|
1024
622
|
return {
|
|
1025
|
-
ngModule:
|
|
1026
|
-
providers: [
|
|
1027
|
-
{ provide: FIREBASE_OPTIONS, useValue: options.firebase },
|
|
1028
|
-
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
1029
|
-
{ provide: ES_CONFIG, useValue: options.elasticSearch },
|
|
1030
|
-
],
|
|
623
|
+
ngModule: AngularHasuraGraphQLModule,
|
|
624
|
+
providers: [{ provide: HASURA_OPTIONS, useValue: options }],
|
|
1031
625
|
};
|
|
1032
626
|
}
|
|
1033
627
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
628
|
+
AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
629
|
+
AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule });
|
|
630
|
+
AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
|
|
1037
631
|
{
|
|
1038
|
-
provide: '
|
|
1039
|
-
useFactory: (
|
|
1040
|
-
|
|
632
|
+
provide: 'HasuraConfig',
|
|
633
|
+
useFactory: (options, platformId) => ({
|
|
634
|
+
endpoint: options.endpoint,
|
|
635
|
+
authOptions: options.credentials,
|
|
1041
636
|
interceptors: {
|
|
1042
637
|
request: (request) => {
|
|
1043
638
|
if (isPlatformBrowser(platformId))
|
|
@@ -1054,603 +649,1062 @@ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0",
|
|
|
1054
649
|
},
|
|
1055
650
|
},
|
|
1056
651
|
}),
|
|
1057
|
-
deps: [
|
|
1058
|
-
},
|
|
1059
|
-
{
|
|
1060
|
-
provide: 'BeautyProfileRepository',
|
|
1061
|
-
useFactory: (config, userRepository) => {
|
|
1062
|
-
return new UserBeautyProfileFirestoreRepository(config, userRepository);
|
|
1063
|
-
},
|
|
1064
|
-
deps: ['FirestoreOptions', 'UserRepository'],
|
|
1065
|
-
},
|
|
1066
|
-
{
|
|
1067
|
-
provide: 'Buy2WinRepository',
|
|
1068
|
-
useFactory: (options) => {
|
|
1069
|
-
return new Buy2WinFirestoreRepository(options);
|
|
1070
|
-
},
|
|
1071
|
-
deps: ['FirestoreOptions'],
|
|
1072
|
-
},
|
|
1073
|
-
{
|
|
1074
|
-
provide: CategoryFirestoreRepository,
|
|
1075
|
-
useFactory: (options) => {
|
|
1076
|
-
return new CategoryFirestoreRepository(options);
|
|
1077
|
-
},
|
|
1078
|
-
deps: ['FirestoreOptions'],
|
|
1079
|
-
},
|
|
1080
|
-
{
|
|
1081
|
-
provide: 'CheckoutRepository',
|
|
1082
|
-
useFactory: (options) => {
|
|
1083
|
-
return new CheckoutFirestoreRepository(options);
|
|
1084
|
-
},
|
|
1085
|
-
deps: ['FirestoreOptions'],
|
|
1086
|
-
},
|
|
1087
|
-
{
|
|
1088
|
-
provide: 'CheckoutSubscriptionRepository',
|
|
1089
|
-
useFactory: (options) => {
|
|
1090
|
-
return new CheckoutSubscriptionFirestoreRepository(options);
|
|
1091
|
-
},
|
|
1092
|
-
deps: ['FirestoreOptions'],
|
|
1093
|
-
},
|
|
1094
|
-
{
|
|
1095
|
-
provide: 'CouponRepository',
|
|
1096
|
-
useFactory: (options) => {
|
|
1097
|
-
return new CouponFirestoreRepository(options);
|
|
1098
|
-
},
|
|
1099
|
-
deps: ['FirestoreOptions'],
|
|
1100
|
-
},
|
|
1101
|
-
{
|
|
1102
|
-
provide: 'CampaignHashtagRepository',
|
|
1103
|
-
useFactory: (options) => {
|
|
1104
|
-
return new CampaignHashtagFirestoreRepository(options);
|
|
1105
|
-
},
|
|
1106
|
-
deps: ['FirestoreOptions'],
|
|
1107
|
-
},
|
|
1108
|
-
{
|
|
1109
|
-
provide: 'CampaignDashboardRepository',
|
|
1110
|
-
useFactory: (options) => {
|
|
1111
|
-
return new CampaignDashboardFirestoreRepository(options);
|
|
1112
|
-
},
|
|
1113
|
-
deps: ['FirestoreOptions'],
|
|
1114
|
-
},
|
|
1115
|
-
{
|
|
1116
|
-
provide: 'EditionRepository',
|
|
1117
|
-
useFactory: (options, subscriptionRepository) => {
|
|
1118
|
-
return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
|
|
1119
|
-
},
|
|
1120
|
-
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
1121
|
-
},
|
|
1122
|
-
{
|
|
1123
|
-
provide: 'HomeRepository',
|
|
1124
|
-
useFactory: (options) => {
|
|
1125
|
-
return new HomeFirestoreRepository(options);
|
|
1126
|
-
},
|
|
1127
|
-
deps: ['FirestoreOptions'],
|
|
1128
|
-
},
|
|
1129
|
-
{
|
|
1130
|
-
provide: 'LeadRepository',
|
|
1131
|
-
useFactory: (options) => {
|
|
1132
|
-
return new LeadFirestoreRepository(options);
|
|
1133
|
-
},
|
|
1134
|
-
deps: ['FirestoreOptions'],
|
|
652
|
+
deps: [HASURA_OPTIONS, PLATFORM_ID],
|
|
1135
653
|
},
|
|
1136
654
|
{
|
|
1137
|
-
provide: '
|
|
1138
|
-
|
|
1139
|
-
return new LegacyOrderFirestoreRepository(options);
|
|
1140
|
-
},
|
|
1141
|
-
deps: ['FirestoreOptions'],
|
|
655
|
+
provide: 'CategoryRepository',
|
|
656
|
+
useExisting: CategoryHasuraGraphQLRepository,
|
|
1142
657
|
},
|
|
1143
658
|
{
|
|
1144
|
-
provide:
|
|
1145
|
-
useFactory: (options) => {
|
|
1146
|
-
return new
|
|
659
|
+
provide: CategoryHasuraGraphQLRepository,
|
|
660
|
+
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
661
|
+
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
1147
662
|
},
|
|
1148
|
-
deps: ['
|
|
663
|
+
deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1149
664
|
},
|
|
1150
665
|
{
|
|
1151
|
-
provide: '
|
|
1152
|
-
|
|
1153
|
-
return new OrderFirestoreRepository(options);
|
|
1154
|
-
},
|
|
1155
|
-
deps: ['FirestoreOptions'],
|
|
666
|
+
provide: 'ProductRepository',
|
|
667
|
+
useExisting: ProductHasuraGraphQLRepository,
|
|
1156
668
|
},
|
|
1157
669
|
{
|
|
1158
|
-
provide:
|
|
1159
|
-
useFactory: (
|
|
1160
|
-
return new
|
|
670
|
+
provide: ProductHasuraGraphQLRepository,
|
|
671
|
+
useFactory: (hasuraConfig) => {
|
|
672
|
+
return new ProductHasuraGraphQLRepository(hasuraConfig);
|
|
1161
673
|
},
|
|
1162
|
-
deps: ['
|
|
674
|
+
deps: ['HasuraConfig'],
|
|
1163
675
|
},
|
|
1164
676
|
{
|
|
1165
|
-
provide:
|
|
1166
|
-
|
|
1167
|
-
return new ProductFirestoreRepository(options);
|
|
1168
|
-
},
|
|
1169
|
-
deps: ['FirestoreOptions'],
|
|
677
|
+
provide: 'VariantRepository',
|
|
678
|
+
useExisting: VariantHasuraGraphQLRepository,
|
|
1170
679
|
},
|
|
1171
680
|
{
|
|
1172
|
-
provide:
|
|
1173
|
-
useFactory: (
|
|
1174
|
-
return new
|
|
681
|
+
provide: VariantHasuraGraphQLRepository,
|
|
682
|
+
useFactory: (hasuraConfig) => {
|
|
683
|
+
return new VariantHasuraGraphQLRepository(hasuraConfig);
|
|
1175
684
|
},
|
|
1176
|
-
deps: ['
|
|
685
|
+
deps: ['HasuraConfig'],
|
|
1177
686
|
},
|
|
1178
687
|
{
|
|
1179
|
-
provide: '
|
|
1180
|
-
|
|
1181
|
-
return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
|
|
1182
|
-
},
|
|
1183
|
-
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
688
|
+
provide: 'CategoryFilterRepository',
|
|
689
|
+
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1184
690
|
},
|
|
1185
691
|
{
|
|
1186
|
-
provide:
|
|
692
|
+
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1187
693
|
useFactory: (options) => {
|
|
1188
|
-
return new
|
|
694
|
+
return new CategoryFilterHasuraGraphQLRepository(options);
|
|
1189
695
|
},
|
|
1190
|
-
deps: ['
|
|
696
|
+
deps: ['HasuraConfig'],
|
|
1191
697
|
},
|
|
1192
698
|
{
|
|
1193
|
-
provide: '
|
|
1194
|
-
|
|
1195
|
-
return new SubscriptionProductFirestoreRepository(options);
|
|
1196
|
-
},
|
|
1197
|
-
deps: ['FirestoreOptions'],
|
|
699
|
+
provide: 'FilterOptionRepository',
|
|
700
|
+
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1198
701
|
},
|
|
1199
702
|
{
|
|
1200
|
-
provide:
|
|
703
|
+
provide: FilterOptionHasuraGraphQLRepository,
|
|
1201
704
|
useFactory: (options) => {
|
|
1202
|
-
return new
|
|
705
|
+
return new FilterOptionHasuraGraphQLRepository(options);
|
|
1203
706
|
},
|
|
1204
|
-
deps: ['
|
|
707
|
+
deps: ['HasuraConfig'],
|
|
1205
708
|
},
|
|
1206
709
|
{
|
|
1207
|
-
provide: '
|
|
1208
|
-
|
|
1209
|
-
return new UserFirestoreRepository(options);
|
|
1210
|
-
},
|
|
1211
|
-
deps: ['FirestoreOptions'],
|
|
710
|
+
provide: 'FilterRepository',
|
|
711
|
+
useExisting: FilterHasuraGraphQLRepository,
|
|
1212
712
|
},
|
|
1213
713
|
{
|
|
1214
|
-
provide:
|
|
1215
|
-
useFactory: (options,
|
|
1216
|
-
return new
|
|
714
|
+
provide: FilterHasuraGraphQLRepository,
|
|
715
|
+
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
716
|
+
return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
|
|
1217
717
|
},
|
|
1218
|
-
deps: ['
|
|
718
|
+
deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1219
719
|
},
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
720
|
+
] });
|
|
721
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
|
|
722
|
+
type: NgModule,
|
|
723
|
+
args: [{
|
|
724
|
+
providers: [
|
|
725
|
+
{
|
|
726
|
+
provide: 'HasuraConfig',
|
|
727
|
+
useFactory: (options, platformId) => ({
|
|
728
|
+
endpoint: options.endpoint,
|
|
729
|
+
authOptions: options.credentials,
|
|
730
|
+
interceptors: {
|
|
731
|
+
request: (request) => {
|
|
732
|
+
if (isPlatformBrowser(platformId))
|
|
733
|
+
return request;
|
|
734
|
+
const interval = setInterval(() => { }, 100);
|
|
735
|
+
request.interval = interval;
|
|
736
|
+
return request;
|
|
737
|
+
},
|
|
738
|
+
response: (response, request) => {
|
|
739
|
+
if (isPlatformBrowser(platformId))
|
|
740
|
+
return response;
|
|
741
|
+
clearInterval(request.interval);
|
|
742
|
+
return response;
|
|
743
|
+
},
|
|
744
|
+
},
|
|
745
|
+
}),
|
|
746
|
+
deps: [HASURA_OPTIONS, PLATFORM_ID],
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
provide: 'CategoryRepository',
|
|
750
|
+
useExisting: CategoryHasuraGraphQLRepository,
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
provide: CategoryHasuraGraphQLRepository,
|
|
754
|
+
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
755
|
+
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
756
|
+
},
|
|
757
|
+
deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
provide: 'ProductRepository',
|
|
761
|
+
useExisting: ProductHasuraGraphQLRepository,
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
provide: ProductHasuraGraphQLRepository,
|
|
765
|
+
useFactory: (hasuraConfig) => {
|
|
766
|
+
return new ProductHasuraGraphQLRepository(hasuraConfig);
|
|
767
|
+
},
|
|
768
|
+
deps: ['HasuraConfig'],
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
provide: 'VariantRepository',
|
|
772
|
+
useExisting: VariantHasuraGraphQLRepository,
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
provide: VariantHasuraGraphQLRepository,
|
|
776
|
+
useFactory: (hasuraConfig) => {
|
|
777
|
+
return new VariantHasuraGraphQLRepository(hasuraConfig);
|
|
778
|
+
},
|
|
779
|
+
deps: ['HasuraConfig'],
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
provide: 'CategoryFilterRepository',
|
|
783
|
+
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
provide: CategoryFilterHasuraGraphQLRepository,
|
|
787
|
+
useFactory: (options) => {
|
|
788
|
+
return new CategoryFilterHasuraGraphQLRepository(options);
|
|
789
|
+
},
|
|
790
|
+
deps: ['HasuraConfig'],
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
provide: 'FilterOptionRepository',
|
|
794
|
+
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
provide: FilterOptionHasuraGraphQLRepository,
|
|
798
|
+
useFactory: (options) => {
|
|
799
|
+
return new FilterOptionHasuraGraphQLRepository(options);
|
|
800
|
+
},
|
|
801
|
+
deps: ['HasuraConfig'],
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
provide: 'FilterRepository',
|
|
805
|
+
useExisting: FilterHasuraGraphQLRepository,
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
provide: FilterHasuraGraphQLRepository,
|
|
809
|
+
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
810
|
+
return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
|
|
811
|
+
},
|
|
812
|
+
deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
813
|
+
},
|
|
814
|
+
],
|
|
815
|
+
}]
|
|
816
|
+
}] });
|
|
817
|
+
|
|
818
|
+
class AuthService {
|
|
819
|
+
constructor(angularFireAuth, userRepository) {
|
|
820
|
+
this.angularFireAuth = angularFireAuth;
|
|
821
|
+
this.userRepository = userRepository;
|
|
822
|
+
}
|
|
823
|
+
getAuthstate() {
|
|
824
|
+
const observables = [this.getFireUser(), this.getUser()];
|
|
825
|
+
return combineLatest(observables).pipe(map(([fireUser, user]) => ({
|
|
826
|
+
user,
|
|
827
|
+
isAnonymous: fireUser?.isAnonymous,
|
|
828
|
+
})));
|
|
829
|
+
}
|
|
830
|
+
getUser() {
|
|
831
|
+
return this.getFireUser().pipe(map((user) => user?.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
|
|
832
|
+
}
|
|
833
|
+
getTokenId() {
|
|
834
|
+
return from(getIdToken(this.angularFireAuth.currentUser));
|
|
835
|
+
}
|
|
836
|
+
getFireUser() {
|
|
837
|
+
return authState(this.angularFireAuth).pipe(catchError(() => of(null)));
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, deps: [{ token: i1$1.Auth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
841
|
+
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService });
|
|
842
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, decorators: [{
|
|
843
|
+
type: Injectable
|
|
844
|
+
}], ctorParameters: function () { return [{ type: i1$1.Auth }, { type: undefined, decorators: [{
|
|
845
|
+
type: Inject,
|
|
846
|
+
args: ['UserRepository']
|
|
847
|
+
}] }]; } });
|
|
848
|
+
|
|
849
|
+
class InvalidCouponError extends CustomError {
|
|
850
|
+
constructor(message) {
|
|
851
|
+
super(message);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
class GroupInvalidCouponError extends CustomError {
|
|
856
|
+
constructor(errors) {
|
|
857
|
+
super('Many coupon errors throw');
|
|
858
|
+
this.errors = errors;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
class CouponService {
|
|
863
|
+
constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
|
|
864
|
+
this.couponRepository = couponRepository;
|
|
865
|
+
this.defaultShop = defaultShop;
|
|
866
|
+
this.orderRepository = orderRepository;
|
|
867
|
+
this.categoryRepository = categoryRepository;
|
|
868
|
+
this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
|
|
869
|
+
}
|
|
870
|
+
checkCoupon(nickname, userEmail, checkoutType, plan, checkout, isSubscription) {
|
|
871
|
+
return from(this.couponRepository.find({
|
|
872
|
+
filters: {
|
|
873
|
+
nickname: { operator: Where.EQUALS, value: nickname },
|
|
874
|
+
active: { operator: Where.EQUALS, value: true },
|
|
1224
875
|
},
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
876
|
+
})).pipe(concatMap((coupons) => this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)), concatMap((coupon) => this.checkCouponUseAndLimit(coupon, userEmail, checkout)), map((coupon) => this.isValidCoupon(coupon, userEmail)), map((coupon) => coupon));
|
|
877
|
+
}
|
|
878
|
+
checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription) {
|
|
879
|
+
// Caso não ache nenhum cupom, retorna erro
|
|
880
|
+
if (coupons.count < 1) {
|
|
881
|
+
return throwError('Cupom inválido.');
|
|
882
|
+
}
|
|
883
|
+
// Get Primeiro Cupom (o find do repository retorna um array)
|
|
884
|
+
const coupon = coupons.data.shift();
|
|
885
|
+
// Verifica se o cupom é aplicavel na loja
|
|
886
|
+
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
887
|
+
// Cupon não aplicavel a loja retorna erro
|
|
888
|
+
if (!isInShop)
|
|
889
|
+
return throwError('Cupom inválido para loja.');
|
|
890
|
+
// Verifica se o coupon é aplicado no checkout que está sendo realizado
|
|
891
|
+
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
892
|
+
// Cupon não aplicavel ao checkout retorna erro
|
|
893
|
+
if (!isCheckoutType)
|
|
894
|
+
return throwError('Cupom inválido. Erro de checkout.');
|
|
895
|
+
// Verifica se o cupom é ou pode ser aplicado para subscription
|
|
896
|
+
if (checkoutType === CheckoutTypes.ALL || checkoutType === CheckoutTypes.SUBSCRIPTION) {
|
|
897
|
+
// Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
|
|
898
|
+
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
899
|
+
return throwError('Cupom inválido para sua assinatura.');
|
|
900
|
+
}
|
|
901
|
+
if (isSubscription)
|
|
902
|
+
return of(coupon);
|
|
903
|
+
// Verifica se possui o valor minimo de compra para utilização do cupom
|
|
904
|
+
const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
|
|
905
|
+
// Se não tem valor mínimo atingido, retorna erro
|
|
906
|
+
if (!hasMinSubTotal)
|
|
907
|
+
return throwError(`Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`);
|
|
908
|
+
return of(coupon);
|
|
909
|
+
}
|
|
910
|
+
isValidCoupon(coupon, userEmail) {
|
|
911
|
+
// Verifica a data de inicio de validade do cupom
|
|
912
|
+
if (coupon?.beginAt > new Date())
|
|
913
|
+
throw new InvalidCouponError('Cupom ainda não liberado.');
|
|
914
|
+
// Verifica a data de validade do cupom
|
|
915
|
+
if (coupon?.expiresIn < new Date())
|
|
916
|
+
throw new InvalidCouponError('Cupom expirado.');
|
|
917
|
+
return coupon;
|
|
918
|
+
}
|
|
919
|
+
async checkCouponUseAndLimit(coupon, userEmail, checkout) {
|
|
920
|
+
const orders = await this.orderRepository.find({
|
|
921
|
+
filters: {
|
|
922
|
+
coupon: { id: coupon.id },
|
|
923
|
+
payment: { status: 'paid' },
|
|
924
|
+
...(coupon.influencerEmail ? { user: { email: userEmail } } : {}),
|
|
1231
925
|
},
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
926
|
+
});
|
|
927
|
+
// orders que usuario ja fez com o cupom
|
|
928
|
+
const ordersUserCoupon = orders.data.filter((o) => o.user.email == userEmail);
|
|
929
|
+
// Verifica o limite de uso de cupom por usuario
|
|
930
|
+
if (coupon.useLimitPerUser && ordersUserCoupon.length)
|
|
931
|
+
throw new InvalidCouponError('Limite de uso por usuário atingido.');
|
|
932
|
+
// Verifica o limite de uso geral por usuario
|
|
933
|
+
if (coupon.useLimit && orders.data.length >= coupon.useLimit)
|
|
934
|
+
throw new InvalidCouponError('Limite de uso atingido.');
|
|
935
|
+
const validUser = this.userValidationAndSubscriptionStatus(coupon, checkout?.user);
|
|
936
|
+
if (!validUser)
|
|
937
|
+
throw new InvalidCouponError('Usuário não elegível.');
|
|
938
|
+
const hasProductCategories = await this.hasProductCategories(coupon, checkout);
|
|
939
|
+
if (!hasProductCategories)
|
|
940
|
+
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
941
|
+
return coupon;
|
|
942
|
+
}
|
|
943
|
+
calcDiscountSubscription(coupon, checkout) {
|
|
944
|
+
//
|
|
945
|
+
let discount = 0;
|
|
946
|
+
if (coupon.type === CouponTypes.ABSOLUTE)
|
|
947
|
+
discount = coupon.discount;
|
|
948
|
+
else if (coupon.type === CouponTypes.PERCENTAGE)
|
|
949
|
+
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount / 100);
|
|
950
|
+
return of(discount);
|
|
951
|
+
}
|
|
952
|
+
async calcDiscountShopping(coupon, checkout) {
|
|
953
|
+
let discount = 0;
|
|
954
|
+
switch (coupon.type) {
|
|
955
|
+
case CouponTypes.ABSOLUTE: {
|
|
956
|
+
discount = coupon.discount;
|
|
957
|
+
break;
|
|
958
|
+
}
|
|
959
|
+
case CouponTypes.PERCENTAGE: {
|
|
960
|
+
discount = await this.calcShoppingPercentageDiscount(coupon, checkout);
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return discount;
|
|
965
|
+
}
|
|
966
|
+
async calcShoppingPercentageDiscount(coupon, checkout) {
|
|
967
|
+
let discount = 0;
|
|
968
|
+
const shop = checkout.shop;
|
|
969
|
+
let lineItensDiscount = [];
|
|
970
|
+
const couponCategories = await this.getCouponCategoriesId(coupon);
|
|
971
|
+
if (coupon.productsCategories && coupon.productsCategories.length) {
|
|
972
|
+
lineItensDiscount = checkout.lineItems?.filter((i) => {
|
|
973
|
+
if (i.categories?.length) {
|
|
974
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
|
|
975
|
+
}
|
|
976
|
+
return true;
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
else {
|
|
980
|
+
lineItensDiscount = checkout.lineItems;
|
|
981
|
+
}
|
|
982
|
+
const subTotal = lineItensDiscount.reduce((acc, curr) => checkout.user?.isSubscriber && curr.price?.subscriberPrice
|
|
983
|
+
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
984
|
+
: acc + curr.pricePaid * curr.quantity, 0) || 0;
|
|
985
|
+
discount = subTotal * (coupon.discount / 100);
|
|
986
|
+
return discount;
|
|
987
|
+
}
|
|
988
|
+
hasMinSubTotal(coupon, checkout) {
|
|
989
|
+
if (!coupon.minSubTotalValue)
|
|
990
|
+
return true;
|
|
991
|
+
const shop = checkout.shop;
|
|
992
|
+
let subTotal = checkout.lineItems?.reduce((acc, curr) => checkout.user?.isSubscriber && curr.price?.subscriberPrice
|
|
993
|
+
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
994
|
+
: acc + curr.pricePaid * curr.quantity, 0) || 0;
|
|
995
|
+
if (coupon.minSubTotalValue <= subTotal)
|
|
996
|
+
return true;
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
async hasProductCategories(coupon, checkout) {
|
|
1000
|
+
if (!coupon.productsCategories || !coupon.productsCategories.length) {
|
|
1001
|
+
return true;
|
|
1002
|
+
}
|
|
1003
|
+
const couponCategories = await this.getCouponCategoriesId(coupon);
|
|
1004
|
+
const hasCategories = checkout.lineItems?.filter((i) => {
|
|
1005
|
+
if (!i.categories || !i.categories?.length)
|
|
1006
|
+
return true;
|
|
1007
|
+
return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
|
|
1008
|
+
});
|
|
1009
|
+
return hasCategories.length ? true : false;
|
|
1010
|
+
}
|
|
1011
|
+
userValidationAndSubscriptionStatus(coupon, user) {
|
|
1012
|
+
if (coupon.exclusivityType === Exclusivities.ALL_USERS)
|
|
1013
|
+
return true;
|
|
1014
|
+
if (!user)
|
|
1015
|
+
return true;
|
|
1016
|
+
// Verifica se o email do usuário é coorporativo
|
|
1017
|
+
if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
|
|
1018
|
+
throw new InvalidCouponError('Você não é colaborador.');
|
|
1019
|
+
// Verifica se o email do usuário é associado ao cupom de uso por usuario
|
|
1020
|
+
if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== user.email)
|
|
1021
|
+
throw new InvalidCouponError('Cupom não é válido para este usuário.');
|
|
1022
|
+
switch (coupon.exclusivityType) {
|
|
1023
|
+
case Exclusivities.ACTIVE_SUBSCRIBER:
|
|
1024
|
+
return user.isSubscriber ? true : false;
|
|
1025
|
+
case Exclusivities.INACTIVE_SUBSCRIBER:
|
|
1026
|
+
return user.isSubscriber ? false : true;
|
|
1027
|
+
case Exclusivities.NON_SUBSCRIBER:
|
|
1028
|
+
return user.isSubscriber ? false : true;
|
|
1029
|
+
}
|
|
1030
|
+
return true;
|
|
1031
|
+
}
|
|
1032
|
+
async getCouponCategoriesId(coupon) {
|
|
1033
|
+
let couponCategories = [];
|
|
1034
|
+
for (let index = 0; index < coupon.productsCategories.length; index++) {
|
|
1035
|
+
let c = await this.categoryRepository.get({
|
|
1036
|
+
id: coupon.productsCategories[index],
|
|
1037
|
+
});
|
|
1038
|
+
couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
|
|
1039
|
+
}
|
|
1040
|
+
return couponCategories;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
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 });
|
|
1044
|
+
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
1045
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
1046
|
+
type: Injectable,
|
|
1244
1047
|
args: [{
|
|
1245
|
-
|
|
1246
|
-
AngularElasticSeachModule,
|
|
1247
|
-
provideFirebaseApp((injector) => {
|
|
1248
|
-
const appName = injector.get(FIREBASE_APP_NAME);
|
|
1249
|
-
return appName
|
|
1250
|
-
? initializeApp$1(injector.get(FIREBASE_OPTIONS), appName)
|
|
1251
|
-
: initializeApp$1(injector.get(FIREBASE_OPTIONS));
|
|
1252
|
-
}),
|
|
1253
|
-
provideFirestore(() => getFirestore()),
|
|
1254
|
-
],
|
|
1255
|
-
providers: [
|
|
1256
|
-
{
|
|
1257
|
-
provide: 'FirestoreOptions',
|
|
1258
|
-
useFactory: (firestore, platformId) => ({
|
|
1259
|
-
firestore,
|
|
1260
|
-
interceptors: {
|
|
1261
|
-
request: (request) => {
|
|
1262
|
-
if (isPlatformBrowser(platformId))
|
|
1263
|
-
return request;
|
|
1264
|
-
const interval = setInterval(() => { }, 100);
|
|
1265
|
-
request.interval = interval;
|
|
1266
|
-
return request;
|
|
1267
|
-
},
|
|
1268
|
-
response: (response, request) => {
|
|
1269
|
-
if (isPlatformBrowser(platformId))
|
|
1270
|
-
return response;
|
|
1271
|
-
clearInterval(request.interval);
|
|
1272
|
-
return response;
|
|
1273
|
-
},
|
|
1274
|
-
},
|
|
1275
|
-
}),
|
|
1276
|
-
deps: [Firestore, PLATFORM_ID],
|
|
1277
|
-
},
|
|
1278
|
-
{
|
|
1279
|
-
provide: 'BeautyProfileRepository',
|
|
1280
|
-
useFactory: (config, userRepository) => {
|
|
1281
|
-
return new UserBeautyProfileFirestoreRepository(config, userRepository);
|
|
1282
|
-
},
|
|
1283
|
-
deps: ['FirestoreOptions', 'UserRepository'],
|
|
1284
|
-
},
|
|
1285
|
-
{
|
|
1286
|
-
provide: 'Buy2WinRepository',
|
|
1287
|
-
useFactory: (options) => {
|
|
1288
|
-
return new Buy2WinFirestoreRepository(options);
|
|
1289
|
-
},
|
|
1290
|
-
deps: ['FirestoreOptions'],
|
|
1291
|
-
},
|
|
1292
|
-
{
|
|
1293
|
-
provide: CategoryFirestoreRepository,
|
|
1294
|
-
useFactory: (options) => {
|
|
1295
|
-
return new CategoryFirestoreRepository(options);
|
|
1296
|
-
},
|
|
1297
|
-
deps: ['FirestoreOptions'],
|
|
1298
|
-
},
|
|
1299
|
-
{
|
|
1300
|
-
provide: 'CheckoutRepository',
|
|
1301
|
-
useFactory: (options) => {
|
|
1302
|
-
return new CheckoutFirestoreRepository(options);
|
|
1303
|
-
},
|
|
1304
|
-
deps: ['FirestoreOptions'],
|
|
1305
|
-
},
|
|
1306
|
-
{
|
|
1307
|
-
provide: 'CheckoutSubscriptionRepository',
|
|
1308
|
-
useFactory: (options) => {
|
|
1309
|
-
return new CheckoutSubscriptionFirestoreRepository(options);
|
|
1310
|
-
},
|
|
1311
|
-
deps: ['FirestoreOptions'],
|
|
1312
|
-
},
|
|
1313
|
-
{
|
|
1314
|
-
provide: 'CouponRepository',
|
|
1315
|
-
useFactory: (options) => {
|
|
1316
|
-
return new CouponFirestoreRepository(options);
|
|
1317
|
-
},
|
|
1318
|
-
deps: ['FirestoreOptions'],
|
|
1319
|
-
},
|
|
1320
|
-
{
|
|
1321
|
-
provide: 'CampaignHashtagRepository',
|
|
1322
|
-
useFactory: (options) => {
|
|
1323
|
-
return new CampaignHashtagFirestoreRepository(options);
|
|
1324
|
-
},
|
|
1325
|
-
deps: ['FirestoreOptions'],
|
|
1326
|
-
},
|
|
1327
|
-
{
|
|
1328
|
-
provide: 'CampaignDashboardRepository',
|
|
1329
|
-
useFactory: (options) => {
|
|
1330
|
-
return new CampaignDashboardFirestoreRepository(options);
|
|
1331
|
-
},
|
|
1332
|
-
deps: ['FirestoreOptions'],
|
|
1333
|
-
},
|
|
1334
|
-
{
|
|
1335
|
-
provide: 'EditionRepository',
|
|
1336
|
-
useFactory: (options, subscriptionRepository) => {
|
|
1337
|
-
return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
|
|
1338
|
-
},
|
|
1339
|
-
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
1340
|
-
},
|
|
1341
|
-
{
|
|
1342
|
-
provide: 'HomeRepository',
|
|
1343
|
-
useFactory: (options) => {
|
|
1344
|
-
return new HomeFirestoreRepository(options);
|
|
1345
|
-
},
|
|
1346
|
-
deps: ['FirestoreOptions'],
|
|
1347
|
-
},
|
|
1348
|
-
{
|
|
1349
|
-
provide: 'LeadRepository',
|
|
1350
|
-
useFactory: (options) => {
|
|
1351
|
-
return new LeadFirestoreRepository(options);
|
|
1352
|
-
},
|
|
1353
|
-
deps: ['FirestoreOptions'],
|
|
1354
|
-
},
|
|
1355
|
-
{
|
|
1356
|
-
provide: 'LegacyOrderRepository',
|
|
1357
|
-
useFactory: (options) => {
|
|
1358
|
-
return new LegacyOrderFirestoreRepository(options);
|
|
1359
|
-
},
|
|
1360
|
-
deps: ['FirestoreOptions'],
|
|
1361
|
-
},
|
|
1362
|
-
{
|
|
1363
|
-
provide: 'ShopMenuRepository',
|
|
1364
|
-
useFactory: (options) => {
|
|
1365
|
-
return new ShopMenuFirestoreRepository(options);
|
|
1366
|
-
},
|
|
1367
|
-
deps: ['FirestoreOptions'],
|
|
1368
|
-
},
|
|
1369
|
-
{
|
|
1370
|
-
provide: 'OrderRepository',
|
|
1371
|
-
useFactory: (options) => {
|
|
1372
|
-
return new OrderFirestoreRepository(options);
|
|
1373
|
-
},
|
|
1374
|
-
deps: ['FirestoreOptions'],
|
|
1375
|
-
},
|
|
1376
|
-
{
|
|
1377
|
-
provide: 'PaymentRepository',
|
|
1378
|
-
useFactory: (options) => {
|
|
1379
|
-
return new PaymentFirestoreRepository(options);
|
|
1380
|
-
},
|
|
1381
|
-
deps: ['FirestoreOptions'],
|
|
1382
|
-
},
|
|
1383
|
-
{
|
|
1384
|
-
provide: ProductFirestoreRepository,
|
|
1385
|
-
useFactory: (options) => {
|
|
1386
|
-
return new ProductFirestoreRepository(options);
|
|
1387
|
-
},
|
|
1388
|
-
deps: ['FirestoreOptions'],
|
|
1389
|
-
},
|
|
1390
|
-
{
|
|
1391
|
-
provide: 'ShopSettingsRepository',
|
|
1392
|
-
useFactory: (options) => {
|
|
1393
|
-
return new ShopSettingsFirestoreRepository(options);
|
|
1394
|
-
},
|
|
1395
|
-
deps: ['FirestoreOptions'],
|
|
1396
|
-
},
|
|
1397
|
-
{
|
|
1398
|
-
provide: 'SubscriptionPaymentRepository',
|
|
1399
|
-
useFactory: (options, subscriptionRepository) => {
|
|
1400
|
-
return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
|
|
1401
|
-
},
|
|
1402
|
-
deps: ['FirestoreOptions', 'SubscriptionRepository'],
|
|
1403
|
-
},
|
|
1404
|
-
{
|
|
1405
|
-
provide: 'SubscriptionPlanRepository',
|
|
1406
|
-
useFactory: (options) => {
|
|
1407
|
-
return new SubscriptionPlanFirestoreRepository(options);
|
|
1408
|
-
},
|
|
1409
|
-
deps: ['FirestoreOptions'],
|
|
1410
|
-
},
|
|
1411
|
-
{
|
|
1412
|
-
provide: 'SubscriptionProductRepository',
|
|
1413
|
-
useFactory: (options) => {
|
|
1414
|
-
return new SubscriptionProductFirestoreRepository(options);
|
|
1415
|
-
},
|
|
1416
|
-
deps: ['FirestoreOptions'],
|
|
1417
|
-
},
|
|
1418
|
-
{
|
|
1419
|
-
provide: 'SubscriptionRepository',
|
|
1420
|
-
useFactory: (options) => {
|
|
1421
|
-
return new SubscriptionFirestoreRepository(options);
|
|
1422
|
-
},
|
|
1423
|
-
deps: ['FirestoreOptions'],
|
|
1424
|
-
},
|
|
1425
|
-
{
|
|
1426
|
-
provide: 'UserRepository',
|
|
1427
|
-
useFactory: (options) => {
|
|
1428
|
-
return new UserFirestoreRepository(options);
|
|
1429
|
-
},
|
|
1430
|
-
deps: ['FirestoreOptions'],
|
|
1431
|
-
},
|
|
1432
|
-
{
|
|
1433
|
-
provide: 'UserAddressRepository',
|
|
1434
|
-
useFactory: (options, userRepository) => {
|
|
1435
|
-
return new UserAddressFirestoreRepository(options, userRepository);
|
|
1436
|
-
},
|
|
1437
|
-
deps: ['FirestoreOptions', 'UserRepository'],
|
|
1438
|
-
},
|
|
1439
|
-
{
|
|
1440
|
-
provide: 'UserPaymentMethodRepository',
|
|
1441
|
-
useFactory: (options, userRepository) => {
|
|
1442
|
-
return new UserPaymentMethodFirestoreRepository(options, userRepository);
|
|
1443
|
-
},
|
|
1444
|
-
deps: ['FirestoreOptions', 'UserRepository'],
|
|
1445
|
-
},
|
|
1446
|
-
{
|
|
1447
|
-
provide: ProductVariantFirestoreRepository,
|
|
1448
|
-
useFactory: (options, productRepository) => {
|
|
1449
|
-
return new ProductVariantFirestoreRepository(options, productRepository);
|
|
1450
|
-
},
|
|
1451
|
-
deps: ['FirestoreOptions', ProductFirestoreRepository],
|
|
1452
|
-
},
|
|
1453
|
-
],
|
|
1048
|
+
providedIn: 'root',
|
|
1454
1049
|
}]
|
|
1455
|
-
}]
|
|
1050
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1051
|
+
type: Inject,
|
|
1052
|
+
args: ['CouponRepository']
|
|
1053
|
+
}] }, { type: i3.Shops, decorators: [{
|
|
1054
|
+
type: Inject,
|
|
1055
|
+
args: [DEFAULT_SHOP]
|
|
1056
|
+
}] }, { type: undefined, decorators: [{
|
|
1057
|
+
type: Inject,
|
|
1058
|
+
args: ['OrderRepository']
|
|
1059
|
+
}] }, { type: undefined, decorators: [{
|
|
1060
|
+
type: Inject,
|
|
1061
|
+
args: ['CategoryRepository']
|
|
1062
|
+
}] }]; } });
|
|
1063
|
+
|
|
1064
|
+
class CheckoutService {
|
|
1065
|
+
constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
|
|
1066
|
+
this.couponService = couponService;
|
|
1067
|
+
this.checkoutRepository = checkoutRepository;
|
|
1068
|
+
this.orderRepository = orderRepository;
|
|
1069
|
+
this.userRepository = userRepository;
|
|
1070
|
+
this.defaultShop = defaultShop;
|
|
1071
|
+
}
|
|
1072
|
+
getCheckout(checkoutData) {
|
|
1073
|
+
const checkoutId = cookie.get('checkoutId');
|
|
1074
|
+
if (!isNil(checkoutId))
|
|
1075
|
+
return from(this.checkoutRepository.get({ id: checkoutId }));
|
|
1076
|
+
return from(this.createCheckout(checkoutData));
|
|
1077
|
+
}
|
|
1078
|
+
getUserByCheckout(checkoutId) {
|
|
1079
|
+
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'))));
|
|
1080
|
+
}
|
|
1081
|
+
updateCheckoutLineItems(checkout) {
|
|
1082
|
+
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
|
|
1083
|
+
}
|
|
1084
|
+
updateCheckoutUser(checkout) {
|
|
1085
|
+
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
|
|
1086
|
+
}
|
|
1087
|
+
clearCheckoutFromSession() {
|
|
1088
|
+
cookie.remove('checkoutId');
|
|
1089
|
+
return of();
|
|
1090
|
+
}
|
|
1091
|
+
calcDiscount(coupon) {
|
|
1092
|
+
return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
|
|
1093
|
+
}
|
|
1094
|
+
checkCoupon(nickname, checkoutType) {
|
|
1095
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.couponService
|
|
1096
|
+
.checkCoupon(nickname, checkout.user?.email, CheckoutTypes.ECOMMERCE, checkout.user.subscriptionPlan, checkout, false)
|
|
1097
|
+
.pipe()));
|
|
1098
|
+
}
|
|
1099
|
+
async createCheckout(checkoutData) {
|
|
1100
|
+
const checkout = await this.checkoutRepository.create({
|
|
1101
|
+
createdAt: new Date(),
|
|
1102
|
+
...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
1103
|
+
shop: checkoutData?.shop || this.defaultShop,
|
|
1104
|
+
});
|
|
1105
|
+
cookie.set('checkoutId', checkout.id);
|
|
1106
|
+
return checkout;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1110
|
+
CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
|
|
1111
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
|
|
1112
|
+
type: Injectable
|
|
1113
|
+
}], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
|
|
1114
|
+
type: Inject,
|
|
1115
|
+
args: ['CheckoutRepository']
|
|
1116
|
+
}] }, { type: undefined, decorators: [{
|
|
1117
|
+
type: Inject,
|
|
1118
|
+
args: ['OrderRepository']
|
|
1119
|
+
}] }, { type: undefined, decorators: [{
|
|
1120
|
+
type: Inject,
|
|
1121
|
+
args: ['UserRepository']
|
|
1122
|
+
}] }, { type: i3.Shops, decorators: [{
|
|
1123
|
+
type: Inject,
|
|
1124
|
+
args: [DEFAULT_SHOP]
|
|
1125
|
+
}] }]; } });
|
|
1126
|
+
|
|
1127
|
+
class CartService {
|
|
1128
|
+
constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
|
|
1129
|
+
this.authService = authService;
|
|
1130
|
+
this.checkoutService = checkoutService;
|
|
1131
|
+
this.defaultShop = defaultShop;
|
|
1132
|
+
this.productRepository = productRepository;
|
|
1133
|
+
this.categoryRepository = categoryRepository;
|
|
1134
|
+
this.variantRepository = variantRepository;
|
|
1135
|
+
this.buy2WinRepository = buy2WinRepository;
|
|
1136
|
+
this.cartSubject = new Subject();
|
|
1137
|
+
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
1138
|
+
const items = [];
|
|
1139
|
+
const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
1140
|
+
if (index > -1) {
|
|
1141
|
+
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
1142
|
+
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
1143
|
+
}
|
|
1144
|
+
else
|
|
1145
|
+
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
1146
|
+
return this.checkoutService
|
|
1147
|
+
.updateCheckoutLineItems(checkoutLoaded)
|
|
1148
|
+
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
1149
|
+
}));
|
|
1150
|
+
this.generateCartObject = (items) => items?.reduce((cart, item) => ({
|
|
1151
|
+
...cart,
|
|
1152
|
+
[item.id]: LineItem.toInstance({
|
|
1153
|
+
...(cart[item.id] || item),
|
|
1154
|
+
quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
|
|
1155
|
+
}),
|
|
1156
|
+
}), {}) || {};
|
|
1157
|
+
this.buildLineItem = async ({ checkout, item, quantity, }) => {
|
|
1158
|
+
const product = await this.getProductData(item.id);
|
|
1159
|
+
item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
|
|
1160
|
+
if (this.checkMaxStock(item, quantity || 0))
|
|
1161
|
+
throw new Error('Desculpe! Temos apenas ' + item.stock?.quantity + ' em estoque.');
|
|
1162
|
+
const image = item.image || item.images?.shift();
|
|
1163
|
+
const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
|
|
1164
|
+
const isGift = item.isGift || null;
|
|
1165
|
+
const pricePaid = this.getProductPrice({
|
|
1166
|
+
product: item,
|
|
1167
|
+
shop: checkout.shop || this.defaultShop,
|
|
1168
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1169
|
+
});
|
|
1170
|
+
RoundProductPricesHelper.roundProductPrices(item);
|
|
1171
|
+
return {
|
|
1172
|
+
checkout,
|
|
1173
|
+
lineItem: LineItem.toInstance({
|
|
1174
|
+
id,
|
|
1175
|
+
name: name ?? product.name,
|
|
1176
|
+
EAN: EAN ?? product.EAN,
|
|
1177
|
+
brand: product.brand,
|
|
1178
|
+
slug: slug ?? product.slug,
|
|
1179
|
+
sku: sku ?? product.sku,
|
|
1180
|
+
stock,
|
|
1181
|
+
price: this.roundPrice(price),
|
|
1182
|
+
image,
|
|
1183
|
+
weight: weight ?? product.weight,
|
|
1184
|
+
quantity: (item.quantity || 0) + (quantity || 0),
|
|
1185
|
+
pricePaid,
|
|
1186
|
+
categories: product.categories ?? [],
|
|
1187
|
+
isGift: isGift ?? null,
|
|
1188
|
+
costPrice: product.costPrice ?? 0,
|
|
1189
|
+
type,
|
|
1190
|
+
}),
|
|
1191
|
+
};
|
|
1192
|
+
};
|
|
1193
|
+
this.getProductPrice = ({ product, isSubscriber, }) => {
|
|
1194
|
+
const info = product.price;
|
|
1195
|
+
if (product.isGift)
|
|
1196
|
+
return 0;
|
|
1197
|
+
return isSubscriber && info.subscriberPrice > 0
|
|
1198
|
+
? Number(info.subscriberPrice.toFixed(2))
|
|
1199
|
+
: Number(info.price.toFixed(2));
|
|
1200
|
+
};
|
|
1201
|
+
this.checkMaxStock = (item, quantity) => {
|
|
1202
|
+
const maxStock = item.stock?.quantity || 0;
|
|
1203
|
+
const currentItemAmount = item.quantity || 0;
|
|
1204
|
+
return currentItemAmount + quantity > maxStock;
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
addItem(item, quantity = 1) {
|
|
1208
|
+
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)));
|
|
1209
|
+
}
|
|
1210
|
+
decreaseItem(item) {
|
|
1211
|
+
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1212
|
+
const checkoutItem = checkout.lineItems?.find((lineItem) => lineItem.id === item.id);
|
|
1213
|
+
if (!isNil(checkoutItem))
|
|
1214
|
+
checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
|
|
1215
|
+
return checkout;
|
|
1216
|
+
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1217
|
+
}
|
|
1218
|
+
getCart(checkout) {
|
|
1219
|
+
this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
|
|
1220
|
+
return this.cartSubject;
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* @deprecated The method should not be used
|
|
1224
|
+
*/
|
|
1225
|
+
getVariantPriceDiscount(item) {
|
|
1226
|
+
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)));
|
|
1227
|
+
}
|
|
1228
|
+
removeItem(item) {
|
|
1229
|
+
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1230
|
+
const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
|
|
1231
|
+
if (index >= 0)
|
|
1232
|
+
checkout.lineItems.splice(index, 1);
|
|
1233
|
+
return checkout;
|
|
1234
|
+
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1235
|
+
}
|
|
1236
|
+
updateUserCart(user) {
|
|
1237
|
+
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => this.checkoutService
|
|
1238
|
+
.updateCheckoutLineItems(Checkout.toInstance({
|
|
1239
|
+
...checkout.toPlain(),
|
|
1240
|
+
lineItems: checkout.lineItems?.length
|
|
1241
|
+
? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
|
|
1242
|
+
: [],
|
|
1243
|
+
}))
|
|
1244
|
+
.toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1245
|
+
}
|
|
1246
|
+
clearCart() {
|
|
1247
|
+
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1248
|
+
this.checkoutService.clearCheckoutFromSession();
|
|
1249
|
+
return checkout;
|
|
1250
|
+
}), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
|
|
1251
|
+
}
|
|
1252
|
+
buildCartFromCheckout(checkoutData) {
|
|
1253
|
+
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
1254
|
+
}
|
|
1255
|
+
roundPrice(productPrice) {
|
|
1256
|
+
const { price, fullPrice, subscriberPrice } = productPrice;
|
|
1257
|
+
return {
|
|
1258
|
+
...productPrice,
|
|
1259
|
+
price: Number(price.toFixed(2)),
|
|
1260
|
+
fullPrice: Number(fullPrice.toFixed(2)),
|
|
1261
|
+
...(subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }),
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
async getProductData(productId) {
|
|
1265
|
+
let product;
|
|
1266
|
+
let variant;
|
|
1267
|
+
try {
|
|
1268
|
+
product = await this.productRepository.get({ id: productId });
|
|
1269
|
+
}
|
|
1270
|
+
catch (error) {
|
|
1271
|
+
if (!(error instanceof NotFoundError))
|
|
1272
|
+
throw error;
|
|
1273
|
+
const { data: variants } = await this.variantRepository.find({ filters: { id: productId } });
|
|
1274
|
+
variant = variants.shift();
|
|
1275
|
+
if (!variant)
|
|
1276
|
+
throw error;
|
|
1277
|
+
product = await this.productRepository.get({ id: variant.productId });
|
|
1278
|
+
}
|
|
1279
|
+
return {
|
|
1280
|
+
...product.toPlain(),
|
|
1281
|
+
...(variant && { ...variant.toPlain() }),
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
getGifts() {
|
|
1285
|
+
return this.checkoutService.getCheckout().pipe(mergeMap(async (checkout) => {
|
|
1286
|
+
const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
|
|
1287
|
+
if (!notGiftItems.length)
|
|
1288
|
+
return { ...checkout, lineItems: [] };
|
|
1289
|
+
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
1290
|
+
const campaigns = await this.buy2WinRepository
|
|
1291
|
+
.find({
|
|
1292
|
+
filters: {
|
|
1293
|
+
active: { operator: Where.EQUALS, value: true },
|
|
1294
|
+
shop: { operator: Where.EQUALS, value: this.defaultShop },
|
|
1295
|
+
},
|
|
1296
|
+
})
|
|
1297
|
+
.then((data) => data.data);
|
|
1298
|
+
if (!campaigns.length)
|
|
1299
|
+
return { ...checkout, lineItems: notGiftItems };
|
|
1300
|
+
const elegibleCampaigns = [];
|
|
1301
|
+
for (const campaign of campaigns) {
|
|
1302
|
+
const today = new Date();
|
|
1303
|
+
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
1304
|
+
continue;
|
|
1305
|
+
if (campaign.activeCategory) {
|
|
1306
|
+
const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
|
|
1307
|
+
const categoriesCampaingFullTree = [];
|
|
1308
|
+
for (const id of categoriesCampaing) {
|
|
1309
|
+
const children = await this.categoryRepository.getChildren(parseInt(id));
|
|
1310
|
+
categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
|
|
1311
|
+
}
|
|
1312
|
+
const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
|
|
1313
|
+
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
1314
|
+
if (!l.categories || !l.categories?.length)
|
|
1315
|
+
return true;
|
|
1316
|
+
return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
|
|
1317
|
+
});
|
|
1318
|
+
if (filterProductsCategories.length) {
|
|
1319
|
+
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
1320
|
+
if (cartTotalCategories >= campaign.cartValueMin)
|
|
1321
|
+
elegibleCampaigns.push(campaign);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
else {
|
|
1325
|
+
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
1326
|
+
if (campaign.cartValue <= cartTotal)
|
|
1327
|
+
elegibleCampaigns.push(campaign);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
if (!elegibleCampaigns.length)
|
|
1332
|
+
return { ...checkout, lineItems: notGiftItems };
|
|
1333
|
+
const campaingnProducts = [];
|
|
1334
|
+
for (const campaign of elegibleCampaigns) {
|
|
1335
|
+
let elegibleProducts = [];
|
|
1336
|
+
for (const product of campaign.products) {
|
|
1337
|
+
const { data: productData } = await this.productRepository.find({ filters: { sku: product } });
|
|
1338
|
+
if (!productData.length)
|
|
1339
|
+
continue;
|
|
1340
|
+
const gift = productData.shift();
|
|
1341
|
+
if (gift.stock.quantity < 1)
|
|
1342
|
+
continue;
|
|
1343
|
+
elegibleProducts.push(gift);
|
|
1344
|
+
}
|
|
1345
|
+
campaingnProducts.push(elegibleProducts);
|
|
1346
|
+
}
|
|
1347
|
+
if (!campaingnProducts.length)
|
|
1348
|
+
return { ...checkout, lineItems: notGiftItems };
|
|
1349
|
+
const gifts = this.giftToLineItems([].concat(...campaingnProducts));
|
|
1350
|
+
return { ...checkout, lineItems: notGiftItems.concat(gifts) };
|
|
1351
|
+
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1352
|
+
}
|
|
1353
|
+
giftToLineItems(items) {
|
|
1354
|
+
return items.map((item) => {
|
|
1355
|
+
const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
1356
|
+
const image = item?.miniatures?.length ? item.miniatures[0] : item.images[0];
|
|
1357
|
+
return LineItem.toInstance({
|
|
1358
|
+
brand,
|
|
1359
|
+
categories,
|
|
1360
|
+
id: id.toString(),
|
|
1361
|
+
name,
|
|
1362
|
+
price,
|
|
1363
|
+
sku,
|
|
1364
|
+
slug,
|
|
1365
|
+
stock,
|
|
1366
|
+
weight,
|
|
1367
|
+
EAN,
|
|
1368
|
+
image,
|
|
1369
|
+
pricePaid: 0,
|
|
1370
|
+
quantity: 1,
|
|
1371
|
+
isGift: true,
|
|
1372
|
+
});
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
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 });
|
|
1377
|
+
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
1378
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
1379
|
+
type: Injectable
|
|
1380
|
+
}], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
|
|
1381
|
+
type: Inject,
|
|
1382
|
+
args: [DEFAULT_SHOP]
|
|
1383
|
+
}] }, { type: undefined, decorators: [{
|
|
1384
|
+
type: Inject,
|
|
1385
|
+
args: ['ProductRepository']
|
|
1386
|
+
}] }, { type: undefined, decorators: [{
|
|
1387
|
+
type: Inject,
|
|
1388
|
+
args: ['CategoryRepository']
|
|
1389
|
+
}] }, { type: undefined, decorators: [{
|
|
1390
|
+
type: Inject,
|
|
1391
|
+
args: ['VariantRepository']
|
|
1392
|
+
}] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
|
|
1393
|
+
type: Inject,
|
|
1394
|
+
args: ['Buy2WinRepository']
|
|
1395
|
+
}] }]; } });
|
|
1456
1396
|
|
|
1457
|
-
class
|
|
1458
|
-
|
|
1397
|
+
class CatalogService {
|
|
1398
|
+
constructor() {
|
|
1399
|
+
this.buildFilterQuery = (category, filters) => { };
|
|
1400
|
+
this.buildSortQuery = (sort) => {
|
|
1401
|
+
const query = {
|
|
1402
|
+
stock: 'desc',
|
|
1403
|
+
gender: 'asc',
|
|
1404
|
+
};
|
|
1405
|
+
return query;
|
|
1406
|
+
};
|
|
1407
|
+
this.buildLimitQuery = (options) => {
|
|
1408
|
+
const limit = options?.perPage || 20;
|
|
1409
|
+
return {
|
|
1410
|
+
limit,
|
|
1411
|
+
offset: ((options?.page || 1) - 1) * limit,
|
|
1412
|
+
};
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
fetchProducts(category, options) {
|
|
1459
1416
|
return {
|
|
1460
|
-
|
|
1461
|
-
|
|
1417
|
+
products: [],
|
|
1418
|
+
pages: 1,
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
class CategoryService {
|
|
1424
|
+
fetchSubCategories(category) {
|
|
1425
|
+
return [];
|
|
1426
|
+
}
|
|
1427
|
+
fetchFilterOptions(category, filters) {
|
|
1428
|
+
return [];
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
var ProductSorts;
|
|
1433
|
+
(function (ProductSorts) {
|
|
1434
|
+
ProductSorts["MOST_RELEVANT"] = "most-relevant";
|
|
1435
|
+
ProductSorts["BEST_SELLER"] = "best-sellers";
|
|
1436
|
+
ProductSorts["BIGGEST_PRICE"] = "biggest-price";
|
|
1437
|
+
ProductSorts["LOWEST_PRICE"] = "lowest-price";
|
|
1438
|
+
ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
|
|
1439
|
+
ProductSorts["BEST_RATING"] = "best-rating";
|
|
1440
|
+
})(ProductSorts || (ProductSorts = {}));
|
|
1441
|
+
|
|
1442
|
+
class CategoryWithTree extends Category {
|
|
1443
|
+
}
|
|
1444
|
+
__decorate([
|
|
1445
|
+
Type(() => CategoryWithTree),
|
|
1446
|
+
__metadata("design:type", Array)
|
|
1447
|
+
], CategoryWithTree.prototype, "children", void 0);
|
|
1448
|
+
|
|
1449
|
+
class CheckoutSubscriptionService {
|
|
1450
|
+
constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
|
|
1451
|
+
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
1452
|
+
this.subscriptionRepository = subscriptionRepository;
|
|
1453
|
+
this.couponService = couponService;
|
|
1454
|
+
}
|
|
1455
|
+
getCheckoutSubscription(checkoutData) {
|
|
1456
|
+
const checkoutId = cookie.get('checkoutSubscriptionId');
|
|
1457
|
+
if (!isNil(checkoutId))
|
|
1458
|
+
return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
|
|
1459
|
+
return from(this.createCheckoutSubscription(checkoutData));
|
|
1460
|
+
}
|
|
1461
|
+
async createCheckoutSubscription(checkoutData) {
|
|
1462
|
+
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
1463
|
+
createdAt: new Date(),
|
|
1464
|
+
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
1465
|
+
});
|
|
1466
|
+
cookie.set('checkoutSubscriptionId', checkout.id);
|
|
1467
|
+
return checkout;
|
|
1468
|
+
}
|
|
1469
|
+
clearCheckoutSubscriptionFromSession() {
|
|
1470
|
+
cookie.remove('checkoutSubscriptionId');
|
|
1471
|
+
return of();
|
|
1472
|
+
}
|
|
1473
|
+
checkCoupon(nickname, userEmail) {
|
|
1474
|
+
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
1475
|
+
.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
|
|
1476
|
+
.pipe()));
|
|
1477
|
+
}
|
|
1478
|
+
calcDiscountSubscription(coupon) {
|
|
1479
|
+
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1483
|
+
CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
|
|
1484
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
1485
|
+
type: Injectable
|
|
1486
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1487
|
+
type: Inject,
|
|
1488
|
+
args: ['CheckoutSubscriptionRepository']
|
|
1489
|
+
}] }, { type: undefined, decorators: [{
|
|
1490
|
+
type: Inject,
|
|
1491
|
+
args: ['SubscriptionRepository']
|
|
1492
|
+
}] }, { type: CouponService }]; } });
|
|
1493
|
+
|
|
1494
|
+
class HomeShopService {
|
|
1495
|
+
constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
|
|
1496
|
+
this.categoryRepository = categoryRepository;
|
|
1497
|
+
this.homeRepository = homeRepository;
|
|
1498
|
+
this.productRepository = productRepository;
|
|
1499
|
+
this.defaultShop = defaultShop;
|
|
1500
|
+
this.buildCategoryGroupWithRequiredData = (group) => ({
|
|
1501
|
+
category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
|
|
1502
|
+
products: group?.products?.map((product) => Product.toInstance(pick(product?.toPlain() || {}, [
|
|
1503
|
+
'id',
|
|
1504
|
+
'price',
|
|
1505
|
+
'reviews',
|
|
1506
|
+
'hasVariants',
|
|
1507
|
+
'slug',
|
|
1508
|
+
'sku',
|
|
1509
|
+
'stock',
|
|
1510
|
+
'costPrice',
|
|
1511
|
+
'images',
|
|
1512
|
+
'miniatures',
|
|
1513
|
+
'name',
|
|
1514
|
+
'weight',
|
|
1515
|
+
'rate',
|
|
1516
|
+
'type',
|
|
1517
|
+
]))) || [],
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
get homeId() {
|
|
1521
|
+
if (this.defaultShop === Shops.GLAMSHOP)
|
|
1522
|
+
return 'glamshop';
|
|
1523
|
+
if (this.defaultShop === Shops.MENSMARKET)
|
|
1524
|
+
return 'mens_market';
|
|
1525
|
+
return null;
|
|
1526
|
+
}
|
|
1527
|
+
getHomeData() {
|
|
1528
|
+
return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
|
|
1529
|
+
? of(home)
|
|
1530
|
+
: forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
|
|
1531
|
+
discoverProducts,
|
|
1532
|
+
featuredProducts,
|
|
1533
|
+
verticalProducts,
|
|
1534
|
+
})), concatMap((data) => this.saveHomeData(data)))));
|
|
1535
|
+
}
|
|
1536
|
+
getBanners(type) {
|
|
1537
|
+
return this.getHomeConfiguration().pipe(map((home) => {
|
|
1538
|
+
if (type === 'brand')
|
|
1539
|
+
return home.brandsCarousel;
|
|
1540
|
+
if (type === 'buyToWin')
|
|
1541
|
+
return [home.buyToWinBanner];
|
|
1542
|
+
if (type === 'block')
|
|
1543
|
+
return home.blockBanners;
|
|
1544
|
+
if (type === 'blog')
|
|
1545
|
+
return [home.blogBanner];
|
|
1546
|
+
return [];
|
|
1547
|
+
}));
|
|
1548
|
+
}
|
|
1549
|
+
getMinValueForFreeShipping() {
|
|
1550
|
+
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
1551
|
+
}
|
|
1552
|
+
getDiscoverProducts() {
|
|
1553
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
1554
|
+
}
|
|
1555
|
+
getFeaturedProducts() {
|
|
1556
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
1557
|
+
}
|
|
1558
|
+
getVerticalProducts() {
|
|
1559
|
+
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({
|
|
1560
|
+
filters: { categories: { operator: Where.IN, value: [category.id] } },
|
|
1561
|
+
limits: { limit: 12 },
|
|
1562
|
+
})).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
|
|
1563
|
+
}
|
|
1564
|
+
getHomeConfiguration() {
|
|
1565
|
+
return of(this.homeConfiguration).pipe(concatMap((home) => home
|
|
1566
|
+
? of(home)
|
|
1567
|
+
: !this.homeId
|
|
1568
|
+
? throwError(new RequiredArgumentError(['homeId']))
|
|
1569
|
+
: from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
|
|
1570
|
+
}
|
|
1571
|
+
saveHomeData(homeData) {
|
|
1572
|
+
const data = {
|
|
1573
|
+
createdAt: new Date(),
|
|
1574
|
+
expiresAt: add(new Date(), { hours: 1 }),
|
|
1575
|
+
data: homeData,
|
|
1462
1576
|
};
|
|
1577
|
+
return from(this.homeRepository.update({
|
|
1578
|
+
id: this.homeId,
|
|
1579
|
+
data,
|
|
1580
|
+
})).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
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 });
|
|
1584
|
+
HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
|
|
1585
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
|
|
1586
|
+
type: Injectable
|
|
1587
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1588
|
+
type: Inject,
|
|
1589
|
+
args: ['CategoryRepository']
|
|
1590
|
+
}] }, { type: undefined, decorators: [{
|
|
1591
|
+
type: Inject,
|
|
1592
|
+
args: ['HomeRepository']
|
|
1593
|
+
}] }, { type: undefined, decorators: [{
|
|
1594
|
+
type: Inject,
|
|
1595
|
+
args: ['ProductRepository']
|
|
1596
|
+
}] }, { type: i3.Shops, decorators: [{
|
|
1597
|
+
type: Inject,
|
|
1598
|
+
args: [DEFAULT_SHOP]
|
|
1599
|
+
}] }]; } });
|
|
1600
|
+
|
|
1601
|
+
class OrderService {
|
|
1602
|
+
constructor(angularFirestore, orderRepository) {
|
|
1603
|
+
this.angularFirestore = angularFirestore;
|
|
1604
|
+
this.orderRepository = orderRepository;
|
|
1605
|
+
this.orderSubject = new Subject();
|
|
1606
|
+
}
|
|
1607
|
+
getOrder(id) {
|
|
1608
|
+
docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
|
|
1609
|
+
.pipe(map((doc) => Order.toInstance(doc.data())))
|
|
1610
|
+
.subscribe((doc) => this.orderSubject.next(doc));
|
|
1611
|
+
return this.orderSubject;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, deps: [{ token: i1$2.Firestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1615
|
+
OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
|
|
1616
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
1617
|
+
type: Injectable
|
|
1618
|
+
}], ctorParameters: function () { return [{ type: i1$2.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
|
|
1619
|
+
type: Inject,
|
|
1620
|
+
args: ['OrderRepository']
|
|
1621
|
+
}] }]; } });
|
|
1622
|
+
|
|
1623
|
+
class ShippingService {
|
|
1624
|
+
constructor(http, apiUrl, homeService) {
|
|
1625
|
+
this.http = http;
|
|
1626
|
+
this.apiUrl = apiUrl;
|
|
1627
|
+
this.homeService = homeService;
|
|
1628
|
+
}
|
|
1629
|
+
getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
|
|
1630
|
+
return combineLatest([
|
|
1631
|
+
this.homeService.getHomeData(),
|
|
1632
|
+
this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
|
|
1633
|
+
]).pipe(map(([datas, shippingMethodsResponse]) => {
|
|
1634
|
+
let shippingMethods = shippingMethodsResponse.result;
|
|
1635
|
+
if (!shippingMethods.length)
|
|
1636
|
+
return [];
|
|
1637
|
+
shippingMethods = shippingMethods.map((shippingMethod) => {
|
|
1638
|
+
if (shippingMethod.ShippingCompanyName == 'Same Day EG')
|
|
1639
|
+
shippingMethod.ShippingCompanyName = 'Same Day';
|
|
1640
|
+
return shippingMethod;
|
|
1641
|
+
});
|
|
1642
|
+
const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
|
|
1643
|
+
if (this.isHolidays(datasSameDayNotAvaliable)) {
|
|
1644
|
+
shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
|
|
1645
|
+
}
|
|
1646
|
+
if (totalPrice >= 200) {
|
|
1647
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
1648
|
+
if (s.serviceName !== 'Same Day')
|
|
1649
|
+
return { ...s, totalPrice: 0 };
|
|
1650
|
+
else
|
|
1651
|
+
return s;
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
if (shop == Shops.GLAMSHOP)
|
|
1655
|
+
return shippingMethods;
|
|
1656
|
+
if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
|
|
1657
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
1658
|
+
if (s.serviceName == 'Same Day')
|
|
1659
|
+
return { ...s, totalPrice: s.totalPrice / 2 };
|
|
1660
|
+
else
|
|
1661
|
+
return { ...s, totalPrice: 0 };
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
|
|
1665
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
1666
|
+
return { ...s, totalPrice: s.totalPrice / 2 };
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
return shippingMethods;
|
|
1670
|
+
}));
|
|
1671
|
+
}
|
|
1672
|
+
isFreeShippingBySubscription(shop, subscriptionPlan) {
|
|
1673
|
+
if (!subscriptionPlan)
|
|
1674
|
+
return false;
|
|
1675
|
+
if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
|
|
1676
|
+
return true;
|
|
1677
|
+
return false;
|
|
1678
|
+
}
|
|
1679
|
+
isHalfShippingBySubscription(shop, subscriptionPlan) {
|
|
1680
|
+
if (!subscriptionPlan)
|
|
1681
|
+
return false;
|
|
1682
|
+
if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
|
|
1683
|
+
return true;
|
|
1684
|
+
}
|
|
1685
|
+
return false;
|
|
1686
|
+
}
|
|
1687
|
+
isHolidays(datas) {
|
|
1688
|
+
const today = new Date();
|
|
1689
|
+
for (const key in datas) {
|
|
1690
|
+
let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
|
|
1691
|
+
let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
|
|
1692
|
+
if (start > end)
|
|
1693
|
+
end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
|
|
1694
|
+
if (today >= start && today <= end)
|
|
1695
|
+
return true;
|
|
1696
|
+
}
|
|
1697
|
+
return false;
|
|
1463
1698
|
}
|
|
1464
1699
|
}
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
interceptors: {
|
|
1474
|
-
request: (request) => {
|
|
1475
|
-
if (isPlatformBrowser(platformId))
|
|
1476
|
-
return request;
|
|
1477
|
-
const interval = setInterval(() => { }, 100);
|
|
1478
|
-
request.interval = interval;
|
|
1479
|
-
return request;
|
|
1480
|
-
},
|
|
1481
|
-
response: (response, request) => {
|
|
1482
|
-
if (isPlatformBrowser(platformId))
|
|
1483
|
-
return response;
|
|
1484
|
-
clearInterval(request.interval);
|
|
1485
|
-
return response;
|
|
1486
|
-
},
|
|
1487
|
-
},
|
|
1488
|
-
}),
|
|
1489
|
-
deps: [HASURA_OPTIONS, PLATFORM_ID],
|
|
1490
|
-
},
|
|
1491
|
-
{
|
|
1492
|
-
provide: 'CategoryRepository',
|
|
1493
|
-
useExisting: CategoryHasuraGraphQLRepository,
|
|
1494
|
-
},
|
|
1495
|
-
{
|
|
1496
|
-
provide: CategoryHasuraGraphQLRepository,
|
|
1497
|
-
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
1498
|
-
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
1499
|
-
},
|
|
1500
|
-
deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1501
|
-
},
|
|
1502
|
-
{
|
|
1503
|
-
provide: 'ProductRepository',
|
|
1504
|
-
useExisting: ProductHasuraGraphQLRepository,
|
|
1505
|
-
},
|
|
1506
|
-
{
|
|
1507
|
-
provide: ProductHasuraGraphQLRepository,
|
|
1508
|
-
useFactory: (hasuraConfig) => {
|
|
1509
|
-
return new ProductHasuraGraphQLRepository(hasuraConfig);
|
|
1510
|
-
},
|
|
1511
|
-
deps: ['HasuraConfig'],
|
|
1512
|
-
},
|
|
1513
|
-
{
|
|
1514
|
-
provide: 'VariantRepository',
|
|
1515
|
-
useExisting: VariantHasuraGraphQLRepository,
|
|
1516
|
-
},
|
|
1517
|
-
{
|
|
1518
|
-
provide: VariantHasuraGraphQLRepository,
|
|
1519
|
-
useFactory: (hasuraConfig) => {
|
|
1520
|
-
return new VariantHasuraGraphQLRepository(hasuraConfig);
|
|
1521
|
-
},
|
|
1522
|
-
deps: ['HasuraConfig'],
|
|
1523
|
-
},
|
|
1524
|
-
{
|
|
1525
|
-
provide: 'CategoryFilterRepository',
|
|
1526
|
-
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1527
|
-
},
|
|
1528
|
-
{
|
|
1529
|
-
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1530
|
-
useFactory: (options) => {
|
|
1531
|
-
return new CategoryFilterHasuraGraphQLRepository(options);
|
|
1532
|
-
},
|
|
1533
|
-
deps: ['HasuraConfig'],
|
|
1534
|
-
},
|
|
1535
|
-
{
|
|
1536
|
-
provide: 'FilterOptionRepository',
|
|
1537
|
-
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1538
|
-
},
|
|
1539
|
-
{
|
|
1540
|
-
provide: FilterOptionHasuraGraphQLRepository,
|
|
1541
|
-
useFactory: (options) => {
|
|
1542
|
-
return new FilterOptionHasuraGraphQLRepository(options);
|
|
1543
|
-
},
|
|
1544
|
-
deps: ['HasuraConfig'],
|
|
1545
|
-
},
|
|
1546
|
-
{
|
|
1547
|
-
provide: 'FilterRepository',
|
|
1548
|
-
useExisting: FilterHasuraGraphQLRepository,
|
|
1549
|
-
},
|
|
1550
|
-
{
|
|
1551
|
-
provide: FilterHasuraGraphQLRepository,
|
|
1552
|
-
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
1553
|
-
return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
|
|
1554
|
-
},
|
|
1555
|
-
deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1556
|
-
},
|
|
1557
|
-
] });
|
|
1558
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
|
|
1559
|
-
type: NgModule,
|
|
1560
|
-
args: [{
|
|
1561
|
-
providers: [
|
|
1562
|
-
{
|
|
1563
|
-
provide: 'HasuraConfig',
|
|
1564
|
-
useFactory: (options, platformId) => ({
|
|
1565
|
-
endpoint: options.endpoint,
|
|
1566
|
-
authOptions: options.credentials,
|
|
1567
|
-
interceptors: {
|
|
1568
|
-
request: (request) => {
|
|
1569
|
-
if (isPlatformBrowser(platformId))
|
|
1570
|
-
return request;
|
|
1571
|
-
const interval = setInterval(() => { }, 100);
|
|
1572
|
-
request.interval = interval;
|
|
1573
|
-
return request;
|
|
1574
|
-
},
|
|
1575
|
-
response: (response, request) => {
|
|
1576
|
-
if (isPlatformBrowser(platformId))
|
|
1577
|
-
return response;
|
|
1578
|
-
clearInterval(request.interval);
|
|
1579
|
-
return response;
|
|
1580
|
-
},
|
|
1581
|
-
},
|
|
1582
|
-
}),
|
|
1583
|
-
deps: [HASURA_OPTIONS, PLATFORM_ID],
|
|
1584
|
-
},
|
|
1585
|
-
{
|
|
1586
|
-
provide: 'CategoryRepository',
|
|
1587
|
-
useExisting: CategoryHasuraGraphQLRepository,
|
|
1588
|
-
},
|
|
1589
|
-
{
|
|
1590
|
-
provide: CategoryHasuraGraphQLRepository,
|
|
1591
|
-
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
1592
|
-
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
1593
|
-
},
|
|
1594
|
-
deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1595
|
-
},
|
|
1596
|
-
{
|
|
1597
|
-
provide: 'ProductRepository',
|
|
1598
|
-
useExisting: ProductHasuraGraphQLRepository,
|
|
1599
|
-
},
|
|
1600
|
-
{
|
|
1601
|
-
provide: ProductHasuraGraphQLRepository,
|
|
1602
|
-
useFactory: (hasuraConfig) => {
|
|
1603
|
-
return new ProductHasuraGraphQLRepository(hasuraConfig);
|
|
1604
|
-
},
|
|
1605
|
-
deps: ['HasuraConfig'],
|
|
1606
|
-
},
|
|
1607
|
-
{
|
|
1608
|
-
provide: 'VariantRepository',
|
|
1609
|
-
useExisting: VariantHasuraGraphQLRepository,
|
|
1610
|
-
},
|
|
1611
|
-
{
|
|
1612
|
-
provide: VariantHasuraGraphQLRepository,
|
|
1613
|
-
useFactory: (hasuraConfig) => {
|
|
1614
|
-
return new VariantHasuraGraphQLRepository(hasuraConfig);
|
|
1615
|
-
},
|
|
1616
|
-
deps: ['HasuraConfig'],
|
|
1617
|
-
},
|
|
1618
|
-
{
|
|
1619
|
-
provide: 'CategoryFilterRepository',
|
|
1620
|
-
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1621
|
-
},
|
|
1622
|
-
{
|
|
1623
|
-
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1624
|
-
useFactory: (options) => {
|
|
1625
|
-
return new CategoryFilterHasuraGraphQLRepository(options);
|
|
1626
|
-
},
|
|
1627
|
-
deps: ['HasuraConfig'],
|
|
1628
|
-
},
|
|
1629
|
-
{
|
|
1630
|
-
provide: 'FilterOptionRepository',
|
|
1631
|
-
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1632
|
-
},
|
|
1633
|
-
{
|
|
1634
|
-
provide: FilterOptionHasuraGraphQLRepository,
|
|
1635
|
-
useFactory: (options) => {
|
|
1636
|
-
return new FilterOptionHasuraGraphQLRepository(options);
|
|
1637
|
-
},
|
|
1638
|
-
deps: ['HasuraConfig'],
|
|
1639
|
-
},
|
|
1640
|
-
{
|
|
1641
|
-
provide: 'FilterRepository',
|
|
1642
|
-
useExisting: FilterHasuraGraphQLRepository,
|
|
1643
|
-
},
|
|
1644
|
-
{
|
|
1645
|
-
provide: FilterHasuraGraphQLRepository,
|
|
1646
|
-
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
1647
|
-
return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
|
|
1648
|
-
},
|
|
1649
|
-
deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1650
|
-
},
|
|
1651
|
-
],
|
|
1652
|
-
}]
|
|
1653
|
-
}] });
|
|
1700
|
+
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 });
|
|
1701
|
+
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
|
|
1702
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
|
|
1703
|
+
type: Injectable
|
|
1704
|
+
}], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
|
|
1705
|
+
type: Inject,
|
|
1706
|
+
args: [BACKEND_URL]
|
|
1707
|
+
}] }, { type: HomeShopService }]; } });
|
|
1654
1708
|
|
|
1655
1709
|
class AngularConnectModule {
|
|
1656
1710
|
static initializeApp(defaultShop, options, nameOrConfig) {
|
|
@@ -1672,6 +1726,8 @@ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", ve
|
|
|
1672
1726
|
AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, providers: [
|
|
1673
1727
|
AuthService,
|
|
1674
1728
|
CartService,
|
|
1729
|
+
CatalogService,
|
|
1730
|
+
CategoryService,
|
|
1675
1731
|
CheckoutService,
|
|
1676
1732
|
CheckoutSubscriptionService,
|
|
1677
1733
|
CouponService,
|
|
@@ -1686,6 +1742,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1686
1742
|
providers: [
|
|
1687
1743
|
AuthService,
|
|
1688
1744
|
CartService,
|
|
1745
|
+
CatalogService,
|
|
1746
|
+
CategoryService,
|
|
1689
1747
|
CheckoutService,
|
|
1690
1748
|
CheckoutSubscriptionService,
|
|
1691
1749
|
CouponService,
|
|
@@ -1700,5 +1758,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1700
1758
|
* Generated bundle index. Do not edit.
|
|
1701
1759
|
*/
|
|
1702
1760
|
|
|
1703
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ShippingService };
|
|
1761
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ProductSorts, ShippingService };
|
|
1704
1762
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|