@infrab4a/connect-angular 4.0.0-beta.26 → 4.0.0-beta.28
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/catalog/catalog.service.d.ts +16 -0
- package/catalog/category.service.d.ts +6 -0
- package/catalog/enums/index.d.ts +1 -0
- package/catalog/enums/product-sorts.enum.d.ts +8 -0
- package/catalog/index.d.ts +5 -0
- package/catalog/models/category-with-tree.model.d.ts +4 -0
- package/catalog/models/index.d.ts +1 -0
- package/catalog/types/index.d.ts +1 -0
- package/catalog/types/product-sort.type.d.ts +2 -0
- package/esm2020/catalog/catalog.service.mjs +26 -0
- package/esm2020/catalog/category.service.mjs +9 -0
- package/esm2020/catalog/enums/index.mjs +2 -0
- package/esm2020/catalog/enums/product-sorts.enum.mjs +10 -0
- package/esm2020/catalog/index.mjs +6 -0
- package/esm2020/catalog/models/category-with-tree.model.mjs +10 -0
- package/esm2020/catalog/models/index.mjs +2 -0
- package/esm2020/catalog/types/index.mjs +2 -0
- package/esm2020/catalog/types/product-sort.type.mjs +2 -0
- package/esm2020/index.mjs +4 -3
- package/esm2020/services/cart.service.mjs +15 -5
- package/fesm2015/infrab4a-connect-angular.mjs +1320 -1257
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +1565 -1501
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/index.d.ts +3 -2
- package/package.json +2 -2
- package/services/cart.service.d.ts +3 -2
|
@@ -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, CheckoutSubscription, Category, 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 * as i1$3 from '@angular/common/http';
|
|
20
|
+
import { Type } from 'class-transformer';
|
|
53
21
|
|
|
54
22
|
const BACKEND_URL = 'BACKEND_URL';
|
|
55
23
|
|
|
@@ -62,1028 +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, variantRepository, buy2WinRepository) {
|
|
367
|
-
this.authService = authService;
|
|
368
|
-
this.checkoutService = checkoutService;
|
|
369
|
-
this.defaultShop = defaultShop;
|
|
370
|
-
this.productRepository = productRepository;
|
|
371
|
-
this.variantRepository = variantRepository;
|
|
372
|
-
this.buy2WinRepository = buy2WinRepository;
|
|
373
|
-
this.cartSubject = new Subject();
|
|
374
|
-
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
375
|
-
var _a;
|
|
376
|
-
const items = [];
|
|
377
|
-
const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
378
|
-
if (index > -1) {
|
|
379
|
-
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
380
|
-
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
381
|
-
}
|
|
382
|
-
else
|
|
383
|
-
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
384
|
-
return this.checkoutService
|
|
385
|
-
.updateCheckoutLineItems(checkoutLoaded)
|
|
386
|
-
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
387
|
-
}));
|
|
388
|
-
this.generateCartObject = (items) => (items === null || items === void 0 ? void 0 : items.reduce((cart, item) => {
|
|
389
|
-
var _a;
|
|
390
|
-
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) })) }));
|
|
391
|
-
}, {})) || {};
|
|
392
|
-
this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
|
|
393
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
394
|
-
const product = yield this.getProductData(item.id);
|
|
395
|
-
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;
|
|
396
|
-
if (this.checkMaxStock(item, quantity || 0))
|
|
397
|
-
throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
|
|
398
|
-
const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
|
|
399
|
-
const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
|
|
400
|
-
const isGift = item.isGift || null;
|
|
401
|
-
const pricePaid = this.getProductPrice({
|
|
402
|
-
product: item,
|
|
403
|
-
shop: checkout.shop || this.defaultShop,
|
|
404
|
-
isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
|
|
405
|
-
});
|
|
406
|
-
RoundProductPricesHelper.roundProductPrices(item);
|
|
407
|
-
return {
|
|
408
|
-
checkout,
|
|
409
|
-
lineItem: LineItem.toInstance({
|
|
410
|
-
id,
|
|
411
|
-
name: name !== null && name !== void 0 ? name : product.name,
|
|
412
|
-
EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
|
|
413
|
-
brand: product.brand,
|
|
414
|
-
slug: slug !== null && slug !== void 0 ? slug : product.slug,
|
|
415
|
-
sku: sku !== null && sku !== void 0 ? sku : product.sku,
|
|
416
|
-
stock,
|
|
417
|
-
price: this.roundPrice(price),
|
|
418
|
-
image,
|
|
419
|
-
weight: weight !== null && weight !== void 0 ? weight : product.weight,
|
|
420
|
-
quantity: (item.quantity || 0) + (quantity || 0),
|
|
421
|
-
pricePaid,
|
|
422
|
-
categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
|
|
423
|
-
isGift: isGift !== null && isGift !== void 0 ? isGift : null,
|
|
424
|
-
costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
|
|
425
|
-
type,
|
|
426
|
-
}),
|
|
427
|
-
};
|
|
428
|
-
});
|
|
429
|
-
this.getProductPrice = ({ product, isSubscriber, }) => {
|
|
430
|
-
const info = product.price;
|
|
431
|
-
if (product.isGift)
|
|
432
|
-
return 0;
|
|
433
|
-
return isSubscriber && info.subscriberPrice > 0
|
|
434
|
-
? Number(info.subscriberPrice.toFixed(2))
|
|
435
|
-
: Number(info.price.toFixed(2));
|
|
436
|
-
};
|
|
437
|
-
this.checkMaxStock = (item, quantity) => {
|
|
438
|
-
var _a;
|
|
439
|
-
const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
|
|
440
|
-
const currentItemAmount = item.quantity || 0;
|
|
441
|
-
return currentItemAmount + quantity > maxStock;
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
addItem(item, quantity = 1) {
|
|
445
|
-
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)));
|
|
446
|
-
}
|
|
447
|
-
decreaseItem(item) {
|
|
448
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
449
|
-
var _a;
|
|
450
|
-
const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
|
|
451
|
-
if (!isNil(checkoutItem))
|
|
452
|
-
checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
|
|
453
|
-
return checkout;
|
|
454
|
-
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
455
|
-
}
|
|
456
|
-
getCart(checkout) {
|
|
457
|
-
this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
|
|
458
|
-
return this.cartSubject;
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* @deprecated The method should not be used
|
|
462
|
-
*/
|
|
463
|
-
getVariantPriceDiscount(item) {
|
|
464
|
-
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)));
|
|
465
|
-
}
|
|
466
|
-
removeItem(item) {
|
|
467
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
468
|
-
const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
|
|
469
|
-
if (index >= 0)
|
|
470
|
-
checkout.lineItems.splice(index, 1);
|
|
471
|
-
return checkout;
|
|
472
|
-
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
473
|
-
}
|
|
474
|
-
updateUserCart(user) {
|
|
475
|
-
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* () {
|
|
476
|
-
var _a, _b;
|
|
477
|
-
return this.checkoutService
|
|
478
|
-
.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
|
|
479
|
-
? 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; })))
|
|
480
|
-
: [] })))
|
|
481
|
-
.toPromise();
|
|
482
|
-
})), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
483
|
-
}
|
|
484
|
-
clearCart() {
|
|
485
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
486
|
-
this.checkoutService.clearCheckoutFromSession();
|
|
487
|
-
return checkout;
|
|
488
|
-
}), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
|
|
489
|
-
}
|
|
490
|
-
buildCartFromCheckout(checkoutData) {
|
|
491
|
-
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
492
|
-
}
|
|
493
|
-
roundPrice(productPrice) {
|
|
494
|
-
const { price, fullPrice, subscriberPrice } = productPrice;
|
|
495
|
-
return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
|
|
496
|
-
}
|
|
497
|
-
getProductData(productId) {
|
|
498
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
499
|
-
let product;
|
|
500
|
-
let variant;
|
|
501
|
-
try {
|
|
502
|
-
product = yield this.productRepository.get({ id: productId });
|
|
503
|
-
}
|
|
504
|
-
catch (error) {
|
|
505
|
-
if (!(error instanceof NotFoundError))
|
|
506
|
-
throw error;
|
|
507
|
-
const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
|
|
508
|
-
variant = variants.shift();
|
|
509
|
-
if (!variant)
|
|
510
|
-
throw error;
|
|
511
|
-
product = yield this.productRepository.get({ id: variant.productId });
|
|
512
|
-
}
|
|
513
|
-
return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
getGifts() {
|
|
517
|
-
return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
|
|
518
|
-
const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
|
|
519
|
-
if (!notGiftItems.length)
|
|
520
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: [] });
|
|
521
|
-
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
522
|
-
const campaigns = yield this.buy2WinRepository
|
|
523
|
-
.find({
|
|
524
|
-
filters: {
|
|
525
|
-
active: { operator: Where.EQUALS, value: true },
|
|
526
|
-
shop: { operator: Where.EQUALS, value: this.defaultShop },
|
|
527
|
-
},
|
|
528
|
-
})
|
|
529
|
-
.then((data) => data.data);
|
|
530
|
-
if (!campaigns.length)
|
|
531
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
532
|
-
const elegibleCampaigns = [];
|
|
533
|
-
for (const campaign of campaigns) {
|
|
534
|
-
const today = new Date();
|
|
535
|
-
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
536
|
-
continue;
|
|
537
|
-
if (campaign.activeCategory) {
|
|
538
|
-
const categoriesCampaing = campaign.categories.map((c) => c.id);
|
|
539
|
-
const filterProductsCategories = checkout.lineItems.filter((l) => {
|
|
540
|
-
var _a;
|
|
541
|
-
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
542
|
-
return true;
|
|
543
|
-
return l.categories.some((c) => categoriesCampaing.some((cat) => cat == c));
|
|
544
|
-
});
|
|
545
|
-
if (filterProductsCategories.length) {
|
|
546
|
-
const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
547
|
-
if (cartTotalCategories >= campaign.cartValueMin)
|
|
548
|
-
elegibleCampaigns.push(campaign);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
else {
|
|
552
|
-
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
553
|
-
if (campaign.cartValue <= cartTotal)
|
|
554
|
-
elegibleCampaigns.push(campaign);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (!elegibleCampaigns.length)
|
|
559
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
560
|
-
const campaingnProducts = [];
|
|
561
|
-
for (const campaign of elegibleCampaigns) {
|
|
562
|
-
let elegibleProducts = [];
|
|
563
|
-
for (const product of campaign.products) {
|
|
564
|
-
const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
|
|
565
|
-
if (!productData.length)
|
|
566
|
-
continue;
|
|
567
|
-
const gift = productData.shift();
|
|
568
|
-
if (gift.stock.quantity < 1)
|
|
569
|
-
continue;
|
|
570
|
-
elegibleProducts.push(gift);
|
|
571
|
-
}
|
|
572
|
-
campaingnProducts.push(elegibleProducts);
|
|
573
|
-
}
|
|
574
|
-
if (!campaingnProducts.length)
|
|
575
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
576
|
-
const gifts = this.giftToLineItems([].concat(...campaingnProducts));
|
|
577
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
|
|
578
|
-
})), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
579
|
-
}
|
|
580
|
-
giftToLineItems(items) {
|
|
581
|
-
return items.map((item) => {
|
|
582
|
-
var _a;
|
|
583
|
-
const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
584
|
-
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];
|
|
585
|
-
return LineItem.toInstance({
|
|
586
|
-
brand,
|
|
587
|
-
categories,
|
|
588
|
-
id: id.toString(),
|
|
589
|
-
name,
|
|
590
|
-
price,
|
|
591
|
-
sku,
|
|
592
|
-
slug,
|
|
593
|
-
stock,
|
|
594
|
-
weight,
|
|
595
|
-
EAN,
|
|
596
|
-
image,
|
|
597
|
-
pricePaid: 0,
|
|
598
|
-
quantity: 1,
|
|
599
|
-
isGift: true,
|
|
600
|
-
});
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
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: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
605
|
-
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
606
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
607
|
-
type: Injectable
|
|
608
|
-
}], ctorParameters: function () {
|
|
609
|
-
return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
|
|
610
|
-
type: Inject,
|
|
611
|
-
args: [DEFAULT_SHOP]
|
|
612
|
-
}] }, { type: undefined, decorators: [{
|
|
613
|
-
type: Inject,
|
|
614
|
-
args: ['ProductRepository']
|
|
615
|
-
}] }, { type: undefined, decorators: [{
|
|
616
|
-
type: Inject,
|
|
617
|
-
args: ['VariantRepository']
|
|
618
|
-
}] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
|
|
619
|
-
type: Inject,
|
|
620
|
-
args: ['Buy2WinRepository']
|
|
621
|
-
}] }];
|
|
622
|
-
} });
|
|
623
|
-
|
|
624
|
-
class CheckoutSubscriptionService {
|
|
625
|
-
constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
|
|
626
|
-
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
627
|
-
this.subscriptionRepository = subscriptionRepository;
|
|
628
|
-
this.couponService = couponService;
|
|
629
|
-
}
|
|
630
|
-
getCheckoutSubscription(checkoutData) {
|
|
631
|
-
const checkoutId = cookie.get('checkoutSubscriptionId');
|
|
632
|
-
if (!isNil(checkoutId))
|
|
633
|
-
return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
|
|
634
|
-
return from(this.createCheckoutSubscription(checkoutData));
|
|
635
|
-
}
|
|
636
|
-
createCheckoutSubscription(checkoutData) {
|
|
637
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
638
|
-
const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
|
|
639
|
-
cookie.set('checkoutSubscriptionId', checkout.id);
|
|
640
|
-
return checkout;
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
clearCheckoutSubscriptionFromSession() {
|
|
644
|
-
cookie.remove('checkoutSubscriptionId');
|
|
645
|
-
return of();
|
|
646
|
-
}
|
|
647
|
-
checkCoupon(nickname, userEmail) {
|
|
648
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
649
|
-
.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
|
|
650
|
-
.pipe()));
|
|
651
|
-
}
|
|
652
|
-
calcDiscountSubscription(coupon) {
|
|
653
|
-
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
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 });
|
|
657
|
-
CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
|
|
658
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
659
|
-
type: Injectable
|
|
660
|
-
}], ctorParameters: function () {
|
|
661
|
-
return [{ type: undefined, decorators: [{
|
|
662
|
-
type: Inject,
|
|
663
|
-
args: ['CheckoutSubscriptionRepository']
|
|
664
|
-
}] }, { type: undefined, decorators: [{
|
|
665
|
-
type: Inject,
|
|
666
|
-
args: ['SubscriptionRepository']
|
|
667
|
-
}] }, { type: CouponService }];
|
|
668
|
-
} });
|
|
669
|
-
|
|
670
|
-
class HomeShopService {
|
|
671
|
-
constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
|
|
672
|
-
this.categoryRepository = categoryRepository;
|
|
673
|
-
this.homeRepository = homeRepository;
|
|
674
|
-
this.productRepository = productRepository;
|
|
675
|
-
this.defaultShop = defaultShop;
|
|
676
|
-
this.buildCategoryGroupWithRequiredData = (group) => {
|
|
677
|
-
var _a, _b;
|
|
678
|
-
return ({
|
|
679
|
-
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'])),
|
|
680
|
-
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()) || {}, [
|
|
681
|
-
'id',
|
|
682
|
-
'price',
|
|
683
|
-
'reviews',
|
|
684
|
-
'hasVariants',
|
|
685
|
-
'slug',
|
|
686
|
-
'sku',
|
|
687
|
-
'stock',
|
|
688
|
-
'costPrice',
|
|
689
|
-
'images',
|
|
690
|
-
'miniatures',
|
|
691
|
-
'name',
|
|
692
|
-
'weight',
|
|
693
|
-
'rate',
|
|
694
|
-
'type',
|
|
695
|
-
])))) || [],
|
|
696
|
-
});
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
get homeId() {
|
|
700
|
-
if (this.defaultShop === Shops.GLAMSHOP)
|
|
701
|
-
return 'glamshop';
|
|
702
|
-
if (this.defaultShop === Shops.MENSMARKET)
|
|
703
|
-
return 'mens_market';
|
|
704
|
-
return null;
|
|
705
|
-
}
|
|
706
|
-
getHomeData() {
|
|
707
|
-
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
|
|
708
|
-
? of(home)
|
|
709
|
-
: forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
|
|
710
|
-
discoverProducts,
|
|
711
|
-
featuredProducts,
|
|
712
|
-
verticalProducts,
|
|
713
|
-
})), concatMap((data) => this.saveHomeData(data)))));
|
|
714
|
-
}
|
|
715
|
-
getBanners(type) {
|
|
716
|
-
return this.getHomeConfiguration().pipe(map((home) => {
|
|
717
|
-
if (type === 'brand')
|
|
718
|
-
return home.brandsCarousel;
|
|
719
|
-
if (type === 'buyToWin')
|
|
720
|
-
return [home.buyToWinBanner];
|
|
721
|
-
if (type === 'block')
|
|
722
|
-
return home.blockBanners;
|
|
723
|
-
if (type === 'blog')
|
|
724
|
-
return [home.blogBanner];
|
|
725
|
-
return [];
|
|
726
|
-
}));
|
|
727
|
-
}
|
|
728
|
-
getMinValueForFreeShipping() {
|
|
729
|
-
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
730
|
-
}
|
|
731
|
-
getDiscoverProducts() {
|
|
732
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
733
|
-
}
|
|
734
|
-
getFeaturedProducts() {
|
|
735
|
-
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
736
|
-
}
|
|
737
|
-
getVerticalProducts() {
|
|
738
|
-
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({
|
|
739
|
-
filters: { categories: { operator: Where.IN, value: [category.id] } },
|
|
740
|
-
limits: { limit: 12 },
|
|
741
|
-
})).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
|
|
742
|
-
}
|
|
743
|
-
getHomeConfiguration() {
|
|
744
|
-
return of(this.homeConfiguration).pipe(concatMap((home) => home
|
|
745
|
-
? of(home)
|
|
746
|
-
: !this.homeId
|
|
747
|
-
? throwError(new RequiredArgumentError(['homeId']))
|
|
748
|
-
: from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
|
|
749
|
-
}
|
|
750
|
-
saveHomeData(homeData) {
|
|
751
|
-
const data = {
|
|
752
|
-
createdAt: new Date(),
|
|
753
|
-
expiresAt: add(new Date(), { hours: 1 }),
|
|
754
|
-
data: homeData,
|
|
755
|
-
};
|
|
756
|
-
return from(this.homeRepository.update({
|
|
757
|
-
id: this.homeId,
|
|
758
|
-
data,
|
|
759
|
-
})).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
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 });
|
|
763
|
-
HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
|
|
764
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
|
|
765
|
-
type: Injectable
|
|
766
|
-
}], ctorParameters: function () {
|
|
767
|
-
return [{ type: undefined, decorators: [{
|
|
768
|
-
type: Inject,
|
|
769
|
-
args: ['CategoryRepository']
|
|
770
|
-
}] }, { type: undefined, decorators: [{
|
|
771
|
-
type: Inject,
|
|
772
|
-
args: ['HomeRepository']
|
|
773
|
-
}] }, { type: undefined, decorators: [{
|
|
774
|
-
type: Inject,
|
|
775
|
-
args: ['ProductRepository']
|
|
776
|
-
}] }, { type: i3.Shops, decorators: [{
|
|
777
|
-
type: Inject,
|
|
778
|
-
args: [DEFAULT_SHOP]
|
|
779
|
-
}] }];
|
|
780
|
-
} });
|
|
781
|
-
|
|
782
|
-
class OrderService {
|
|
783
|
-
constructor(angularFirestore, orderRepository) {
|
|
784
|
-
this.angularFirestore = angularFirestore;
|
|
785
|
-
this.orderRepository = orderRepository;
|
|
786
|
-
this.orderSubject = new Subject();
|
|
787
|
-
}
|
|
788
|
-
getOrder(id) {
|
|
789
|
-
docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
|
|
790
|
-
.pipe(map((doc) => Order.toInstance(doc.data())))
|
|
791
|
-
.subscribe((doc) => this.orderSubject.next(doc));
|
|
792
|
-
return this.orderSubject;
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
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 });
|
|
796
|
-
OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
|
|
797
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
798
|
-
type: Injectable
|
|
799
|
-
}], ctorParameters: function () {
|
|
800
|
-
return [{ type: i1$1.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
|
|
801
|
-
type: Inject,
|
|
802
|
-
args: ['OrderRepository']
|
|
803
|
-
}] }];
|
|
804
|
-
} });
|
|
805
|
-
|
|
806
|
-
class ShippingService {
|
|
807
|
-
constructor(http, apiUrl, homeService) {
|
|
808
|
-
this.http = http;
|
|
809
|
-
this.apiUrl = apiUrl;
|
|
810
|
-
this.homeService = homeService;
|
|
811
|
-
}
|
|
812
|
-
getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
|
|
813
|
-
return combineLatest([
|
|
814
|
-
this.homeService.getHomeData(),
|
|
815
|
-
this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
|
|
816
|
-
]).pipe(map(([datas, shippingMethodsResponse]) => {
|
|
817
|
-
let shippingMethods = shippingMethodsResponse.result;
|
|
818
|
-
if (!shippingMethods.length)
|
|
819
|
-
return [];
|
|
820
|
-
shippingMethods = shippingMethods.map((shippingMethod) => {
|
|
821
|
-
if (shippingMethod.ShippingCompanyName == 'Same Day EG')
|
|
822
|
-
shippingMethod.ShippingCompanyName = 'Same Day';
|
|
823
|
-
return shippingMethod;
|
|
824
|
-
});
|
|
825
|
-
const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
|
|
826
|
-
if (this.isHolidays(datasSameDayNotAvaliable)) {
|
|
827
|
-
shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
|
|
828
|
-
}
|
|
829
|
-
if (totalPrice >= 200) {
|
|
830
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
831
|
-
if (s.serviceName !== 'Same Day')
|
|
832
|
-
return Object.assign(Object.assign({}, s), { totalPrice: 0 });
|
|
833
|
-
else
|
|
834
|
-
return s;
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
if (shop == Shops.GLAMSHOP)
|
|
838
|
-
return shippingMethods;
|
|
839
|
-
if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
|
|
840
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
841
|
-
if (s.serviceName == 'Same Day')
|
|
842
|
-
return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
|
|
843
|
-
else
|
|
844
|
-
return Object.assign(Object.assign({}, s), { totalPrice: 0 });
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
|
|
848
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
849
|
-
return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
return shippingMethods;
|
|
853
|
-
}));
|
|
854
|
-
}
|
|
855
|
-
isFreeShippingBySubscription(shop, subscriptionPlan) {
|
|
856
|
-
if (!subscriptionPlan)
|
|
857
|
-
return false;
|
|
858
|
-
if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
|
|
859
|
-
return true;
|
|
860
|
-
return false;
|
|
861
|
-
}
|
|
862
|
-
isHalfShippingBySubscription(shop, subscriptionPlan) {
|
|
863
|
-
if (!subscriptionPlan)
|
|
864
|
-
return false;
|
|
865
|
-
if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
|
|
866
|
-
return true;
|
|
867
|
-
}
|
|
868
|
-
return false;
|
|
869
|
-
}
|
|
870
|
-
isHolidays(datas) {
|
|
871
|
-
const today = new Date();
|
|
872
|
-
for (const key in datas) {
|
|
873
|
-
let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
|
|
874
|
-
let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
|
|
875
|
-
if (start > end)
|
|
876
|
-
end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
|
|
877
|
-
if (today >= start && today <= end)
|
|
878
|
-
return true;
|
|
879
|
-
}
|
|
880
|
-
return false;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
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 });
|
|
884
|
-
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
|
|
885
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
|
|
886
|
-
type: Injectable
|
|
887
|
-
}], ctorParameters: function () {
|
|
888
|
-
return [{ type: i1$2.HttpClient }, { type: undefined, decorators: [{
|
|
889
|
-
type: Inject,
|
|
890
|
-
args: [BACKEND_URL]
|
|
891
|
-
}] }, { type: HomeShopService }];
|
|
892
|
-
} });
|
|
893
|
-
|
|
894
|
-
class AngularFirebaseAuthModule {
|
|
895
|
-
static initializeApp(options, nameOrConfig) {
|
|
896
|
-
return {
|
|
897
|
-
ngModule: AngularFirebaseAuthModule,
|
|
898
|
-
providers: [
|
|
899
|
-
{ provide: FIREBASE_OPTIONS, useValue: options },
|
|
900
|
-
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
901
|
-
],
|
|
902
|
-
};
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
906
|
-
AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1$3.FirebaseAppModule, i1.AuthModule] });
|
|
907
|
-
AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
|
|
908
|
-
{
|
|
909
|
-
provide: 'Authentication',
|
|
910
|
-
useFactory: (authenticationService, userRepository) => {
|
|
911
|
-
return new Authentication(authenticationService, userRepository);
|
|
912
|
-
},
|
|
913
|
-
deps: ['AuthenticationService', 'UserRepository'],
|
|
914
|
-
},
|
|
915
|
-
{
|
|
916
|
-
provide: 'AuthenticationService',
|
|
917
|
-
useFactory: (angularFireAuth) => {
|
|
918
|
-
return new AuthenticationFirebaseAuthService(angularFireAuth);
|
|
919
|
-
},
|
|
920
|
-
deps: [Auth],
|
|
921
|
-
},
|
|
922
|
-
{
|
|
923
|
-
provide: 'Register',
|
|
924
|
-
useFactory: (registerService, userRepository) => {
|
|
925
|
-
return new Register(registerService, userRepository);
|
|
926
|
-
},
|
|
927
|
-
deps: ['RegisterService', 'UserRepository'],
|
|
928
|
-
},
|
|
929
|
-
{
|
|
930
|
-
provide: 'RegisterService',
|
|
931
|
-
useFactory: (angularFireAuth) => {
|
|
932
|
-
return new RegisterFirebaseAuthService(angularFireAuth);
|
|
933
|
-
},
|
|
934
|
-
deps: [Auth],
|
|
935
|
-
},
|
|
936
|
-
{
|
|
937
|
-
provide: 'SignOut',
|
|
938
|
-
useFactory: (authenticationService) => {
|
|
939
|
-
return new SignOut(authenticationService);
|
|
940
|
-
},
|
|
941
|
-
deps: ['AuthenticationService'],
|
|
942
|
-
},
|
|
943
|
-
{
|
|
944
|
-
provide: 'RecoveryPassword',
|
|
945
|
-
useFactory: (authenticationService) => {
|
|
946
|
-
return new RecoveryPassword(authenticationService);
|
|
947
|
-
},
|
|
948
|
-
deps: ['AuthenticationService'],
|
|
949
|
-
},
|
|
950
|
-
], imports: [provideFirebaseApp((injector) => {
|
|
951
|
-
const appName = injector.get(FIREBASE_APP_NAME);
|
|
952
|
-
return appName
|
|
953
|
-
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
954
|
-
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
955
|
-
}),
|
|
956
|
-
provideAuth(() => getAuth())] });
|
|
957
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
|
|
958
|
-
type: NgModule,
|
|
959
|
-
args: [{
|
|
960
|
-
imports: [
|
|
961
|
-
provideFirebaseApp((injector) => {
|
|
962
|
-
const appName = injector.get(FIREBASE_APP_NAME);
|
|
963
|
-
return appName
|
|
964
|
-
? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
|
|
965
|
-
: initializeApp(injector.get(FIREBASE_OPTIONS));
|
|
966
|
-
}),
|
|
967
|
-
provideAuth(() => getAuth()),
|
|
968
|
-
],
|
|
969
|
-
providers: [
|
|
970
|
-
{
|
|
971
|
-
provide: 'Authentication',
|
|
972
|
-
useFactory: (authenticationService, userRepository) => {
|
|
973
|
-
return new Authentication(authenticationService, userRepository);
|
|
974
|
-
},
|
|
975
|
-
deps: ['AuthenticationService', 'UserRepository'],
|
|
976
|
-
},
|
|
977
|
-
{
|
|
978
|
-
provide: 'AuthenticationService',
|
|
979
|
-
useFactory: (angularFireAuth) => {
|
|
980
|
-
return new AuthenticationFirebaseAuthService(angularFireAuth);
|
|
981
|
-
},
|
|
982
|
-
deps: [Auth],
|
|
983
|
-
},
|
|
984
|
-
{
|
|
985
|
-
provide: 'Register',
|
|
986
|
-
useFactory: (registerService, userRepository) => {
|
|
987
|
-
return new Register(registerService, userRepository);
|
|
988
|
-
},
|
|
989
|
-
deps: ['RegisterService', 'UserRepository'],
|
|
990
|
-
},
|
|
991
|
-
{
|
|
992
|
-
provide: 'RegisterService',
|
|
993
|
-
useFactory: (angularFireAuth) => {
|
|
994
|
-
return new RegisterFirebaseAuthService(angularFireAuth);
|
|
995
|
-
},
|
|
996
|
-
deps: [Auth],
|
|
997
|
-
},
|
|
998
|
-
{
|
|
999
|
-
provide: 'SignOut',
|
|
1000
|
-
useFactory: (authenticationService) => {
|
|
1001
|
-
return new SignOut(authenticationService);
|
|
1002
|
-
},
|
|
1003
|
-
deps: ['AuthenticationService'],
|
|
1004
|
-
},
|
|
1005
|
-
{
|
|
1006
|
-
provide: 'RecoveryPassword',
|
|
1007
|
-
useFactory: (authenticationService) => {
|
|
1008
|
-
return new RecoveryPassword(authenticationService);
|
|
1009
|
-
},
|
|
1010
|
-
deps: ['AuthenticationService'],
|
|
1011
|
-
},
|
|
1012
|
-
],
|
|
1013
|
-
}]
|
|
1014
|
-
}] });
|
|
1015
|
-
|
|
1016
|
-
class AngularElasticSeachModule {
|
|
1017
|
-
static initializeApp(options) {
|
|
1018
|
-
return {
|
|
1019
|
-
ngModule: AngularElasticSeachModule,
|
|
1020
|
-
providers: [{ provide: ES_CONFIG, useValue: options }],
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1025
|
-
AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule });
|
|
1026
|
-
AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
|
|
1027
|
-
{
|
|
1028
|
-
provide: ProductsIndex,
|
|
1029
|
-
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
1030
|
-
deps: [ES_CONFIG],
|
|
1031
|
-
},
|
|
1032
|
-
] });
|
|
1033
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
|
|
1034
|
-
type: NgModule,
|
|
1035
|
-
args: [{
|
|
1036
|
-
providers: [
|
|
1037
|
-
{
|
|
1038
|
-
provide: ProductsIndex,
|
|
1039
|
-
useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
|
|
1040
|
-
deps: [ES_CONFIG],
|
|
1041
|
-
},
|
|
1042
|
-
],
|
|
1043
|
-
}]
|
|
1044
|
-
}] });
|
|
1045
|
-
|
|
1046
|
-
class AngularFirestoreModule {
|
|
1047
|
-
static initializeApp(options, nameOrConfig) {
|
|
1048
|
-
return {
|
|
1049
|
-
ngModule: AngularFirestoreModule,
|
|
1050
|
-
providers: [
|
|
1051
|
-
{ provide: FIREBASE_OPTIONS, useValue: options.firebase },
|
|
1052
|
-
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
1053
|
-
{ provide: ES_CONFIG, useValue: options.elasticSearch },
|
|
1054
|
-
],
|
|
1055
|
-
};
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1059
|
-
AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$3.FirebaseAppModule, i1$1.FirestoreModule] });
|
|
1060
|
-
AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, providers: [
|
|
1061
|
-
{
|
|
1062
|
-
provide: 'FirestoreOptions',
|
|
1063
|
-
useFactory: (firestore, platformId) => ({
|
|
1064
|
-
firestore,
|
|
1065
|
-
interceptors: {
|
|
1066
|
-
request: (request) => {
|
|
1067
|
-
if (isPlatformBrowser(platformId))
|
|
1068
|
-
return request;
|
|
1069
|
-
const interval = setInterval(() => { }, 100);
|
|
1070
|
-
request.interval = interval;
|
|
1071
|
-
return request;
|
|
1072
|
-
},
|
|
1073
|
-
response: (response, request) => {
|
|
1074
|
-
if (isPlatformBrowser(platformId))
|
|
1075
|
-
return response;
|
|
1076
|
-
clearInterval(request.interval);
|
|
1077
|
-
return response;
|
|
1078
|
-
},
|
|
1079
|
-
},
|
|
1080
|
-
}),
|
|
1081
|
-
deps: [Firestore, PLATFORM_ID],
|
|
1082
|
-
},
|
|
1083
|
-
{
|
|
1084
|
-
provide: 'BeautyProfileRepository',
|
|
1085
|
-
useFactory: (config, userRepository) => {
|
|
1086
|
-
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);
|
|
1087
226
|
},
|
|
1088
227
|
deps: ['FirestoreOptions', 'UserRepository'],
|
|
1089
228
|
},
|
|
@@ -1476,205 +615,1077 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1476
615
|
},
|
|
1477
616
|
],
|
|
1478
617
|
}]
|
|
1479
|
-
}] });
|
|
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
|
+
} });
|
|
1480
1419
|
|
|
1481
|
-
class
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1420
|
+
class CheckoutSubscriptionService {
|
|
1421
|
+
constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
|
|
1422
|
+
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
1423
|
+
this.subscriptionRepository = subscriptionRepository;
|
|
1424
|
+
this.couponService = couponService;
|
|
1425
|
+
}
|
|
1426
|
+
getCheckoutSubscription(checkoutData) {
|
|
1427
|
+
const checkoutId = cookie.get('checkoutSubscriptionId');
|
|
1428
|
+
if (!isNil(checkoutId))
|
|
1429
|
+
return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
|
|
1430
|
+
return from(this.createCheckoutSubscription(checkoutData));
|
|
1431
|
+
}
|
|
1432
|
+
createCheckoutSubscription(checkoutData) {
|
|
1433
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1434
|
+
const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
|
|
1435
|
+
cookie.set('checkoutSubscriptionId', checkout.id);
|
|
1436
|
+
return checkout;
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
clearCheckoutSubscriptionFromSession() {
|
|
1440
|
+
cookie.remove('checkoutSubscriptionId');
|
|
1441
|
+
return of();
|
|
1442
|
+
}
|
|
1443
|
+
checkCoupon(nickname, userEmail) {
|
|
1444
|
+
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
|
|
1445
|
+
.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
|
|
1446
|
+
.pipe()));
|
|
1447
|
+
}
|
|
1448
|
+
calcDiscountSubscription(coupon) {
|
|
1449
|
+
return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
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 });
|
|
1453
|
+
CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
|
|
1454
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
|
|
1455
|
+
type: Injectable
|
|
1456
|
+
}], ctorParameters: function () {
|
|
1457
|
+
return [{ type: undefined, decorators: [{
|
|
1458
|
+
type: Inject,
|
|
1459
|
+
args: ['CheckoutSubscriptionRepository']
|
|
1460
|
+
}] }, { type: undefined, decorators: [{
|
|
1461
|
+
type: Inject,
|
|
1462
|
+
args: ['SubscriptionRepository']
|
|
1463
|
+
}] }, { type: CouponService }];
|
|
1464
|
+
} });
|
|
1465
|
+
|
|
1466
|
+
class HomeShopService {
|
|
1467
|
+
constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
|
|
1468
|
+
this.categoryRepository = categoryRepository;
|
|
1469
|
+
this.homeRepository = homeRepository;
|
|
1470
|
+
this.productRepository = productRepository;
|
|
1471
|
+
this.defaultShop = defaultShop;
|
|
1472
|
+
this.buildCategoryGroupWithRequiredData = (group) => {
|
|
1473
|
+
var _a, _b;
|
|
1474
|
+
return ({
|
|
1475
|
+
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'])),
|
|
1476
|
+
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()) || {}, [
|
|
1477
|
+
'id',
|
|
1478
|
+
'price',
|
|
1479
|
+
'reviews',
|
|
1480
|
+
'hasVariants',
|
|
1481
|
+
'slug',
|
|
1482
|
+
'sku',
|
|
1483
|
+
'stock',
|
|
1484
|
+
'costPrice',
|
|
1485
|
+
'images',
|
|
1486
|
+
'miniatures',
|
|
1487
|
+
'name',
|
|
1488
|
+
'weight',
|
|
1489
|
+
'rate',
|
|
1490
|
+
'type',
|
|
1491
|
+
])))) || [],
|
|
1492
|
+
});
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
get homeId() {
|
|
1496
|
+
if (this.defaultShop === Shops.GLAMSHOP)
|
|
1497
|
+
return 'glamshop';
|
|
1498
|
+
if (this.defaultShop === Shops.MENSMARKET)
|
|
1499
|
+
return 'mens_market';
|
|
1500
|
+
return null;
|
|
1501
|
+
}
|
|
1502
|
+
getHomeData() {
|
|
1503
|
+
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
|
|
1504
|
+
? of(home)
|
|
1505
|
+
: forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
|
|
1506
|
+
discoverProducts,
|
|
1507
|
+
featuredProducts,
|
|
1508
|
+
verticalProducts,
|
|
1509
|
+
})), concatMap((data) => this.saveHomeData(data)))));
|
|
1510
|
+
}
|
|
1511
|
+
getBanners(type) {
|
|
1512
|
+
return this.getHomeConfiguration().pipe(map((home) => {
|
|
1513
|
+
if (type === 'brand')
|
|
1514
|
+
return home.brandsCarousel;
|
|
1515
|
+
if (type === 'buyToWin')
|
|
1516
|
+
return [home.buyToWinBanner];
|
|
1517
|
+
if (type === 'block')
|
|
1518
|
+
return home.blockBanners;
|
|
1519
|
+
if (type === 'blog')
|
|
1520
|
+
return [home.blogBanner];
|
|
1521
|
+
return [];
|
|
1522
|
+
}));
|
|
1523
|
+
}
|
|
1524
|
+
getMinValueForFreeShipping() {
|
|
1525
|
+
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
1526
|
+
}
|
|
1527
|
+
getDiscoverProducts() {
|
|
1528
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
1529
|
+
}
|
|
1530
|
+
getFeaturedProducts() {
|
|
1531
|
+
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|
|
1532
|
+
}
|
|
1533
|
+
getVerticalProducts() {
|
|
1534
|
+
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({
|
|
1535
|
+
filters: { categories: { operator: Where.IN, value: [category.id] } },
|
|
1536
|
+
limits: { limit: 12 },
|
|
1537
|
+
})).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
|
|
1538
|
+
}
|
|
1539
|
+
getHomeConfiguration() {
|
|
1540
|
+
return of(this.homeConfiguration).pipe(concatMap((home) => home
|
|
1541
|
+
? of(home)
|
|
1542
|
+
: !this.homeId
|
|
1543
|
+
? throwError(new RequiredArgumentError(['homeId']))
|
|
1544
|
+
: from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
|
|
1545
|
+
}
|
|
1546
|
+
saveHomeData(homeData) {
|
|
1547
|
+
const data = {
|
|
1548
|
+
createdAt: new Date(),
|
|
1549
|
+
expiresAt: add(new Date(), { hours: 1 }),
|
|
1550
|
+
data: homeData,
|
|
1486
1551
|
};
|
|
1552
|
+
return from(this.homeRepository.update({
|
|
1553
|
+
id: this.homeId,
|
|
1554
|
+
data,
|
|
1555
|
+
})).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
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 });
|
|
1559
|
+
HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
|
|
1560
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
|
|
1561
|
+
type: Injectable
|
|
1562
|
+
}], ctorParameters: function () {
|
|
1563
|
+
return [{ type: undefined, decorators: [{
|
|
1564
|
+
type: Inject,
|
|
1565
|
+
args: ['CategoryRepository']
|
|
1566
|
+
}] }, { type: undefined, decorators: [{
|
|
1567
|
+
type: Inject,
|
|
1568
|
+
args: ['HomeRepository']
|
|
1569
|
+
}] }, { type: undefined, decorators: [{
|
|
1570
|
+
type: Inject,
|
|
1571
|
+
args: ['ProductRepository']
|
|
1572
|
+
}] }, { type: i3.Shops, decorators: [{
|
|
1573
|
+
type: Inject,
|
|
1574
|
+
args: [DEFAULT_SHOP]
|
|
1575
|
+
}] }];
|
|
1576
|
+
} });
|
|
1577
|
+
|
|
1578
|
+
class OrderService {
|
|
1579
|
+
constructor(angularFirestore, orderRepository) {
|
|
1580
|
+
this.angularFirestore = angularFirestore;
|
|
1581
|
+
this.orderRepository = orderRepository;
|
|
1582
|
+
this.orderSubject = new Subject();
|
|
1583
|
+
}
|
|
1584
|
+
getOrder(id) {
|
|
1585
|
+
docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
|
|
1586
|
+
.pipe(map((doc) => Order.toInstance(doc.data())))
|
|
1587
|
+
.subscribe((doc) => this.orderSubject.next(doc));
|
|
1588
|
+
return this.orderSubject;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
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 });
|
|
1592
|
+
OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
|
|
1593
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
1594
|
+
type: Injectable
|
|
1595
|
+
}], ctorParameters: function () {
|
|
1596
|
+
return [{ type: i1$2.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
|
|
1597
|
+
type: Inject,
|
|
1598
|
+
args: ['OrderRepository']
|
|
1599
|
+
}] }];
|
|
1600
|
+
} });
|
|
1601
|
+
|
|
1602
|
+
class ShippingService {
|
|
1603
|
+
constructor(http, apiUrl, homeService) {
|
|
1604
|
+
this.http = http;
|
|
1605
|
+
this.apiUrl = apiUrl;
|
|
1606
|
+
this.homeService = homeService;
|
|
1607
|
+
}
|
|
1608
|
+
getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
|
|
1609
|
+
return combineLatest([
|
|
1610
|
+
this.homeService.getHomeData(),
|
|
1611
|
+
this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
|
|
1612
|
+
]).pipe(map(([datas, shippingMethodsResponse]) => {
|
|
1613
|
+
let shippingMethods = shippingMethodsResponse.result;
|
|
1614
|
+
if (!shippingMethods.length)
|
|
1615
|
+
return [];
|
|
1616
|
+
shippingMethods = shippingMethods.map((shippingMethod) => {
|
|
1617
|
+
if (shippingMethod.ShippingCompanyName == 'Same Day EG')
|
|
1618
|
+
shippingMethod.ShippingCompanyName = 'Same Day';
|
|
1619
|
+
return shippingMethod;
|
|
1620
|
+
});
|
|
1621
|
+
const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
|
|
1622
|
+
if (this.isHolidays(datasSameDayNotAvaliable)) {
|
|
1623
|
+
shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
|
|
1624
|
+
}
|
|
1625
|
+
if (totalPrice >= 200) {
|
|
1626
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
1627
|
+
if (s.serviceName !== 'Same Day')
|
|
1628
|
+
return Object.assign(Object.assign({}, s), { totalPrice: 0 });
|
|
1629
|
+
else
|
|
1630
|
+
return s;
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
if (shop == Shops.GLAMSHOP)
|
|
1634
|
+
return shippingMethods;
|
|
1635
|
+
if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
|
|
1636
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
1637
|
+
if (s.serviceName == 'Same Day')
|
|
1638
|
+
return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
|
|
1639
|
+
else
|
|
1640
|
+
return Object.assign(Object.assign({}, s), { totalPrice: 0 });
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
|
|
1644
|
+
shippingMethods = shippingMethods.map((s) => {
|
|
1645
|
+
return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
return shippingMethods;
|
|
1649
|
+
}));
|
|
1650
|
+
}
|
|
1651
|
+
isFreeShippingBySubscription(shop, subscriptionPlan) {
|
|
1652
|
+
if (!subscriptionPlan)
|
|
1653
|
+
return false;
|
|
1654
|
+
if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
|
|
1655
|
+
return true;
|
|
1656
|
+
return false;
|
|
1657
|
+
}
|
|
1658
|
+
isHalfShippingBySubscription(shop, subscriptionPlan) {
|
|
1659
|
+
if (!subscriptionPlan)
|
|
1660
|
+
return false;
|
|
1661
|
+
if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
|
|
1662
|
+
return true;
|
|
1663
|
+
}
|
|
1664
|
+
return false;
|
|
1665
|
+
}
|
|
1666
|
+
isHolidays(datas) {
|
|
1667
|
+
const today = new Date();
|
|
1668
|
+
for (const key in datas) {
|
|
1669
|
+
let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
|
|
1670
|
+
let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
|
|
1671
|
+
if (start > end)
|
|
1672
|
+
end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
|
|
1673
|
+
if (today >= start && today <= end)
|
|
1674
|
+
return true;
|
|
1675
|
+
}
|
|
1676
|
+
return false;
|
|
1487
1677
|
}
|
|
1488
1678
|
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
if (isPlatformBrowser(platformId))
|
|
1500
|
-
return request;
|
|
1501
|
-
const interval = setInterval(() => { }, 100);
|
|
1502
|
-
request.interval = interval;
|
|
1503
|
-
return request;
|
|
1504
|
-
},
|
|
1505
|
-
response: (response, request) => {
|
|
1506
|
-
if (isPlatformBrowser(platformId))
|
|
1507
|
-
return response;
|
|
1508
|
-
clearInterval(request.interval);
|
|
1509
|
-
return response;
|
|
1510
|
-
},
|
|
1511
|
-
},
|
|
1512
|
-
}),
|
|
1513
|
-
deps: [HASURA_OPTIONS, PLATFORM_ID],
|
|
1514
|
-
},
|
|
1515
|
-
{
|
|
1516
|
-
provide: 'CategoryRepository',
|
|
1517
|
-
useExisting: CategoryHasuraGraphQLRepository,
|
|
1518
|
-
},
|
|
1519
|
-
{
|
|
1520
|
-
provide: CategoryHasuraGraphQLRepository,
|
|
1521
|
-
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
1522
|
-
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
1523
|
-
},
|
|
1524
|
-
deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1525
|
-
},
|
|
1526
|
-
{
|
|
1527
|
-
provide: 'ProductRepository',
|
|
1528
|
-
useExisting: ProductHasuraGraphQLRepository,
|
|
1529
|
-
},
|
|
1530
|
-
{
|
|
1531
|
-
provide: ProductHasuraGraphQLRepository,
|
|
1532
|
-
useFactory: (hasuraConfig) => {
|
|
1533
|
-
return new ProductHasuraGraphQLRepository(hasuraConfig);
|
|
1534
|
-
},
|
|
1535
|
-
deps: ['HasuraConfig'],
|
|
1536
|
-
},
|
|
1537
|
-
{
|
|
1538
|
-
provide: 'VariantRepository',
|
|
1539
|
-
useExisting: VariantHasuraGraphQLRepository,
|
|
1540
|
-
},
|
|
1541
|
-
{
|
|
1542
|
-
provide: VariantHasuraGraphQLRepository,
|
|
1543
|
-
useFactory: (hasuraConfig) => {
|
|
1544
|
-
return new VariantHasuraGraphQLRepository(hasuraConfig);
|
|
1545
|
-
},
|
|
1546
|
-
deps: ['HasuraConfig'],
|
|
1547
|
-
},
|
|
1548
|
-
{
|
|
1549
|
-
provide: 'CategoryFilterRepository',
|
|
1550
|
-
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1551
|
-
},
|
|
1552
|
-
{
|
|
1553
|
-
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1554
|
-
useFactory: (options) => {
|
|
1555
|
-
return new CategoryFilterHasuraGraphQLRepository(options);
|
|
1556
|
-
},
|
|
1557
|
-
deps: ['HasuraConfig'],
|
|
1558
|
-
},
|
|
1559
|
-
{
|
|
1560
|
-
provide: 'FilterOptionRepository',
|
|
1561
|
-
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1562
|
-
},
|
|
1563
|
-
{
|
|
1564
|
-
provide: FilterOptionHasuraGraphQLRepository,
|
|
1565
|
-
useFactory: (options) => {
|
|
1566
|
-
return new FilterOptionHasuraGraphQLRepository(options);
|
|
1567
|
-
},
|
|
1568
|
-
deps: ['HasuraConfig'],
|
|
1569
|
-
},
|
|
1570
|
-
{
|
|
1571
|
-
provide: 'FilterRepository',
|
|
1572
|
-
useExisting: FilterHasuraGraphQLRepository,
|
|
1573
|
-
},
|
|
1574
|
-
{
|
|
1575
|
-
provide: FilterHasuraGraphQLRepository,
|
|
1576
|
-
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
1577
|
-
return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
|
|
1578
|
-
},
|
|
1579
|
-
deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1580
|
-
},
|
|
1581
|
-
] });
|
|
1582
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
|
|
1583
|
-
type: NgModule,
|
|
1584
|
-
args: [{
|
|
1585
|
-
providers: [
|
|
1586
|
-
{
|
|
1587
|
-
provide: 'HasuraConfig',
|
|
1588
|
-
useFactory: (options, platformId) => ({
|
|
1589
|
-
endpoint: options.endpoint,
|
|
1590
|
-
authOptions: options.credentials,
|
|
1591
|
-
interceptors: {
|
|
1592
|
-
request: (request) => {
|
|
1593
|
-
if (isPlatformBrowser(platformId))
|
|
1594
|
-
return request;
|
|
1595
|
-
const interval = setInterval(() => { }, 100);
|
|
1596
|
-
request.interval = interval;
|
|
1597
|
-
return request;
|
|
1598
|
-
},
|
|
1599
|
-
response: (response, request) => {
|
|
1600
|
-
if (isPlatformBrowser(platformId))
|
|
1601
|
-
return response;
|
|
1602
|
-
clearInterval(request.interval);
|
|
1603
|
-
return response;
|
|
1604
|
-
},
|
|
1605
|
-
},
|
|
1606
|
-
}),
|
|
1607
|
-
deps: [HASURA_OPTIONS, PLATFORM_ID],
|
|
1608
|
-
},
|
|
1609
|
-
{
|
|
1610
|
-
provide: 'CategoryRepository',
|
|
1611
|
-
useExisting: CategoryHasuraGraphQLRepository,
|
|
1612
|
-
},
|
|
1613
|
-
{
|
|
1614
|
-
provide: CategoryHasuraGraphQLRepository,
|
|
1615
|
-
useFactory: (options, productRepository, categoryFilterRepository) => {
|
|
1616
|
-
return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
|
|
1617
|
-
},
|
|
1618
|
-
deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1619
|
-
},
|
|
1620
|
-
{
|
|
1621
|
-
provide: 'ProductRepository',
|
|
1622
|
-
useExisting: ProductHasuraGraphQLRepository,
|
|
1623
|
-
},
|
|
1624
|
-
{
|
|
1625
|
-
provide: ProductHasuraGraphQLRepository,
|
|
1626
|
-
useFactory: (hasuraConfig) => {
|
|
1627
|
-
return new ProductHasuraGraphQLRepository(hasuraConfig);
|
|
1628
|
-
},
|
|
1629
|
-
deps: ['HasuraConfig'],
|
|
1630
|
-
},
|
|
1631
|
-
{
|
|
1632
|
-
provide: 'VariantRepository',
|
|
1633
|
-
useExisting: VariantHasuraGraphQLRepository,
|
|
1634
|
-
},
|
|
1635
|
-
{
|
|
1636
|
-
provide: VariantHasuraGraphQLRepository,
|
|
1637
|
-
useFactory: (hasuraConfig) => {
|
|
1638
|
-
return new VariantHasuraGraphQLRepository(hasuraConfig);
|
|
1639
|
-
},
|
|
1640
|
-
deps: ['HasuraConfig'],
|
|
1641
|
-
},
|
|
1642
|
-
{
|
|
1643
|
-
provide: 'CategoryFilterRepository',
|
|
1644
|
-
useExisting: CategoryFilterHasuraGraphQLRepository,
|
|
1645
|
-
},
|
|
1646
|
-
{
|
|
1647
|
-
provide: CategoryFilterHasuraGraphQLRepository,
|
|
1648
|
-
useFactory: (options) => {
|
|
1649
|
-
return new CategoryFilterHasuraGraphQLRepository(options);
|
|
1650
|
-
},
|
|
1651
|
-
deps: ['HasuraConfig'],
|
|
1652
|
-
},
|
|
1653
|
-
{
|
|
1654
|
-
provide: 'FilterOptionRepository',
|
|
1655
|
-
useExisting: FilterOptionHasuraGraphQLRepository,
|
|
1656
|
-
},
|
|
1657
|
-
{
|
|
1658
|
-
provide: FilterOptionHasuraGraphQLRepository,
|
|
1659
|
-
useFactory: (options) => {
|
|
1660
|
-
return new FilterOptionHasuraGraphQLRepository(options);
|
|
1661
|
-
},
|
|
1662
|
-
deps: ['HasuraConfig'],
|
|
1663
|
-
},
|
|
1664
|
-
{
|
|
1665
|
-
provide: 'FilterRepository',
|
|
1666
|
-
useExisting: FilterHasuraGraphQLRepository,
|
|
1667
|
-
},
|
|
1668
|
-
{
|
|
1669
|
-
provide: FilterHasuraGraphQLRepository,
|
|
1670
|
-
useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
|
|
1671
|
-
return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
|
|
1672
|
-
},
|
|
1673
|
-
deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
|
|
1674
|
-
},
|
|
1675
|
-
],
|
|
1676
|
-
}]
|
|
1677
|
-
}] });
|
|
1679
|
+
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 });
|
|
1680
|
+
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
|
|
1681
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
|
|
1682
|
+
type: Injectable
|
|
1683
|
+
}], ctorParameters: function () {
|
|
1684
|
+
return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
|
|
1685
|
+
type: Inject,
|
|
1686
|
+
args: [BACKEND_URL]
|
|
1687
|
+
}] }, { type: HomeShopService }];
|
|
1688
|
+
} });
|
|
1678
1689
|
|
|
1679
1690
|
class AngularConnectModule {
|
|
1680
1691
|
static initializeApp(defaultShop, options, nameOrConfig) {
|
|
@@ -1720,9 +1731,61 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1720
1731
|
}]
|
|
1721
1732
|
}] });
|
|
1722
1733
|
|
|
1734
|
+
class CatalogService {
|
|
1735
|
+
constructor() {
|
|
1736
|
+
this.buildFilterQuery = (category, filters) => { };
|
|
1737
|
+
this.buildSortQuery = (sort) => {
|
|
1738
|
+
const query = {
|
|
1739
|
+
stock: 'desc',
|
|
1740
|
+
gender: 'asc',
|
|
1741
|
+
};
|
|
1742
|
+
return query;
|
|
1743
|
+
};
|
|
1744
|
+
this.buildLimitQuery = (options) => {
|
|
1745
|
+
const limit = (options === null || options === void 0 ? void 0 : options.perPage) || 20;
|
|
1746
|
+
return {
|
|
1747
|
+
limit,
|
|
1748
|
+
offset: (((options === null || options === void 0 ? void 0 : options.page) || 1) - 1) * limit,
|
|
1749
|
+
};
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
fetchProducts(category, options) {
|
|
1753
|
+
return {
|
|
1754
|
+
products: [],
|
|
1755
|
+
pages: 1,
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
class CategoryService {
|
|
1761
|
+
fetchSubCategories(category) {
|
|
1762
|
+
return [];
|
|
1763
|
+
}
|
|
1764
|
+
fetchFilterOptions(category, filters) {
|
|
1765
|
+
return [];
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
var ProductSorts;
|
|
1770
|
+
(function (ProductSorts) {
|
|
1771
|
+
ProductSorts["MOST_RELEVANT"] = "most-relevant";
|
|
1772
|
+
ProductSorts["BEST_SELLER"] = "best-sellers";
|
|
1773
|
+
ProductSorts["BIGGEST_PRICE"] = "biggest-price";
|
|
1774
|
+
ProductSorts["LOWEST_PRICE"] = "lowest-price";
|
|
1775
|
+
ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
|
|
1776
|
+
ProductSorts["BEST_RATING"] = "best-rating";
|
|
1777
|
+
})(ProductSorts || (ProductSorts = {}));
|
|
1778
|
+
|
|
1779
|
+
class CategoryWithTree extends Category {
|
|
1780
|
+
}
|
|
1781
|
+
__decorate([
|
|
1782
|
+
Type(() => CategoryWithTree),
|
|
1783
|
+
__metadata("design:type", Array)
|
|
1784
|
+
], CategoryWithTree.prototype, "children", void 0);
|
|
1785
|
+
|
|
1723
1786
|
/**
|
|
1724
1787
|
* Generated bundle index. Do not edit.
|
|
1725
1788
|
*/
|
|
1726
1789
|
|
|
1727
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ShippingService };
|
|
1790
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ProductSorts, ShippingService };
|
|
1728
1791
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|