@infrab4a/connect-angular 3.9.5 → 3.10.0-beta.0

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