@infrab4a/connect-angular 3.10.0-beta.8 → 3.10.1

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