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